Jump to content

while loop not showing all results


kira-chan

Recommended Posts

I'm trying to get this while loop to display 4 separate links, but it refuses to display the first one for some reason.

 

$sql =  "SELECT projects. * , categories. * FROM projects, categories " . 
	"WHERE categories.id = " . $validentry . 
	" AND projects.cat_id = " . $validentry . 
	" LIMIT 4";
$result = mysql_query($sql);

$row = mysql_fetch_assoc($result);

$numrows = mysql_num_rows($result);

$i = 1;

while($row = mysql_fetch_assoc($result)) {
echo "<a href='projectpage.php?id=" . $row['pid'] . "'>" . $row['name'] . "</a><br>";
$i++;
}

 

projects.cat_id and catagories.id are the same number. The query returns 4 results, but the while loop refuses to display the first one.

Link to comment
https://forums.phpfreaks.com/topic/125839-while-loop-not-showing-all-results/
Share on other sites

I keep seeing code with this problem in the forum and I truly want to know where people keep coming up with code that fetches and discards the first row? Where did you get this code from?

I'm pasting together snippets of code from a college book, and I just ended up pasting that piece without realizing I didn't need it. Most people are probably in the same situation - they think they need that piece of code because they've needed it before, but they don't know they don't need it if they're also using it in a loop.

Ive noticed a lot wrong with the code you need to do a proper mysql tutoral, copy and past dosent work...........................................................

 

schools charge 3000 pound for a course and it profetic,all you need is the php.net manual and the mysql manual

there your best friend..............

 

collage sucks i no been there done that exspected to learn the whole off php in 10 lession yeee rite

been only programmnig for over 5 years what a joke ..............

 

still learning........

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.