chelnov63 Posted March 20, 2009 Share Posted March 20, 2009 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!! Quote Link to comment Share on other sites More sharing options...
kickstart Posted March 20, 2009 Share Posted March 20, 2009 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 Quote Link to comment Share on other sites More sharing options...
chelnov63 Posted March 20, 2009 Author Share Posted March 20, 2009 thanks for that Kieth... however is there a way to do that while still using SELECT * ?? As I will be using a lot of other columns from the two tables, only the id column has the same name across tables.. Quote Link to comment Share on other sites More sharing options...
kickstart Posted March 20, 2009 Share Posted March 20, 2009 Hi It is generally bad practice to use SELECT *, so I have never really tried to find a way to do it without specifying an alias for the columns. All the best Keith Quote Link to comment Share on other sites More sharing options...
chelnov63 Posted March 23, 2009 Author Share Posted March 23, 2009 I'll just do it that way then... thanks for your help mate..appreciate it Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted March 23, 2009 Share Posted March 23, 2009 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.