shyish Posted August 15, 2009 Share Posted August 15, 2009 I'm trying to set up a simple query to get the news from a datbase... so heres the code I used <?php $host="localhost"; $username="root"; $password="XXXXXX"; $database="vd"; mysql_connect($host,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM articles"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <?php $i=0; while ($i < $num) { $title=mysql_result($result,$i,"title"); $author=mysql_result($result,$i,"Author"); $body=mysql_result($result,$i,"body"); ?> and then at the end of the page I got <?php $i++; } ?> And ofcourse in the table for my news in the HTML I just add $title, $body, $autor. The problem is for each column in the database it repeats the entire page... Help? Link to comment https://forums.phpfreaks.com/topic/170395-solved-php-news-error/ Share on other sites More sharing options...
smerny Posted August 15, 2009 Share Posted August 15, 2009 that would only be the case if you had the entire page within the loop, the only stuff you should put in the loop is the stuff you want to be repeated Link to comment https://forums.phpfreaks.com/topic/170395-solved-php-news-error/#findComment-898870 Share on other sites More sharing options...
Renlok Posted August 15, 2009 Share Posted August 15, 2009 it should be mysql_num_rows( not mysql_numrows( Link to comment https://forums.phpfreaks.com/topic/170395-solved-php-news-error/#findComment-898872 Share on other sites More sharing options...
shyish Posted August 15, 2009 Author Share Posted August 15, 2009 Ok Fixed, thanks Link to comment https://forums.phpfreaks.com/topic/170395-solved-php-news-error/#findComment-898905 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.