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
Suraski
Forum Newbie
Posts: 10 Joined: Tue Jul 10, 2007 10:30 pm
Post
by Suraski » Fri Jul 13, 2007 12:56 pm
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 » Fri Jul 13, 2007 1:29 pm
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 » Fri Jul 13, 2007 1:59 pm
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 » Fri Jul 13, 2007 2:08 pm
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 » Fri Jul 13, 2007 6:07 pm
no, that didn't work either
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Fri Jul 13, 2007 6:27 pm
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";
}