Jump to content

How to use two tables at the same time?


Zephyris

Recommended Posts

Like this:

 

section1_news(id, title, msg, datetime)

section2_news(id, title, msg, datetime)

 

like: $result = mysql_query("SELECT * FROM section1_news, section2_news");

 

but like by datetime and LIMIT of 5 rows.

 

outputing the most recent news from the combined two tables.. displaying a max of 5 results.

Link to comment
Share on other sites

If both your tables have the exact same columns, they should be in one table. Just add another column to differentiate between the two sets of data.

 

For example, if you have a table called Japanese news, and a table called English news, and the column names are exactly the same, you should just use one table called news, then add an extra column called country, filling it in with the applicable country from which the news came from.

 

Then when you are doing your query, you set your query conditions and leave out any reference to country, and it will bring back all news.

Link to comment
Share on other sites

my test script is basicly

 

<?php

// Get Gaming Headlines

$result = mysql_query("SELECT * FROM `gaming_news`, `community_news`");

 

while($row = mysql_fetch_array($result) ){

                              echo("<td class='10whitebold'>" . ($row['title']) . "</td>");

                            }

?>

 

only displays community news

Link to comment
Share on other sites

<?php

                    // Get Gaming Headlines

                    $result = mysql_query("SELECT * FROM `gaming_news`, `community_news`");

                   

                    while($row = mysql_fetch_array($result) ){

                              echo("<td class='10whitebold'>" . ($row['title']) . "</td>");

                            }

?>

 

Dear you are just using $row['title'] title to show the title from two pages you are not mentioning the

anyother thing to show you like date or other

try to do like this

 

 

while($row = mysql_fetch_array($result) ){

  echo("<td class='10whitebold'>" . ($row['title']) . "</td>");

  echo("<td class='10whitebold'>" . ($row['news']) . "</td>");

  echo("<td class='10whitebold'>" . ($row['date']) . "</td>");

or any other coulmn

}

 

if you still not able to do it let me know ...............................

 

 

 

 

Link to comment
Share on other sites

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.