By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,831 Members | 1,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,831 IT Pros & Developers. It's quick & easy.

Can't get mysql_query to work inside foreach loop

P: 1
I can`t get this block of code to work. I think there is something wrong with my syntax, but I can`t figure out what it is.

source code look like this:
[php]$stemmer=array(
array('stemme'=>'$ftenor', 'ref'=>'1.tenor', 'patch'=>'$ft'),
array('stemme'=>'$atenor', 'ref'=>'2.tenor', 'patch'=>'$at'),
array('stemme'=>'$fbass', 'ref'=>'1.bass'), 'patch'=>'$fb',
array('stemme'=>'$abass', 'ref'=>'2.bass'), 'patch'=>'$ab'); foreach($stemmer as $klasser) {
$query = "SELECT * FROM kor WHERE stemme=' ".$klasser['ref']." ' ";
$klasser['stemme'] = mysql_query($query) or die(mysql_error());

while( $klasser['patch']= mysql_fetch_array($klasser['stemme'])) {
[/php] etc.

when i try to use my "$klasser['stemme']" later in the script, i get:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
resource

Im new to PHP and MySQL so for all i know, the error might be fundamental. Is it even possible to use MySQL inside a foreach loop?
Mar 21 '08 #1
Share this Question
Share on Google+
1 Reply


ronverdonk
Expert 2.5K+
P: 4,258
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Mar 21 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.