0

I currently have a linked table from two tables in one database. I would like to add information from a third table contained in another database. The code for the current table is:

<?php
$con = mysql_connect("","","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("", $con);

$result = mysql_query("SELECT A.Company, A.CStatus, A.OnlineLvl, B.CustomerID, B.Name, C.OrderID, C.DateCall, C.WStatus
FROM A, B, C WHERE A.CompanyID=C.CompanyID and B.CustomerID=C.CustomerID ") or die(mysql_error());

echo "<table border='1'>
<tr>
<th>Company</th>
<th>Company Status</th>
<th>Online Level</th>
<th>Customer ID</th>
<th>Customer Name</th>
<th>Order ID</th>
<th>Date of Call</th>
<th>Order Status</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['Company'] . "</td>";
  echo "<td>" . $row['CStatus'] . "</td>";
  echo "<td>" . $row['OnlineLvl'] . "</td>";
  echo "<td>" . $row['CustomerID'] . "</td>"; 
  echo "<td>" . $row['Name'] . "</td>";
  echo "<td>" . $row['OrderID'] . "</td>";
  echo "<td>" . $row['DateCall'] . "</td>";
  echo "<td>" . $row['WStatus'] . "</td>";
  echo "</tr>";
  }
echo "</table>";
mysql_close(

I would like to add information from another table called 'phonecall' contained in database 'iphone'. I understand that you can call up information by putting the "database.table.row" in the select, from, and where for all the bits of information. However, how should I connect to the databases at this section of code:

mysql_select_db("", $con);

Do I put both database names here?

Thanks for any help!

2
Contributors
2
Replies
6
Views
6 Years
Discussion Span
Last Post by pritaeas
0

Since no one replied I continued working on it and this is what I figured out.
In the section I put:

mysql_select_db("database1 and database2", $con);

This worked but I also identified all of the variables by databasename.tablename.row

0

That code will fail. But it will not affect your queries if they specify the database names. So you can use it to select one of them, or just remove the line entirely.

Just a sample query:

SELECT * FROM database1.table1 t1, database2.table2 t2 WHERE t1.id = t2.id

Edited by pritaeas: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.