Ell20 Posted October 23, 2007 Share Posted October 23, 2007 Hey guys, Ive got my page set up correctly as far as getting data into the database goes however I am not sure how to display it all on the page. Basically I have a news table: news_id, club_id, title, news I would like to display all the news items associated with the club that the user is logged into. Id like each news item to be separated so that its easy to identify they are different news items e.g. __________________________ $title $news __________________________ $title $news __________________________ Appreciate any help Cheers Elliot Link to comment https://forums.phpfreaks.com/topic/74492-solved-display-data-on-page/ Share on other sites More sharing options...
atlanta Posted October 23, 2007 Share Posted October 23, 2007 Hey guys, Ive got my page set up correctly as far as getting data into the database goes however I am not sure how to display it all on the page. Basically I have a news table: news_id, club_id, title, news I would like to display all the news items associated with the club that the user is logged into. Id like each news item to be separated so that its easy to identify they are different news items e.g. __________________________ $title $news __________________________ $title $news __________________________ Appreciate any help Cheers Elliot something to this sort $query = "select * from news"; $results = mysql_query($query); while ($row = mysql_fetch_array($result)) { echo $row['news_id']; echo $row['club_id']; echo $row['title']; echo $row['news']; echo "<hr>"; \\ adds a horizontal line between echo set of data } you can edit the query to be more specific with the data Link to comment https://forums.phpfreaks.com/topic/74492-solved-display-data-on-page/#findComment-376456 Share on other sites More sharing options...
manixrock Posted October 23, 2007 Share Posted October 23, 2007 I suppose you're also inquiring about connecting to the database: <?php // You connect to the database like: mysql_connect('database_path', 'username', 'password'); // I used the default values here, you should replace them with your values (which, unless you changed them, are the default ones): mysql_connect('localhost', 'root', '') or die('Could not connect to the database.'); mysql_select_db('mydatabase'); $result = mysql_query('SELECT news_id, club_id, title, news FROM mytable'); while ($row = mysql_fetch_assoc($result)) { echo "$row[news_id], $row[club_id], $row[title], $row[news]<HR>\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/74492-solved-display-data-on-page/#findComment-376468 Share on other sites More sharing options...
Ell20 Posted October 23, 2007 Author Share Posted October 23, 2007 Thanks for the suggestions. Im ok connecting to database. I get this error from your suggestions: Suggestion 1: An error occured in script c:\program files\easyphp1-8\www\html\news.php on line 41: Undefined variable: resultAn error occured in script c:\program files\easyphp1-8\www\html\news.php on line 41: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Suggestion 2: An error occured in script c:\program files\easyphp1-8\www\html\news.php on line 41: Undefined variable: resultAn error occured in script c:\program files\easyphp1-8\www\html\news.php on line 41: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource Cheers Link to comment https://forums.phpfreaks.com/topic/74492-solved-display-data-on-page/#findComment-376471 Share on other sites More sharing options...
Ell20 Posted October 23, 2007 Author Share Posted October 23, 2007 Just discovered a typo on one of the suggestions. Working now, thanks alot Link to comment https://forums.phpfreaks.com/topic/74492-solved-display-data-on-page/#findComment-376473 Share on other sites More sharing options...
atlanta Posted October 23, 2007 Share Posted October 23, 2007 coolio which one did u get to work ? Link to comment https://forums.phpfreaks.com/topic/74492-solved-display-data-on-page/#findComment-376481 Share on other sites More sharing options...
Ell20 Posted October 23, 2007 Author Share Posted October 23, 2007 Your one Link to comment https://forums.phpfreaks.com/topic/74492-solved-display-data-on-page/#findComment-376503 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.