Jump to content

SQL JOIN question...


chelnov63

Recommended Posts

Hi i have a join between two table actions and contacts .. both of these tables have a column called id

 

excerpt of my code is:

 

$result_actions = mysql_query("SELECT * FROM actions JOIN contacts ON(actions.contact_id = contacts.id) WHERE date_of_reminder = '$today' AND send_reminder='Y' AND complete='N' ORDER BY contact_id");

while ($row_actions = mysql_fetch_assoc($result_actions))
{
 $id = $row_actions["id"];
echo $id; 
}

 

The above echos out the id associated to the contacts table. However I want the id associated to the actions table to be echoed out ..any ideas how to do this? thanks for your help!!

Link to comment
https://forums.phpfreaks.com/topic/150352-sql-join-question/
Share on other sites

Hi

 

$result_actions = mysql_query("SELECT actions.id as actionsid, contacts.id as contactid FROM actions JOIN contacts ON(actions.contact_id = contacts.id) WHERE date_of_reminder = '$today' AND send_reminder='Y' AND complete='N' ORDER BY contact_id");

while ($row_actions = mysql_fetch_assoc($result_actions))
{
echo $row_actions["actionsid"] . $row_actions["contactid"];
}

 

All the best

 

Keith

Link to comment
https://forums.phpfreaks.com/topic/150352-sql-join-question/#findComment-789614
Share on other sites

Try this

$result_actions = mysql_query("SELECT *,actions.id as actionsid, contacts.id as contactid FROM actions JOIN contacts ON(actions.contact_id = contacts.id) WHERE date_of_reminder = '$today' AND send_reminder='Y' AND complete='N' ORDER BY contact_id");

while ($row_actions = mysql_fetch_assoc($result_actions))
{
echo $row_actions["actionsid"] . $row_actions["contactid"];
}

 

Hi

 

$result_actions = mysql_query("SELECT actions.id as actionsid, contacts.id as contactid FROM actions JOIN contacts ON(actions.contact_id = contacts.id) WHERE date_of_reminder = '$today' AND send_reminder='Y' AND complete='N' ORDER BY contact_id");

while ($row_actions = mysql_fetch_assoc($result_actions))
{
echo $row_actions["actionsid"] . $row_actions["contactid"];
}

 

All the best

 

Keith

Link to comment
https://forums.phpfreaks.com/topic/150352-sql-join-question/#findComment-791640
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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