Newbie having array display probs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MadCow573
Forum Newbie
Posts: 1
Joined: Sat Oct 19, 2002 2:29 pm

Newbie having array display probs

Post by MadCow573 »

Hi there,

Sorry for the dumb question, but im new to PHP and just cant figure this out . I am trying to create a "roster" type layout but cant get my array items to display the way I wish.

DB schema
rank_id | rank1 | rank2 | rank3

1 | user1 | user2 | user3
2 | user1b |

Idea being that I can display each rank and its users with only one query and array, unfortunatly when I try to pull two or more fields PHP is printing out the rows in succession casuing "user1b" to be inserted AFTER the entire first row has been displayed.

$row = mysql_fetch_array($result);

print $row["rank1"];

print $row["rank2"];

will print
user1, user2, user1b

when I'd like
user1, user1b, user2

(i realize this example is oversimplified)

Is my db flawed? Can i use another function to diplay multi-col only w/o re-query? Am i just a newbie moron?

Thanks for the time,
Eric C
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

$result = mysql_query($query, $dbConn) creates a result set according to $query. $result identifies the result set for further access.
$row = mysql_fetch_array($result); fetches one (/the next) row of a result set.
$row["rank1"]; refers to the value of the field rank1 in this row.

there are some mysql/php tutorials at http://www.phpcomplete.com/section_content.php?id=3

btw: welcome to this forum :D
Post Reply