[SOLVED] fetch_row issue

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
reverend_ink
Forum Contributor
Posts: 151
Joined: Sun Apr 20, 2003 1:18 am
Location: Las Vegas | London

[SOLVED] fetch_row issue

Post by reverend_ink »

I have a problem, the following code pulls all from the DB but doesn't right the proper tblID for the first row listing.

Can anyone help?

Thanks in advance!

Code: Select all

<?php
$query="select tblID from mngENTRIES WHERE contestID = '$id' ORDER by tblID ASC";
$result = mysql_query($query);
$num_rows=mysql_num_rows($result);
for ($i=1; $i<=$num_rows; $i++) $newData[]=mysql_fetch_array($result);
     mysql_close;
     for ($i=1; $i<=$num_rows; $i++) {
 	$newData[]=mysql_fetch_array($result);
	$currentRow = $newData[$i];
        echo "<td><a href=entry_detail.php?id=".$currentRow[0]."><img src=entry/tn_".$currentRow[0].".jpg width=40 border=1><br>".$currentRow[0]."</a></td>\n";

	if(($i % 2) == 0) {
		echo "</tr>\n<tr>\n";
	}
     }

?>
?>

[Edit: Added [SOLVED] to the topic, if you don't mind. --JAM]
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post by liljester »

im not sure why you are running 2 loops?

try this:

Code: Select all

$query="select tblID from mngENTRIES WHERE contestID = '$id' ORDER by tblID ASC"; 
$result = mysql_query($query); 
$num_rows=mysql_num_rows($result);
for($i = 0; $i < $num_rows; $i++){
    $newData[]=mysql_fetch_array($result);
    print"<td><a href=entry_detail.php?id=".$newData[0]."><img src=entry/tn_".$newData[0].".jpg width=40 border=1><br>".$newData[0]."</a></td>\n";
    if(($i % 2)){
        print"</tr>\n<tr>\n";
    }
}
reverend_ink
Forum Contributor
Posts: 151
Joined: Sun Apr 20, 2003 1:18 am
Location: Las Vegas | London

Post by reverend_ink »

That almost worked, but now $newData[0] writes the work Array instead of the numeric value.
reverend_ink
Forum Contributor
Posts: 151
Joined: Sun Apr 20, 2003 1:18 am
Location: Las Vegas | London

Post by reverend_ink »

thanks liljester

After some tweaking I got it!

Today you are my hero, I was up till 4AM and back up at 7AM to get work done and this one(be it tired or being stupid) couldnt get for the life of me.

:twisted:
Post Reply