fetching rows

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
aybra
Forum Commoner
Posts: 56
Joined: Sun Nov 24, 2002 12:52 am

fetching rows

Post by aybra »

bloody hell I just cant figure this out, I've been reading php.net, and programming php by o'reilly and i just cant for the life of me figure out how to fetch more the one row at a time... its simply driving me nuts. can any one help me out here?

Code: Select all

<?php
    while ($row = mysql_fetch_assoc($result)) {
            $name = $rowї"name"]; 
            $name2 = $rowї"nameї0]"]; 
           $owner= $rowї"owner"]; 
            $sire = $rowї"sire"]; 
            $dam = $rowї"dam"]; 
}
?>
The above script will print out the last entry made.. but not the other two made so far, running on an apache server... please help an insane man out :oops: :o :idea:
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

by design the mysql_fetch_* functions are designed to get one row at a time. you could loop through the result and put each row into an array
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I can't see any function call that's outputs anything at all....
Did you place your print/echo outside the while loop? The of course only the last record is printed ;)
try

Code: Select all

<table>
...
<?php
while ($row = mysql_fetch_assoc($result)) {
	$name = $rowї"name"]; 
	$name2 = $rowї"nameї0]"]; 
	$owner= $rowї"owner"]; 
	$sire = $rowї"sire"]; 
	$dam = $rowї"dam"]; 
	echo '<tr><td>',
				$name, '</td><td>', $name2,
				$owner, '</td><td>',
				$sire, '</td><td>',
				$dam, '</td></tr>';
}
?>
...
</table>
aybra
Forum Commoner
Posts: 56
Joined: Sun Nov 24, 2002 12:52 am

Post by aybra »

DUDE!!! thanks man!


I'm farly new to this php stuff... been doing it a week now, teaching myself from like I said.. a book and manual :) I think i'm doing pretty good but some of the obvious things excape my sight :(
Post Reply