Reply to Re: arrays and mySQL querys

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация