Posted by Steve on 12/05/05 20:04
> I can't get an $array[key] to be used as a select query on a mySQL database.
> The basket page needs to pull these requsted rows (id) from the database.
> I have tried various combinations of MySQL queries but can't seem to get the
> data into a $query.
>
>
> $query = "SELECT * FROM z350 WHERE id=\"{$basket[id]}\"";
> $result = mysql_query($query)
> or die ("Couldn't execute query.");
The form is fine, your array $basket is fine, the problem is your use
of $basket in the SQL statement. In the context of this statement what
does {$basket[id]} mean? Not what you think it means...
Depending on your requirements you can either fetch all the rows at
once or process each row individually.
All at once:
$query = 'SELECT * FROM z350 WHERE id IN ( ' . join( ',', $basket )
.. ')';
// process...
One at a time:
foreach( $basket AS $id )
{
$query = "SELECT * FROM z350 WHERE id = $id";
// process...
}
---
Steve
[Back to original message]
|