tags:

views:

36

answers:

2

Hi

I would like to select multiple table in one query say like below and insert into multiple table:

$result = $db->sql_query("SELECT * FROM data1,data2,data3,data4 WHERE person='" .$name. "'");

$row = $db->sql_fetchrow($result);
$day = $row['regtime'];
$days = (strtotime(date("Y-m-d")) - strtotime($row['regtime'])) / (60 * 60 * 24);
if($row > 0 && $days < 15){

$row = ['name'];
$row = ['age'];

//etc

}else { //do something 

if ($row == 0 && $name > 0){
$db->sql_query("INSERT INTO data1 ??????

}

This seems problem as days are not been calculated hence it always process new data and not accessing stored data in table...

Is there any way which this can get work??

A: 

Mysql UNION ?

Gabriel Sosa
+1  A: 

It looks like you want to use a join. There are a lot of different joins, but all of them involve asking for one or more columns in the first table to be lined up with one or more columns in the second table. In your query above, you're including lots of tables in the FROM clause, but you aren't specifying how the tables should be joined together.

Without knowing what each table looks like, it's hard to give an example using your tables. The link I provided above has many, many examples.

Charles
there is a problem in Join the $name variable is filled with user search...So I need to search $name in all tables
mathew
It sounds like the name column is the one you want to use to join all the tables together then! `SELECT * FROM table1, table2 WHERE table1.name = table2.name AND table1.name = ?`
Charles
Yes I need to combine name column and then call them with user search name...but in your example you shown only two and I got 4..then how I change this according to??
mathew
Read the article I linked. :) Just follow the pattern: match the column in table 1, then join 1 to 2, then 2 to 3, then 3 to 4, and so on.
Charles
great it worked I got the Idea from your example..thank you very much..it took quite time but worked well..
mathew