MYSQL List Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Suraski
Forum Newbie
Posts: 10
Joined: Tue Jul 10, 2007 10:30 pm

MYSQL List Problem

Post by Suraski »

The script below doesn't list the text from from the database correctly, unless I remove the 'if' statement

Code: Select all

mysql_select_db("news", $blog);
$result = mysql_query("SELECT * FROM news LIMIT 5");
while($row['cat'] = mysql_fetch_array($result))
{
if($row['cat'] == 'Blog')
{
	echo "<t1><a href=\"blog.php\" target=\"_blank\" class=\"s1\">" . $row['title'] . "</a> <br /> </t1>";
}else{}
}
	echo " <br /><a href=\"blog.php\" class=\"s1\">see more...</a> </td>
  </tr>
</table>";
mysql_close($blog);
mentor
Forum Contributor
Posts: 100
Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan

Post by mentor »

Then remove if.

This condition is here to display the data from Blog category.

Code: Select all

if($row['cat'] == 'Blog') 
{ 
        echo "<t1><a href=\"blog.php\" target=\"_blank\" class=\"s1\">" . $row['title'] . "</a> <br /> </t1>"; 
}
else{}

What do you want?
Suraski
Forum Newbie
Posts: 10
Joined: Tue Jul 10, 2007 10:30 pm

Post by Suraski »

I have other entries in the 'cat' column in the table, I want to display just the one's with Blog in the column.

http://www.bensphotosite.com/home/index.php
that's my website, the green table on the right side-bar is where this code starts, you can see that it isn't displaying the data
mentor
Forum Contributor
Posts: 100
Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan

Post by mentor »

Then change your query and remove the if statement. The below query will get only those records where cat=Blog

Code: Select all

result = mysql_query("SELECT * FROM news where cat='Blog' LIMIT 5");
Suraski
Forum Newbie
Posts: 10
Joined: Tue Jul 10, 2007 10:30 pm

Post by Suraski »

no, that didn't work either
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

mysql_select_db("news", $blog) or die(mysql_error());
$result = mysql_query("SELECT title FROM news WHERE cat='Blog' LIMIT 5") or die(mysql_error());
while($row=mysql_fetch_array($result)) {
  echo '<a href="blog.php" target="_blank" class="s1">', htmlentities($row['title']), "</a><br />\n";
}
Post Reply