Page 1 of 1

MYSQL List Problem

Posted: Fri Jul 13, 2007 12:56 pm
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);

Posted: Fri Jul 13, 2007 1:29 pm
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?

Posted: Fri Jul 13, 2007 1:59 pm
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

Posted: Fri Jul 13, 2007 2:08 pm
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");

Posted: Fri Jul 13, 2007 6:07 pm
by Suraski
no, that didn't work either

Posted: Fri Jul 13, 2007 6:27 pm
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";
}