开发者

find value of row out of 3 columns in php and mysql

开发者 https://www.devze.com 2023-01-20 17:28 出处:网络
How can i find 3 in row id#1 with 4 columns in php id,Content_type1, Content_ty开发者_运维百科pe2, Content_type3

How can i find 3 in row id#1 with 4 columns in php

 id,   Content_type1, Content_ty开发者_运维百科pe2, Content_type3

 1         6               3             9


You should restate your question with some context included. Not sure if you're looking for values in that column, or only if the value is 3?

 $sql = "SELECT Content_type2 FROM [yourTableHere] WHERE Content_type2 = 3
 mysql_query($sql);

That query will get that exact value. If you want to get that value for all records, remove the WHERE clause.


I'll have to say:

$sql = 'SELECT Content_type2 FROM some_table';
$rs = mysql_query($sql);
$row = mysql_fetch_assoc($rs);
echo $row['Content_type2'];

This will fetch the value from Content_type2 assuming there's exactly one row in that table. If there's more than one row or if there's some other logic you want to apply in order to determine what value to use, please clarify.


If you're looking to just return a row that has a value your looking for, then you can use something like the following for your SQL satement:

SELECT * FROM [TABLE] WHERE Content_type1 = [SEARCH] OR Content_type2 = [SEARCH] OR Content_type3 = [SEARCH]

Where [TABLE] is your table name and [SEARCH] is the value you're looking for. If you want to know which specific column had the value, you'll have to sift through the returned rows to figure that out.

0

精彩评论

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