473,385 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Can't get mysql_query to work inside foreach loop

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
1 2413
ronverdonk
4,258 Expert 4TB
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

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

Similar topics

13
by: TrintCSD | last post by:
How can I reset the collections within a foreach to be read as a change from within the foreach loop then restart the foreach after collections has been changed? foreach(string invoice in...
2
by: dSchwartz | last post by:
I need help adding a column to a dataset, but its a little bit more complicated then just that. Here's the situation: I have many xml files in one directory, each which represent a newsletter. I...
2
by: ad | last post by:
I want to delete a DataRowView in a DataView if the DataRowView not checked OK. (CheckRow is a function for checking ) I used the codes below: But when some row is delete, it fail , the error...
2
by: Alan Silver | last post by:
Hello, I have code like the following... foreach (Control ctl in Page.Controls) { if (ctl.ID.StartsWith("X_")) { // do stuff } }
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
10
by: =?Utf-8?B?YmJn?= | last post by:
Hi all, I wanted to go through each entry(?) of ArrayList and remove some particular entry. So I tried following but it throws exception at runtime: foreach (myEntry entry in myArrayList) {...
8
by: =?Utf-8?B?YmJn?= | last post by:
I am getting this error when I tried to modify one field inside foreach loop. public struct myStruct { public int a; public bool b; //... } private List<myStructMyStruct = new...
3
by: xmail123 | last post by:
Why does this code work? I am new to C# and have been studying this piece of code. It loops through an Adjacency Matrix table to populate a tree view. I have two questions about why this code...
8
by: Andrus | last post by:
Code below causes error in class definition line .....Isolator<T>' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'. 'Myapp.Isolator<T>.GetEnumerator()'...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.