retrieving a single cell of data from a MySQL database

Thread Solved

Join Date: Jun 2007
Posts: 42
Reputation: sickly_man is an unknown quantity at this point 
Solved Threads: 0
sickly_man's Avatar
sickly_man sickly_man is offline Offline
Light Poster

retrieving a single cell of data from a MySQL database

 
0
  #1
Jun 25th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,422
Reputation: stymiee is on a distinguished road 
Solved Threads: 35
Moderator
stymiee's Avatar
stymiee stymiee is offline Offline
He's No Good To Me Dead

Re: retrieving a single cell of data from a MySQL database

 
0
  #2
Jun 25th, 2007
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'
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 42
Reputation: sickly_man is an unknown quantity at this point 
Solved Threads: 0
sickly_man's Avatar
sickly_man sickly_man is offline Offline
Light Poster

Re: retrieving a single cell of data from a MySQL database

 
0
  #3
Jun 26th, 2007
[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?
Henry Phillips
Web Programmer
Adirondack Area Network, LLC
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,422
Reputation: stymiee is on a distinguished road 
Solved Threads: 35
Moderator
stymiee's Avatar
stymiee stymiee is offline Offline
He's No Good To Me Dead

Re: retrieving a single cell of data from a MySQL database

 
0
  #4
Jun 26th, 2007
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!
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 42
Reputation: sickly_man is an unknown quantity at this point 
Solved Threads: 0
sickly_man's Avatar
sickly_man sickly_man is offline Offline
Light Poster

Re: retrieving a single cell of data from a MySQL database

 
0
  #5
Jun 26th, 2007
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
Henry Phillips
Web Programmer
Adirondack Area Network, LLC
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 494
Reputation: Puckdropper is an unknown quantity at this point 
Solved Threads: 21
Puckdropper Puckdropper is offline Offline
Posting Pro in Training

Re: retrieving a single cell of data from a MySQL database

 
0
  #6
Jun 27th, 2007
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.)
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 16
Reputation: WhiteLeo is an unknown quantity at this point 
Solved Threads: 2
WhiteLeo's Avatar
WhiteLeo WhiteLeo is offline Offline
Newbie Poster

Re: retrieving a single cell of data from a MySQL database

 
0
  #7
Jun 27th, 2007
To get a specific thing out of the array, you can use
  1. $array = mysql_fetch_array($result);
  2. $whatever = $array[columnname]
where $result is the executed query, and $columnname is the name of the column you want.

Or if its just one use:
  1. $whatever = mysql_result($result,0);
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...)
Last edited by WhiteLeo; Jun 27th, 2007 at 8:35 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 42
Reputation: sickly_man is an unknown quantity at this point 
Solved Threads: 0
sickly_man's Avatar
sickly_man sickly_man is offline Offline
Light Poster

Re: retrieving a single cell of data from a MySQL database

 
0
  #8
Jun 28th, 2007
thanks WhiteLeo.
Henry Phillips
Web Programmer
Adirondack Area Network, LLC
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC