Forum Moderators: coopster

Message Too Old, No Replies

Mysql join issues, pulling data from only one table

         

smartie231

6:25 pm on Jul 11, 2010 (gmt 0)

10+ Year Member




Alright so attached below is my code for joining the two tables, and it does work... sort of. When I parse the data out on to the page it only displays the units_notes table and not the units tables.

I tried everything i can think of but it doesn't work. Currently right now when the data parses out it shows the units_notes id as the row'id' and not the unit id.

You should know I did try $row['units.id'] and that displays nothing but $row['id'] does.




<?
include 'includes/config.php';
$today = date("Y-m-d");
$query = "SELECT
units.id,
units.first,
units.last,
units.hphone,
units.cphone,
units.closed,
units_notes.id,
units_notes.unitid,
units_notes.date,
units_notes.wtc,
units_notes.woc
FROM
units
RIGHT JOIN
units_notes
ON
units.id = units_notes.unitid
WHERE
units.closed = 'N'
AND
units_notes.date = '2010-07-10'

ORDER BY units.id desc";

$result = mysql_query($query) or die(mysql_error());


print "this page is working";
print "<table>\n
<tr>
<td>ID</td>
<td width='50'>First</td>
<td width='100'>Last</td>
<td width='100'>Home phone</td>
<td width='100'>Cell phone</td>
<td width='150'>Description</td>
<td width='100'>Recieved</td>
<td width='50'>Call</td>
</tr>";
while($row = mysql_fetch_array($result)) {
print "<tr><td><a href='unit_information2.php?id=".$row['id']."'>".$row['id']."</a></td><td>"
. $row['date'] . "</td><td>"
. $row['date'] . "</td><td>"
. $row['units.hphone'] . "</td><td>"
. $row['units.cphone'] . "</td></tr>\n";
}
print "</table>";
?>

LifeinAsia

6:49 pm on Jul 11, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Welcome [webmasterworld.com] to the Forums, smartie231!

The problem is that you are pulling 2 fields called "ID" from the tables. Try using an alias:
SELECT units.id AS UnitsID,...
then use ".$row['UnitsID']." to reverence that value.

smartie231

11:01 pm on Jul 11, 2010 (gmt 0)

10+ Year Member



thanks I figured it out! :)