Can't get mysql_query to work inside foreach loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bronso
    New Member
    • Mar 2008
    • 1

    Can't get mysql_query to work inside foreach loop

    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($stemme r as $klasser) {
    $query = "SELECT * FROM kor WHERE stemme=' ".$klasser['ref']." ' ";
    $klasser['stemme'] = mysql_query($qu ery) or die(mysql_error ());

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

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

    Warning: mysql_fetch_arr ay(): 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?
    Last edited by ronverdonk; Mar 21 '08, 10:32 PM. Reason: code tags
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    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

    Comment

    Working...