Re: [PHP] Simple PHP 4 and MySQL question about query
To follow on, one thing this newbie learned is that it is usually best to build the query string and then pass it to the mysql_query funcion. i had some odd results when I had several ( ) in there for my where clause I made it a separate string and presto it works every time. chris On Tue, 20 Mar 2001 13:08:20 +1030, David Robley wrote: On Tue, 20 Mar 2001 12:45, SED wrote: Hi, I'm trying to get a result from the following query: $result = mysql_query("SELECT 'islname' FROM $table WHERE id='$id'"); Because "id" is a unique key in my table, I know it has only one value. What mysql_funtion should I use to echo the result and with what parameters? (I have tried many most of the functions but I don't get the correct result, and the manual is not helping me :) Regards, Sumarlidi Einar Dadason If id is an integer type field, you will not get a result using the query you show. Remove the single quotes around $id as they indicate a text type value. Also you shouldn't need single quotes around islname - so your query might look more like: $result = mysql_query("SELECT islname FROM $table WHERE id=$id"); Then you can use mysql_fetch_array to get row[s] containing an array of all the fields (one!) in your query, and then use extract to put the field values in a variable named as the field. (The example for mysql_fetch_array shows another way of displaying the fetched values.) So: $row = mysql_fetch_array($result); extract($row); echo $islname; -- David Robley| WEBMASTER Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet| http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Simple PHP 4 and MySQL question about query
Hi, I'm trying to get a result from the following query: $result = mysql_query("SELECT 'islname' FROM $table WHERE id='$id'"); Because "id" is a unique key in my table, I know it has only one value. What mysql_funtion should I use to echo the result and with what parameters? (I have tried many most of the functions but I don't get the correct result, and the manual is not helping me :) Regards, Sumarlidi Einar Dadason SED - Graphic Design -- Phone: (+354) 4615501 Mobile: (+354) 8960376 Fax: (+354) 4615503 E-mail: [EMAIL PROTECTED] Homepage:www.sed.is - New Homepage! -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Simple PHP 4 and MySQL question about query
try somethin' like this... $result = mysql_query("SELECT 'islname' FROM $table WHERE id='$id'"); // For one row.. use a zero $islname = mysql_result($result, 0, "islname"); // Otherwise, loop through $islname=mysql_result($result, $i, "islname"); At 02:15 AM 3/20/2001 -, you wrote: Hi, I'm trying to get a result from the following query: $result = mysql_query("SELECT 'islname' FROM $table WHERE id='$id'"); Because "id" is a unique key in my table, I know it has only one value. What mysql_funtion should I use to echo the result and with what parameters? (I have tried many most of the functions but I don't get the correct result, and the manual is not helping me :) Regards, Sumarlidi Einar Dadason SED - Graphic Design -- Phone: (+354) 4615501 Mobile: (+354) 8960376 Fax: (+354) 4615503 E-mail: [EMAIL PROTECTED] Homepage:www.sed.is - New Homepage! -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] art-nude.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Simple PHP 4 and MySQL question about query
On Tue, 20 Mar 2001 12:45, SED wrote: Hi, I'm trying to get a result from the following query: $result = mysql_query("SELECT 'islname' FROM $table WHERE id='$id'"); Because "id" is a unique key in my table, I know it has only one value. What mysql_funtion should I use to echo the result and with what parameters? (I have tried many most of the functions but I don't get the correct result, and the manual is not helping me :) Regards, Sumarlidi Einar Dadason If id is an integer type field, you will not get a result using the query you show. Remove the single quotes around $id as they indicate a text type value. Also you shouldn't need single quotes around islname - so your query might look more like: $result = mysql_query("SELECT islname FROM $table WHERE id=$id"); Then you can use mysql_fetch_array to get row[s] containing an array of all the fields (one!) in your query, and then use extract to put the field values in a variable named as the field. (The example for mysql_fetch_array shows another way of displaying the fetched values.) So: $row = mysql_fetch_array($result); extract($row); echo $islname; -- David Robley| WEBMASTER Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet| http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Simple PHP 4 and MySQL question about query - Problem solved!
Thank you all for your replies. The following solved my problem (from David Robley): -- Also you shouldn't need single quotes around islname - so your query might look more like: $result = mysql_query("SELECT islname FROM $table WHERE id=$id"); -- Then I was able to use: mysql_result($result, 0); to get the result. Regards, Sumarlidi Einar Dadason SED - Graphic Design -- Phone: (+354) 4615501 Mobile: (+354) 8960376 Fax: (+354) 4615503 E-mail: [EMAIL PROTECTED] Homepage:www.sed.is - New Homepage! -- -Original Message- From: SED [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 20, 2001 1:15 PM To: [EMAIL PROTECTED] Subject: [PHP] Simple PHP 4 and MySQL question about query Hi, I'm trying to get a result from the following query: $result = mysql_query("SELECT 'islname' FROM $table WHERE id='$id'"); Because "id" is a unique key in my table, I know it has only one value. What mysql_funtion should I use to echo the result and with what parameters? (I have tried many most of the functions but I don't get the correct result, and the manual is not helping me :) Regards, Sumarlidi Einar Dadason SED - Graphic Design -- Phone: (+354) 4615501 Mobile: (+354) 8960376 Fax: (+354) 4615503 E-mail: [EMAIL PROTECTED] Homepage:www.sed.is - New Homepage! -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]