Jump to content

Recommended Posts

Ive got this to get news posts from my database to display on the home page. The problem is the both the Users table and Forum_Topics table have an ID and Name field that I need. The result is the 2nd one to be selected seem to overwrite the 1st one...

 

How can I get and display both Forum_Topics.ID, Forum_Topics.Name, Users.ID and Users.Name ?

$query = mysql_query("
SELECT Forum_Topics.ID, Forum_Topics.Name, Forum_Topics.Date_Created, Forum_Topics.First,
Forum_Posts.Topic, Forum_Posts.Content,
Users.ID, Users.Name
FROM Forum_Topics, Forum_Posts , Users
WHERE Forum_Topics.Section = 1 AND Forum_Topics.First = Forum_Posts.ID AND Users.ID = Forum_Posts.User
ORDER BY Forum_Topics.Date_Created DESC") or exit(mysql_error());

while ($data = mysql_fetch_array($query))
{
	echo
		'<div class="news_body">'."\n".
		//HEADER
		'  Subject: <a href="'. $url_forum . 'view_topic.php?id=' . $data['ID'] . '">' .
		    $data['Name'] .
		'  </a>' .
		' Posted on: '.$data['Date_Created'].
		' By: <a href="'. $url_root . 'users.php?id=' . $data['ID'] . '">' .$data['Name'] . '</a>' .
		//CONTENT
		' <div class="news_content">' . "\n" .
		$data['Content'] .
		" </div>\n</div>\n";
}

Link to comment
https://forums.phpfreaks.com/topic/84175-problem-getting-post-data-from-database/
Share on other sites

do a print_r($data) and see if they are both stored in the array or not.

 

May have to use $data[number] instead of fieldname to get to it, unless the array takes $data[users.ID]

 

What I do in my tables is not have the ID fieldname the same.  My users ID is uid, my Topics ID is tid..etc.

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.