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