SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Arrays

  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2007
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrays

    Evening All,

    Wondering if someone could help me with a major headache i'm getting that I can't solve and I'd like to get solved quickly as it's holding me back in my development of my football site.

    I’m trying to create an array to post multiple values into my database table.

    PHP Code:
    $lastinsert mysql_insert_id(); //to get report_id from reports table 

    $sql = array(); 
    foreach(
    $_REQUEST['r'] as $row
       { 
            
    $sql[] = sprintf("('%s', %d)"
                
    $player_id $row['player_id'], 
                
    $team_id $_GET['team_id']);     
        } 
                         
    $query_three mysql_query("INSERT INTO `goals2` ( `player_id`,`team_id`, `report_id` ) 
    VALUES ('
    $sql', '$lastinsert')"); 

    Now I want to get the first two values from the array I created and the $lastinsert value (report_id) from the last insert in another table. However it just outputs the message ‘query is empty’ in my validation checks to see if any data enters the database.

    Anyone see what’s wrong with my above piece of code please?

    Thanks

    Chris

  2. #2
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    echo the sql statement
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  3. #3
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $sql is an array, you will have to supply some type of index...
    Use a loop...
    PHP Code:
    foreach ($sql as $data) {
        
    $query_three mysql_query("INSERT INTO `goals2` ( `player_id`,`team_id`, `report_id` ) 
            VALUES (
    $data[0]$data[1]$lastinsert);
        mysql_query( 
    $query_three );

    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.


Bookmarks

Posting Permissions

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