Akenatehm Posted March 10, 2009 Share Posted March 10, 2009 Hey Guys, I am trying to create a mini news system. Here is the code: <html> <body> <?php $dbhost = "localhost"; $dbuser = "user"; $dbpass = "pass"; $dbname = "game"; $connect = mysql_connect($dbhost,$dbuser,$dbpass); $selectdb = mysql_select_db($dbname); $selectentries = mysql_query("SELECT * FROM news"); $filterentries = mysql_fetch_assoc($selectentries); $title = $filterentries['title']; $content = $filterentries['content']; $author = $filterentries['author']; $date = $filterentries['date']; $arr=array("$title" ); foreach ($arr as $value) { echo "$title - " . "$date" ."<br /> <br /> "; echo "Content: " . $content . "<br /> <br />"; echo "Posted By: " . "$author <br />"; } ?> </body> </html> It is only displaying the first entry in the database. Could you please help me in making it show all of them. Thanks in Advanced, Cody Link to comment https://forums.phpfreaks.com/topic/148722-looping-data/ Share on other sites More sharing options...
aseaofflames Posted March 10, 2009 Share Posted March 10, 2009 your loop is completely wrong. $filterentries = mysql_fetch_assoc($selectentries); fetches the first row and then the next if it is called again...and so on... change it to while($filterentries = mysql_fetch_assoc($selectentries)) { and remove $arr=array("$title" ); foreach ($arr as $value) { should work (not tested) aseaofflames Link to comment https://forums.phpfreaks.com/topic/148722-looping-data/#findComment-780899 Share on other sites More sharing options...
Akenatehm Posted March 10, 2009 Author Share Posted March 10, 2009 Thanks for that. Works great now. One other thing. I have set a background colour for a DIV through CSS and I want to be able to echo into the DIV and make it auto extend. Is this possible? Link to comment https://forums.phpfreaks.com/topic/148722-looping-data/#findComment-780903 Share on other sites More sharing options...
aseaofflames Posted March 10, 2009 Share Posted March 10, 2009 Thanks for that. Works great now. One other thing. I have set a background colour for a DIV through CSS and I want to be able to echo into the DIV and make it auto extend. Is this possible? put the php code inside of the <div> Link to comment https://forums.phpfreaks.com/topic/148722-looping-data/#findComment-780907 Share on other sites More sharing options...
Akenatehm Posted March 10, 2009 Author Share Posted March 10, 2009 I have, and the DIV tag doesnt expand for it. Link to comment https://forums.phpfreaks.com/topic/148722-looping-data/#findComment-780917 Share on other sites More sharing options...
aseaofflames Posted March 16, 2009 Share Posted March 16, 2009 What is your css code for the div? Link to comment https://forums.phpfreaks.com/topic/148722-looping-data/#findComment-786200 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.