|
Posted by Stephen Preston on 12/06/05 11:48
Thanks very much for that guys. I'd never have worked that out easily.
This is my first foray into any form of programming and started a few months
ago with PHP and MySQL for dummies, it was a good easy start, but even with
a few library books open on PHP and MySQL I have struggled with this (array)
interaction between php and mySQL.
Did you learn by just reading books or did you go on a course or study on
the net?
Is there any easy reference ie a book that gives an explaination (giving
hypothetical situations) of problems/queries and the code in laymans terms
for the php/mysql interaction.
I find the php and mysql reference assumes I know more of the basics, so
they are quite a hard read.
Thanks once again.
"Steve" <googlespam@nastysoft.com> wrote in message
news:1133805882.074058.254380@z14g2000cwz.googlegroups.com...
>
>> 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
>
Navigation:
[Reply to this message]
|