www.webdeveloper.com
Results 1 to 6 of 6

Thread: foreach Statement error

Threaded View

  1. #1
    Join Date
    Apr 2009
    Posts
    107

    foreach Statement error

    I am getting an error from a foreach statement, not sure why, here is the code:
    PHP Code:
    $new_prod_id $count 100;

    function 
    arrayQuery($f_prod_id,$table

       
    $sql=mysql_query("SELECT * FROM $table WHERE prod_id='$f_prod_id'"); 
       if(
    mysql_num_rows($sql)) 
       { 
          return(
    mysql_fetch_assoc($sql)); // use fetch_assoc 
       

       return 
    false


    function 
    createSpec($f_desc,$f_step_num,$f_prod_id) {
        
    $sql=mysql_query("INSERT INTO specs (descriptor,num,prod_id) VALUES ('$f_desc','$f_step_num','$f_prod_id')") or die (mysql_error());
    }

    $spec=arrayQuery($type,"specs");    
        
        
    $i=0

        
    foreach($spec['descriptor'] as $descriptor) {
            
    createSpec($spec['descriptor'],[$i],$new_prod_id);
            
    $i++;
        } 
    "descriptor" is a column in the specs DB.

    I am trying to write 27 rows in the specs database from a template created. I get the values using "$spec=arrayQuery($type,"specs");" and then I want to loop for each array value and create a new row in the specs DB.

    This is the error I am getting:"Parse error: syntax error, unexpected T_FOREACH in"

    Any help would be greatly appreciated.
    Last edited by themonkey40; 02-11-2010 at 01:03 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles