Jump to content

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

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.