Jump to content

[SOLVED] display all rows with a specific entry?


marksie1988

Recommended Posts

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";
				}
		?>

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 />";
}

Also caregory might/should be category :)

 

oo well spotted hehe :P

 

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

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.