What does this statement do?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rocky86
    New Member
    • Jun 2007
    • 93

    What does this statement do?

    hi plss help I need to noe what this php code is doing

    [PHP]
    while($row = mysql_fetch_arr ay($resultposta l))
    {
    $temp[]=$row;
    }

    foreach($temp as $key=>$extract)
    $report=$report .$key."=".$extr act."&";



    [/PHP]
  • sumaabey
    New Member
    • Jun 2007
    • 29

    #2
    i dont understand what you want but try this code then you will be able to understand
    [php]
    $query1="select productname from product1";
    $resultpostal = mysql_db_query( $dbname,$query1 ); //queryresult1
    while($row = mysql_fetch_arr ay($resultposta l))

    {

    $temp[]=$row['productname'];

    }


    foreach($temp as $key=>$extract)
    {
    echo"[". $key."]".$extract;

    //$report=$report .$key."=".$extr act;
    }
    ?>
    [/php]

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, Rocky.

      Originally posted by Rocky86
      hi plss help I need to noe what this php code is doing

      [PHP]
      while($row = mysql_fetch_arr ay($resultposta l))
      {
      $temp[]=$row;
      }

      foreach($temp as $key=>$extract)
      $report=$report .$key."=".$extr act."&";



      [/PHP]
      mysql_fetch_arr ay() (s/b mysql_fetch_ass oc()) will return an array of results from the last MySQL query, or false if there are no more results in the query.

      Each time it gets a result, we'll append it to $temp. As a result, $temp becomes an array that stores all of our MySQL results.

      Then, for each row in $temp, we will have a set of keys, which match the MySQL columns, and '$extract', which are the retuned values.

      We append each entry to $report, set up to be sent in a URL.

      Of course, the http_build_quer y() function does that last part for you....
      [code=php]
      while($row = mysql_fetch_ass oc($resultposta l))
      $report .= ($report ? '?' : '&') . http_build_quer y($row);
      [/code]

      Comment

      Working...