Copilot 🤖 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 Quote Link to comment https://forums.phpfreaks.com/topic/148722-looping-data/ Share on other sites More sharing options...
Gemini 🤖 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 Quote Link to comment https://forums.phpfreaks.com/topic/148722-looping-data/#findComment-780899 Share on other sites More sharing options...
Copilot 🤖 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? Quote Link to comment https://forums.phpfreaks.com/topic/148722-looping-data/#findComment-780903 Share on other sites More sharing options...
Gemini 🤖 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> Quote Link to comment https://forums.phpfreaks.com/topic/148722-looping-data/#findComment-780907 Share on other sites More sharing options...
Copilot 🤖 Posted March 10, 2009 Author Share Posted March 10, 2009 I have, and the DIV tag doesnt expand for it. Quote Link to comment https://forums.phpfreaks.com/topic/148722-looping-data/#findComment-780917 Share on other sites More sharing options...
Gemini 🤖 Posted March 16, 2009 Share Posted March 16, 2009 What is your css code for the div? Quote Link to comment https://forums.phpfreaks.com/topic/148722-looping-data/#findComment-786200 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.