php & mySQL
The Problem: I have two tables and I want to compare the values of a column in table one with a column in table two.
If there is a match, I want to write a row to a results table which displays the name of the company (only appears in table 2) and I want to merge it with the rest of the record from table one on the match.
table one : phone_table
columns : date, time, length, trnk, dir, city_state, dialed
table two : phone2_table
columns : client, phone_number, phone_number2, company, contact
If phone_table.dialed matches any phone2_table.phone_number I want to print a row which shows all of phone_table + phone2_table.phone_number
At this time, this is the result I am getting :
http://www.jbai2.com/m.php
from using this code: (what am I doing wrong)
$sql01 = "SELECT phone_table.*, phone2_table.company FROM phone_table, phone2_table WHERE phone_table.dialed = phone2_table.phone_number";
$result01 = mysql_query($sql01) or die(mysql_error());
echo $result01;
$total_recs = 0;
while($myrow = mysql_fetch_array($result01))
{
$call_date = $myrow["phone_table.date"];
$call_time = $myrow["phone_table.time"];
$call_length = $myrow["phone_table.length"];
$call_trnk = $myrow["phone_table.trnk"];
$call_dir = $myrow["phone_table.dir"];
$call_city_state = $myrow["phone_table.city_state"];
$call_dialed = $myrow["phone_table.dialed"];
$company = $myrow["phone2_table.company"];
$pn = $myrow["phone2_table.phone_number"];
echo "Call Date: $call_date<br>";
echo "Call Time: $call_time<br>";
echo "Call Length: $call_length<br>";
echo "Call Trnk: $call_trnk<br>";
echo "Call Directory: $call_dir<br>";
echo "Number Dialed: $call_dialed<br>";
echo "Company : $company<br>";
echo "PhoneNumber : $pn";
echo "<br><br>";
$total_recs++;
echo "Total Records :$total_recs";
}