kira-chan Posted September 25, 2008 Share Posted September 25, 2008 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 More sharing options...
DarkWater Posted September 25, 2008 Share Posted September 25, 2008 You called mysql_fetch_assoc() once before the loop, effectively throwing out the first result. Link to comment https://forums.phpfreaks.com/topic/125839-while-loop-not-showing-all-results/#findComment-650690 Share on other sites More sharing options...
kira-chan Posted September 25, 2008 Author Share Posted September 25, 2008 I see. Throwing that out makes it work perfectly! Thanks! Link to comment https://forums.phpfreaks.com/topic/125839-while-loop-not-showing-all-results/#findComment-650691 Share on other sites More sharing options...
PFMaBiSmAd Posted September 25, 2008 Share Posted September 25, 2008 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? Link to comment https://forums.phpfreaks.com/topic/125839-while-loop-not-showing-all-results/#findComment-650692 Share on other sites More sharing options...
DarkWater Posted September 25, 2008 Share Posted September 25, 2008 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? Lol, I'm always curious about that too. Link to comment https://forums.phpfreaks.com/topic/125839-while-loop-not-showing-all-results/#findComment-650695 Share on other sites More sharing options...
kira-chan Posted September 25, 2008 Author Share Posted September 25, 2008 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. Link to comment https://forums.phpfreaks.com/topic/125839-while-loop-not-showing-all-results/#findComment-650709 Share on other sites More sharing options...
discomatt Posted September 26, 2008 Share Posted September 26, 2008 I found a few of my teachers did that too Screw core stuff, just give them a bunch of libraries and get right on to full application development. Link to comment https://forums.phpfreaks.com/topic/125839-while-loop-not-showing-all-results/#findComment-650904 Share on other sites More sharing options...
redarrow Posted September 26, 2008 Share Posted September 26, 2008 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........ Link to comment https://forums.phpfreaks.com/topic/125839-while-loop-not-showing-all-results/#findComment-650907 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.