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
https://forums.phpfreaks.com/topic/89670-how-to-use-two-tables-at-the-same-time/
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.

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

<?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 ...............................

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.