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!! Link to comment https://forums.phpfreaks.com/topic/150352-sql-join-question/ 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 Link to comment https://forums.phpfreaks.com/topic/150352-sql-join-question/#findComment-789614 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.. Link to comment https://forums.phpfreaks.com/topic/150352-sql-join-question/#findComment-789620 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 Link to comment https://forums.phpfreaks.com/topic/150352-sql-join-question/#findComment-789635 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 Link to comment https://forums.phpfreaks.com/topic/150352-sql-join-question/#findComment-791585 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 Link to comment https://forums.phpfreaks.com/topic/150352-sql-join-question/#findComment-791640 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.