Jump to content

[SOLVED] Getting data from a Particular Column and Row in a Table


Recommended Posts

Right now I can query my table as an array (mysql_fetch_array) and output all the data into a table I create.

 

However if I just wanted to get the data from Column 2, Row 1 of a table in my database and output it not into a table but just as is, is there a way to do that?

 

Thank you much.

Yes, you can do that with mysql_result(). You can either do a blanket

 

$sql = "select * from table";
$result = mysql_query($sql);

$row = 0; // row 1 cuz it starts at 0
$col = 1; // col 2 cuz it starts at 0
$val = mysql_result($result, $row, $col);

 

But that's not really very efficient unless you're wanting to be able to grab multiple pieces of data and the "x,y coords" are variable.

 

If you're looking for retrieving just 1 cell in a table, you should write your query string to return only that cell to begin with.  Example:

 

tNames

id name

0  John

1  Mary

2  Jane

3  Mike

 

$sql = "select name from tNames where id = 1";
$result = mysql_query($sql);
$name = mysql_result($result, 0, 0);

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.