난 내가 내 인생 해결할 수에 대한 문제로 실행했습니다 데이터베이스 & 많이 사용의 조금을 포함에 SecondLife에 대한 약간의 시스템에서 일하고 있어요. 여러 열 값을 기반으로 행 선택?
나는 두 개의 서로 다른 컬럼 값을 기준으로 전체 행을 선택하는 쿼리를 실행하기 위해 노력하고있어. $ _GET [ ''] 호출을 사용하여 필요한 세부 정보를 확인한 다음 전체 행에서 모든 데이터를 가져 와서 빈 페이지에 표시해야합니다.지금, 나는 처음에 일을 가지고 있지만, 그것은 UUID에 의해 생성 된 모든 행을 당겨 난 단지 특정을 필요로 할 때, 그들을 반향했다. 그런 다음 두 번째 식별자 (테스트 목적의 '필드'라는 열)를 사용하여 작업하도록 만들려고 노력했습니다. 그 부분을 잃어 버렸습니다.
난 그냥이 개 정확한 값이 한 행을 선택해야합니다, 그리고 그것은 단지 모두가 아닌 둘 중 하나가있는 행을 선택 그래서 엄격한해야합니다.
아이디어가 있으십니까?
스크립트 (혼란 또는 I는 참조 용으로 보관 주석 코드 상관 없어! 내가이 작업을 일단 스크립트를 청소하기 위하여려고하고있다)를 동봉
<?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);
?>
테이블을 보지 않고 말하기 힘들지만 '$ questname' 대신'$ questid'를 기반으로 했습니까? – nullrevolution
+1 @nullrevolution. U는 우리에게 당신의 테이블과 기대되는 결과를 보여줄 수있었습니다 : $ – bonCodigo
무엇이 문제입니까? db 쿼리에는 두 값 ('and'조건)이 필요합니다. –