0

I'm working on a little system for SecondLife which involves a bit of heavy use of databases & I've run into a problem I can't for the life of me solve.

I'm trying to run a query that selects an entire row based on two different column values. I'm using the $_GET[''] call to identify which details I need, and then I need to pull all the data from the entire row and echo it onto a blank page.

Now, I got it to work at first, but it was pulling ALL the rows created by a UUID and echoing them, when I only needed a specific. Then I tried to get it to work with a second identifier (which is a column called 'field' for the purpose of testing), and that's pretty much where I lost it.

I just need to select one row that has two exact values, and I need it to be draconian so it only selects a row that has both and not just one of the two.

Any ideas?

Script enclosed (don't mind the mess or the commented out code which I kept for reference; I am going to clean the script once I get it working!)

     <?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);

?>
4

1 回答 1

2

在获取行数和打印字段之间,您似乎缺少一步。您需要将查询结果实际存储在 $row 数组中。

$rows_returned = mysql_num_rows($result);
$row = mysql_fetch_array($result);
echo $row['field'];
于 2012-12-05T18:39:40.203 回答