开发者

MySQL fetch column value of particular row

I need to fetch a particular column value of a particular row using php in mysql.

For example if I want to开发者_开发技巧 fetch column2 value in row2, I tried using:

$qry = mysql_query("SELECT * from $table");
$data = mysql_fetch_row($qry);
$result = $data[1];

but this always returns only the first row value.


SELECT Column2
FROM $table
ORDER BY Something
LIMIT 1,1;

Or, if you know the key of the row

SELECT Column2
FROM $table
WHERE Key = Something
-- Optional: if you want 2nd after filtering
-- ORDER BY Something
-- LIMIT 1,1;


select COLUMNNAME from TABLENAME where ROWELEMENT="SOME_VALUE";

This should be your sql query.. You will need to access the value of that element using

$result['COLUMNNAME']

Complete code should look like this.

$query="select COLUMNNAME from TABLENAME where ROWELEMENT='SOME_VALUE'";
$result=mysql_query($query);
$result=mysql_fetch_array($result);
$columnvalue=$result['COLUMNNAME'];

Its bcoz mysql_query returns the result in an associative array form. After the above code, You can access all elements like this.

$columnname[$index];

This will return the first value,

According to your question, You will need to first get the column values in a saperate array, and then access it using your index value..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜