-2

如何以这种方式选择:

$sql_result = mysql_query("SELECT 1 FROM myTable WHERE myColumn = 'something' LIMIT 0,1");
if(is_resource($sql_result) && mysql_num_rows($sql_result) > 0 ){
    // how do I select a row here?
}

就像我会这样:

$query = "SELECT * FROM myTable WHERE myColumn='something'";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
    $something = $row['SOMETHING'];
}
4

1 回答 1

1

这是过时的解决方案。不要使用 mysql_ 函数


方法1. (不要用我它已经过时了)

$sql_result = mysql_query("SELECT xxx FROM myTable WHERE myColumn = 'something' LIMIT 0,1");
$row = mysql_fetch_array($sql_result); 
echo $row['xxx'];

方法2. (不要用我它已经过时了)

$sql_result = mysql_query("SELECT xxx FROM myTable WHERE myColumn = 'something' LIMIT 0,1");
$row = mysql_fetch_row($sql_result); 
echo $row[0];

请注意SELECT 1 FROM table会给你...每行第 1 个/

于 2013-01-27T20:15:15.263 回答