944,118 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 8425
  • PHP RSS
Jun 25th, 2007
-1

retrieving a single cell of data from a MySQL database

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
sickly_man is offline Offline
42 posts
since Jun 2007
Jun 25th, 2007
0

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

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'
Moderator
Reputation Points: 161
Solved Threads: 38
He's No Good To Me Dead
stymiee is offline Offline
1,422 posts
since May 2006
Jun 26th, 2007
0

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

[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?
Reputation Points: 10
Solved Threads: 0
Light Poster
sickly_man is offline Offline
42 posts
since Jun 2007
Jun 26th, 2007
0

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

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.
Moderator
Reputation Points: 161
Solved Threads: 38
He's No Good To Me Dead
stymiee is offline Offline
1,422 posts
since May 2006
Jun 26th, 2007
0

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

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
Reputation Points: 10
Solved Threads: 0
Light Poster
sickly_man is offline Offline
42 posts
since Jun 2007
Jun 27th, 2007
0

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

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.)
Reputation Points: 23
Solved Threads: 23
Posting Pro in Training
Puckdropper is offline Offline
494 posts
since Jul 2004
Jun 27th, 2007
0

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

To get a specific thing out of the array, you can use
php Syntax (Toggle Plain Text)
  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:
php Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 2
Newbie Poster
WhiteLeo is offline Offline
16 posts
since Feb 2007
Jun 28th, 2007
0

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

thanks WhiteLeo.
Reputation Points: 10
Solved Threads: 0
Light Poster
sickly_man is offline Offline
42 posts
since Jun 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Parse error: parse error, unexpected T_STRING
Next Thread in PHP Forum Timeline: Can't connect to MySQL server on 'localhost' (10061)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC