Jump to content

[SOLVED] can't retrieve name field in left join statement


sherric

Recommended Posts

i'm trying to compile data from different tables for a report. this code:

 

$result4 = mysql_query("select reportequipment.id, equipment.name from reportequipment LEFT JOIN equipment

ON reportequipment.id = equipment.id where webid='$myid'")or die(mysql_error());

 

print "<div id='e42' style='position:absolute; left:0px; top:121px; height: 16px; vertical-align:top; width: 215px;'>

<table width=200 border=0>

<div class='title'>Selected Equipment</div>

\n<tr>";

$i = 0;

while ( $row = mysql_fetch_array($result4) ) {

$i++;

echo "<input type='hidden' name='hidDelete' value='$row[id]}' />";

echo "<td>{$row[id]} {$row[name]} </td><td>";

 

 

returns the row id from my reportequipment table, but will not return the row name from the equipment table. if i remove the where statement, it performs fine.  how do i configure this to retrieve all of the data that i need.  btw the where statement filters the first table, the reportequipment. i'm sure that has a bearing, but i dont know how to reflect that in my select stmt.

 

thanks for taking the time to assist.

Link to comment
Share on other sites

hi keith thanks for hollering back at me. 

 

reportequipment is the equipment selected to go with the incident being reported. in this table, i've used the equipment id # to identify.  the equipment table is my list of all equipment, with the id # and the names.  webid is my session #, which is the number that i use to track all transactions for each table.

 

when i enter information into my forms, i can then look and see the info reflected into the correct db table.  my problem is that i'm not sure how to pull out the info for my report. 

 

$result4 = mysql_query("select reportequipment.id, equipment.name from reportequipment LEFT JOIN equipment

ON reportequipment.id = equipment.id where webid='$myid'")or die(mysql_error());

 

with this query, i can return everything that i need, except for the name of the equipment from my equipment list table.  reportequipment.id returns.  equipment.name does not. nor can i return any values for the second table in my query.

 

 

 

Link to comment
Share on other sites

Hi

 

With the LEFT JOIN you are using it will bring back records from reportequipment whether there is a matching row on equipment or not. The only way I can see the cause of the issue you have is if there isn't a matching row on equipment.

 

Which table is webid on? Have you got some sample data and the table declares for us to have a look at.

 

All the best

 

Keith

Link to comment
Share on other sites

hi again keith,

 

rtfm!  and ended up with

 

SELECT reportequipment.*,equipment.*

  FROM reportequipment LEFT JOIN equipment ON reportequipment.equip = equipment.id

WHERE reportequipment.webid='$myid';

 

which gives me the results that i need.  thanks again.  have a good one!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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