我正在为SecondLife开发一个小系统,它需要大量使用数据库和数据库。我遇到了一个我无法解决的问题。
我正在尝试运行一个查询,根据两个不同的列值选择整行。我正在使用$ _GET ['']调用来识别我需要的细节,然后我需要从整行中提取所有数据并将其回显到空白页面。
现在,我首先让它工作,但是当我只需要一个特定的时候,它正在拉动由UUID创建的所有行并回显它们。然后我尝试使用第二个标识符(这是一个名为'field'的列用于测试),这就是我失去它的地方。
我只需要选择一行有两个确切值的行,我需要它是严格的,所以它只选择一个既包含两个又不包含其中一个的行。
有什么想法吗?
附带的脚本(不介意我留下来参考的混乱或注释掉的代码;一旦我开始工作,我将清理脚本!)
<?php
// Get key from the parameter.
$avatar_key = $_GET['key'];
// Quest params.
$questname = $_GET['questname'];
$questid = $_GET['id'];
// Connect to the database. $con holds connection info.
$con = mysql_connect("localhost","user","pass");
// Error checking.
if(!$con)
{
die('Could not connect: '.mysql_error());
}
// Select the DB we want.
mysql_select_db("yyyyy_slcom",$con);
// Build the query.
$query = "SELECT * FROM sldb_data WHERE sldb_data.uuid = '$avatar_key' AND sldb_data.field = '$questname'";
/*$query = "select * from (
select uuid, field, value, progress, ROW_NUMBER() OVER (PARTITION BY uuid ORDER BY progress DESC)
";*/
// Run the query, store the result in variable $result.
$result = mysql_query($query);
if(!result)
{
die('Error: ' . mysql_error());
}
// Check how many rows we got back with our query.
$rows_returned = mysql_num_rows($result);
echo $row['field'];
// If we get anything back,
if($rows_returned > 0)
{
//echo $row['field'] . ' was found.' . $questname;
/*if(!$row['field'])
{
echo 'You are not on this quest yet.';
}
elseif(($row['field']) && ($row['value'] == "notstarted"))
{
echo 'This quest hasn\'t started yet.';
}
elseif(($row['field']) && ($row['value'] == "started"))
{
echo 'You are on quest: "' .$row['field']. '"';
}*/
/* $fields = mysql_list_fields("tenaar_slcom","sldb_data");
$columns = mysql_num_fields($fields);
for ($i = 0; $i < $columns; $i++) {$field_array[] = mysql_field_name($fields, $i);}
if(in_array($quest, $field_array))
{
echo 'Your quest is ' . $row['field'];
}
elseif(!in_array($questname, $field_array))
{
echo 'You are not on this quest yet.';
}
elseif((in_array($questname, $field_array)) && ($row['value'] == "notstarted"))
{
echo 'You have not started quest "' .$row['field']. '" yet.';
} */
// cycle through and print what we got.
//while($row = mysql_fetch_array($result))
//{
//echo 'Quest name: ' . $row['field'] . ' | Progress: ' .$row['value'] . '<br />';
//}
}
/*else
{
echo 'You are not on this quest yet.';
}*/
// Close the connection.
mysql_close($con);
?>
答案 0 :(得分:2)
在获得行数和打印字段之间,您似乎缺少一个步骤。您需要将查询结果实际存储在$ row数组中。
$rows_returned = mysql_num_rows($result);
$row = mysql_fetch_array($result);
echo $row['field'];