marksie1988 Posted August 12, 2007 Share Posted August 12, 2007 i have some code which displays information from a table as links, the links are split up into categories and then should all be displayed under their category but for some reason i can only get it to display one row not all rows please help :S <?php $query = "SELECT * FROM links ORDER BY title"; $result = mysql_query ($query); while ($row = mysql_fetch_assoc ($result)) { $category = html_entity_decode($row['category']); $link = html_entity_decode($row['link']); $title = html_entity_decode($row['title']); $desc = html_entity_decode($row['description']); } if($caregory == music){ echo"<a href='$link' title='$desc' target='_blank'>$title</a>"; } else{ echo"There are no links"; } ?> Link to comment https://forums.phpfreaks.com/topic/64562-solved-display-all-rows-with-a-specific-entry/ Share on other sites More sharing options...
Orio Posted August 12, 2007 Share Posted August 12, 2007 You need to print the link inside the loop. This way it only prints the last one (or nothing). Orio. Link to comment https://forums.phpfreaks.com/topic/64562-solved-display-all-rows-with-a-specific-entry/#findComment-321827 Share on other sites More sharing options...
NArc0t1c Posted August 12, 2007 Share Posted August 12, 2007 Look at this line: if($caregory == music){ You cannot point to such a statement. it is text, and it should be in quotes. But I would suggest that you rather have more than one query if you want to display data under categories. For example: <?php if (empty($_GET['cat'])){ $cat = 'music'; } else { $cat = htmlspecialchars($_GET['cat']); $query = "SELECT title FROM links WHERE category=".$cat." LIMIT 10"; $result = mysql_query($query) or die(mysql_error()); echo "Showing data ordered by " . $cat . "<br />"; while($row = mysql_fetch_assoc($result)){ echo $row['title'] . "<br />"; } Link to comment https://forums.phpfreaks.com/topic/64562-solved-display-all-rows-with-a-specific-entry/#findComment-321828 Share on other sites More sharing options...
keeB Posted August 12, 2007 Share Posted August 12, 2007 Also caregory might/should be category Link to comment https://forums.phpfreaks.com/topic/64562-solved-display-all-rows-with-a-specific-entry/#findComment-321839 Share on other sites More sharing options...
marksie1988 Posted August 13, 2007 Author Share Posted August 13, 2007 Also caregory might/should be category oo well spotted hehe unfortunatly the way that my page code works i will have to do the query's seperatley i was trying to do it as one but it messes up my page as its mainly html Link to comment https://forums.phpfreaks.com/topic/64562-solved-display-all-rows-with-a-specific-entry/#findComment-322216 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.