| | |
retrieving a single cell of data from a MySQL database
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
Is it possible to retrieve one cell of data from a MySQL database? I need to put the ID from one row of a table into a php variable so that I can recall the correct row later on for editing purposes. If you know how to do this please help me! I will post my code if you ask me to.
Last edited by sickly_man; Jun 25th, 2007 at 4:37 pm.
Henry Phillips
Web Programmer
Adirondack Area Network, LLC
Web Programmer
Adirondack Area Network, LLC
Yes. Just select that one column name and use a WHERE clause to limit it to the one row you want:
SELECT column_name FROM table_name WHERE spme_column = 'some value'
SELECT column_name FROM table_name WHERE spme_column = 'some value'
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
[sql]
SELECT ip_id FROM test WHERE network = '10.0.0.1'
[/sql]
so i've got that much already....what i need to do is query the database and get that ip_id number into a php variable or an html hidden input container......do you know how to do that?
SELECT ip_id FROM test WHERE network = '10.0.0.1'
[/sql]
so i've got that much already....what i need to do is query the database and get that ip_id number into a php variable or an html hidden input container......do you know how to do that?
Henry Phillips
Web Programmer
Adirondack Area Network, LLC
Web Programmer
Adirondack Area Network, LLC
This is pretty basic PHP/MySQL. Have you read any tutorials on this yet? How much code have you written so far?
Last edited by stymiee; Jun 26th, 2007 at 11:38 am.
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
i should be a little more specific. i can get to the point where i have the $result array that has the results of that query we were talking about.
[PHP]
// run the query on the connection
if (!($result = @ mysql_query ($query, $connection)))
showerror();
[/PHP]
i don't know what to do with the $result array to retrieve this one piece of data (an ID). The query only asks for one piece of data so the array should only have one item in it. So that's where I'm at
[PHP]
// run the query on the connection
if (!($result = @ mysql_query ($query, $connection)))
showerror();
[/PHP]
i don't know what to do with the $result array to retrieve this one piece of data (an ID). The query only asks for one piece of data so the array should only have one item in it. So that's where I'm at
Henry Phillips
Web Programmer
Adirondack Area Network, LLC
Web Programmer
Adirondack Area Network, LLC
•
•
Join Date: Jul 2004
Posts: 494
Reputation:
Solved Threads: 21
Take a look at the mysql_fetch* functions and mysql_result. I've got a feeling that mysql_result will do what you want.
(You can simply type "MySQL" in php.net's search box to bring up a page that lists most the MySQL functions.)
(You can simply type "MySQL" in php.net's search box to bring up a page that lists most the MySQL functions.)
www.uncreativelabs.net
Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
To get a specific thing out of the array, you can use
where $result is the executed query, and $columnname is the name of the column you want.
Or if its just one use:
where 0 is the position of the column you want. (In your SQL statement, like SELECT `name`,`bob`... bob would be 1, name would be 0 ect...)
php Syntax (Toggle Plain Text)
$array = mysql_fetch_array($result); $whatever = $array[columnname]
Or if its just one use:
php Syntax (Toggle Plain Text)
$whatever = mysql_result($result,0);
Last edited by WhiteLeo; Jun 27th, 2007 at 8:35 am.
![]() |
Similar Threads
- How To Connect Remote Mysql Database (Visual Basic 4 / 5 / 6)
- Error message while importing data to Excel from the MySQL db (MySQL)
Other Threads in the PHP Forum
- Previous Thread: Parse error: parse error, unexpected T_STRING
- Next Thread: Can't connect to MySQL server on 'localhost' (10061)
| Thread Tools | Search this Thread |
5.2.10 action apache api array beginner beneath binary broken cakephp checkbox class classes cms code cron curl database date destroy display dynamic echo echo$_get[x]changingitintovariable... email encode error fcc file files folder form forms function functions google header howtowriteathesis href htaccess html image images include insert ip javascript joomla limit link local login mail memberships menu mlm mod_rewrite multiple multipletables mysql mysqlquery neutrality oop open passwords paypal pdf php provider query radio random record remote rss script search server sessions sockets source space sql strip_tags syntax system table template thesishelp tutorial update upload url validator variable video voteup web window.onbeforeunload=closeme; youtube






