Re: [PHP-DB] Re: Retrieve information from mutiple tables
It's a no go... This is what I tryed: SELECT User.NickName FROM User, Rights WHERE (User.UserID = Rights.UserID (Rights.MainID = ${row['MainID']} || ISNULL(Rights.MainID)) The only thing I want to be able to retrieve is a list of nicknames (User.NickName) based on MainID. In the Rights Table the MainID value has to be NULL or = ${row['MainID']} Jason Wong wrote: On Monday 22 April 2002 00:53, Prodoc wrote: E.g. I've got two tables (User and Rights) both contianing UserID, I want to retrieve some UserID's from the Rights table and use those UserID's the get the nickname of those users from the User table. (SELECT UserID FROM Rights WHERE...) (SELECT NickName FROM User WHERE...) Is it possible to combine those two statements? Try: SELECT Rights.UserID, User.NickName FROM Rights, User WHERE User.UserID = Rights.UserID -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Retrieve information from mutiple tables
On Monday 22 April 2002 16:04, Prodoc wrote: It's a no go... This is what I tryed: SELECT User.NickName FROM User, Rights WHERE (User.UserID = Rights.UserID (Rights.MainID = ${row['MainID']} || ISNULL(Rights.MainID)) The only thing I want to be able to retrieve is a list of nicknames (User.NickName) based on MainID. In the Rights Table the MainID value has to be NULL or = ${row['MainID']} Does the simple case (without specifying MainID) work? And are you pretty sure that $row['MainID'] actually holds a valid value? Have you tried printing the whole of the above query to see what it actually contains? If it looks valid try copy-paste that query into the mysql command-line to see what comes up. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Ask five economists and you'll get five different explanations (six if one went to Harvard). -- Edgar R. Fiedler */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Retrieve information from mutiple tables
Does the simple case (without specifying MainID) work? And are you pretty sure that $row['MainID'] actually holds a valid value? Have you tried printing the whole of the above query to see what it actually contains? If it looks valid try copy-paste that query into the mysql command-line to see what comes up. I tried the query in the mysql command-line and this does give me the data I want to get. $row['MainID'] does hold a valid value is this should mean I doing something wrong at displaying the values, doesn't it? I just started using mysql and php it will probebly be a stupid mistake I made. I get one or more values back using the mysql command-line and I'm trying to display the values one by one by using $result = mysql_fetch_row (res) (I tried mysql_fetch_array as well) but it only displays one result by using $result[0]. $result[1] or higher doesn't give me anything, what could be the problem? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Retrieve information from mutiple tables
mysql_fetch_array() brings back an associative array by default. It's not $result[0] but instead $results[column_name] Also, you can use is_set() on subarrays. if ((isset($result[col1])) (is_array($result[col1])) (sizeof($result[col1]))) { // do stuff here } Remember that the above SEQUENCE is important. If you deviate from it, you may get unknown variable or other error messages. -Szii - Original Message - From: Prodoc [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, April 22, 2002 2:38 PM Subject: Re: [PHP-DB] Re: Retrieve information from mutiple tables Does the simple case (without specifying MainID) work? And are you pretty sure that $row['MainID'] actually holds a valid value? Have you tried printing the whole of the above query to see what it actually contains? If it looks valid try copy-paste that query into the mysql command-line to see what comes up. I tried the query in the mysql command-line and this does give me the data I want to get. $row['MainID'] does hold a valid value is this should mean I doing something wrong at displaying the values, doesn't it? I just started using mysql and php it will probebly be a stupid mistake I made. I get one or more values back using the mysql command-line and I'm trying to display the values one by one by using $result = mysql_fetch_row (res) (I tried mysql_fetch_array as well) but it only displays one result by using $result[0]. $result[1] or higher doesn't give me anything, what could be the problem? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Retrieve information from mutiple tables
E.g. I've got two tables (User and Rights) both contianing UserID, I want to retrieve some UserID's from the Rights table and use those UserID's the get the nickname of those users from the User table. (SELECT UserID FROM Rights WHERE...) (SELECT NickName FROM User WHERE...) Is it possible to combine those two statements? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Retrieve information from mutiple tables
On Monday 22 April 2002 00:53, Prodoc wrote: E.g. I've got two tables (User and Rights) both contianing UserID, I want to retrieve some UserID's from the Rights table and use those UserID's the get the nickname of those users from the User table. (SELECT UserID FROM Rights WHERE...) (SELECT NickName FROM User WHERE...) Is it possible to combine those two statements? Try: SELECT Rights.UserID, User.NickName FROM Rights, User WHERE User.UserID = Rights.UserID -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* HOW YOU CAN TELL THAT IT'S GOING TO BE A ROTTEN DAY: #15 Your pet rock snaps at you. */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php