Jump to content

newbie problem


Recommended Posts

yeah well i'm stuck here... i know my problem is stupid but i'm still a newbie ><

 

$query78 = "SELECT * from pp_files WHERE category = '$id'"; 
$res78 = mysql_query($query78) or die(mysql_error());   
while($row = mysql_fetch_array($res78)) { 
$picture = $row["picture"];
$vidid = $row["id"];
$rows = mysql_num_rows($res78);
}



if ($rows > 0) {
echo "<br><table width=\"85%\" align=\"center\" cellpadding=\"8\"><tr><td style=\"background: url(1.png); border: 1px dashed #FFFFFF; cellpadding: 5px;\" colspan=\"5\">";
echo "<center><b><font size=\"3\">$vbphrase[ilya]il y a <font size=\"5\">$rows</font> $vbphrase[vids]</font></b><br>";

$query78 = "SELECT * from pp_files WHERE category = '$id'"; 
$res78 = mysql_query($query78) or die(mysql_error());   
while($row = mysql_fetch_array($res78)) { 



echo "<a href=\"videos/video.php?id=$vidid\"><img src=\"";
echo $picture;
echo "\" border=\"0\" alt=\"$vbphrase[vids_click]\"></a>  ";
}

echo "<br><font size=\"2\"><a href=\"videos/submit.php\">$vbphrase[vids_add]</a></font></center></td></tr></table>";
}

 

i have multiple items in tables of my database and i am trying to display all of the pictures, with a link to the corresponding picture

 

my problem is that only the last item is displayed.... If there is 3 entry to display, 3 items will be displayed, but with the same picture (none) and the same link (last id of the array)

Link to comment
Share on other sites

the problem is you loop over the records loading variables, but you don't do anything with those variables until after the loop. so all you get is the last ones. i suggest that you use the variables as you load them or that you load them all into arrays and use them after the loop

 

while($row = mysql_fetch_array($res78)) { // here, you loop over every record setting values, but never using them.
    $picture = $row["picture"];
    $vidid = $row["id"];
   $rows = mysql_num_rows($res78);
}

Link to comment
Share on other sites

i use $vbphrase because i am putting this script inside a vbulletin template... so all $vbphrase variables will be replaced with its corresponding language signification from the vbulletin's language and phrases system.... so basically it's just words and text, but i use it to have both a french and an english version of my site :)

 

oui mon site est en francais ;) Tu parles francais? D'ou viens tu?

Link to comment
Share on other sites

$query78 = "SELECT * from pp_files WHERE category = '$id'"; 
$res78 = mysql_query($query78) or die(mysql_error());   
$rows = mysql_num_rows($res78);
while($row = mysql_fetch_array($res78)) { 
$picture = $row["picture"];
$vidid = $row["id"];

}



if ($rows > 0) {
while($row = mysql_fetch_array($res78)) { 
$picture = $row["picture"];
$vidid = $row["id"];

echo "<br><table width=\"85%\" align=\"center\" cellpadding=\"8\"><tr><td style=\"background: url(1.png); border: 1px dashed #FFFFFF; cellpadding: 5px;\" colspan=\"5\">";
echo "<center><b><font size=\"3\">$vbphrase[ilya]il y a <font size=\"5\">$rows</font> $vbphrase[vids]</font></b><br>";





echo "<a href=\"videos/video.php?id=$vidid\"><img src=\"";
echo $picture;
echo "\" border=\"0\" alt=\"$vbphrase[vids_click]\"></a>  ";

echo "<br><font size=\"2\"><a href=\"videos/submit.php\">$vbphrase[vids_add]</a></font></center></td></tr></table>";
}

 

Je pense qu'il va fonctionner...

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.