SyncViews Posted January 2, 2008 Share Posted January 2, 2008 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"; } Quote Link to comment https://forums.phpfreaks.com/topic/84175-problem-getting-post-data-from-database/ Share on other sites More sharing options...
revraz Posted January 2, 2008 Share Posted January 2, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84175-problem-getting-post-data-from-database/#findComment-428503 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.