Jump to content

Recommended Posts

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

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

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";
}
?>

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.