Jump to content

Really wierd coding error - Please help!


georgebates

Recommended Posts

Hello. I am new to PHP and am having some really annoying problems.

 

I have this code that reads entries in a database and then puts them on the page. Each database entry has a category name. When i found the code it just displayed all the entries on the one page but i want it to only display the entries from a certain category name (say all the ones with category name of 'Brian Strong'). So i looked through the code and added in some bits that i though would work.

 

1) I added the $user with a value of "Brian Strong"

 	$user="Brian Strong";

 

2) I added an if statement so that if the category name on that entry was the same as $user then it would display that entry.

 if ($user=$row['category_name']) {	

	print '<div id="ref_links">';
	print "<h3>Painting Name: ".$row['topic_name']."</h3>\n";
	print "<p>Price: ".$row['topic_desc']."</p>\n";
	print '<br/>'."\n";
	print "<a href=".$row['topic_url']."><img src=".$row['topic_url']." /></a>";
	print '<p><a href="art_inquiry_form.html">Inquire</a></p>'."\n";


  $lastCat = $row['category_name']; // record which category this listing was in so we can test if the cat. changes
  }
  

 

3) I put an else if statement so that if it wasn't the same category then it would print that entry,

else if ($user<>$row['category_name']) {
  
  print "none";
  }
  

 

But my problem is that it still just prints all the entrys in the database. Anyone's help would be very much appreciated and i would gladly pay someone if they could help to fix this.

 

Thanks

 

Edit: Oh and heres the whole code put together.

 <?php 



$myResult = mysql_query('SELECT ref_links.*, ref_categories.category_name FROM ref_links, ref_categories WHERE ref_links.ref_categories_id=ref_categories.id ORDER BY ref_categories_id, ref_links.topic_name', $connectID)
  or die ("Unable to select from database");

	$user="Brian Strong";

while ($row=mysql_fetch_array($myResult, MYSQL_ASSOC)) {
  $thisCat= $row['category_name'];
//print the category heading, but only once for the listings in that catagory
if ($lastCat<>$thisCat) { // true first time($lastCat not set), and each time a new category is found
			print "<h2>".$row['category_name']."</h2>";  // print the next category heading
	}

	 if ($user=$row['category_name']) {	

	print '<div id="ref_links">';
	print "<h3>Painting Name: ".$row['topic_name']."</h3>\n";
	print "<p>Price: ".$row['topic_desc']."</p>\n";
	print '<br/>'."\n";
	print "<a href=".$row['topic_url']."><img src=".$row['topic_url']." /></a>";
	print '<p><a href="art_inquiry_form.html">Inquire</a></p>'."\n";


  $lastCat = $row['category_name']; // record which category this listing was in so we can test if the cat. changes
  }
  
   else if ($user<>$row['category_name']) {
  
  print "none";
  }
  
    print "</div>\n";  //end of ref_links div
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/184929-really-wierd-coding-error-please-help/
Share on other sites

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.