MYSQL Query Result to Arrays
Results 1 to 6 of 6

Thread: MYSQL Query Result to Arrays

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    3

    MYSQL Query Result to Arrays

    PHP Code:
      $user $_GET["user_name"]; 
      

        

        

    $con=mysqli_connect(DB_HOSTDB_USERDB_PASSDB_NAME);
      

        

        

    if (
    mysqli_connect_errno()){ echo "Failed to connect to MySQL: " mysqli_connect_error(); }

        

        

        

        

        


      

        

        

    $result mysqli_query($con,"SELECT data1, data2, FROM datatable"); 
      

        

        

        

    while(
    $row=mysql_fetch_array($result)){
      

        

        

        

        

    echo 
    $row['data1'];
      

        

        

        

        

    echo 
    $row['data2'];
      

        

        

        

        

    echo 
    $row['data3'];
      

        

        

    Hi... How do you insert MYSQL Query Result to Arrays    

    }
     
     

     
    $row[] = "data1";
     
    $row[] = "data2";
     
    $row[] = "data2";
     
    $xls->addRow($row); 
     
     
    # or multidimentional array
     
    $row = array();
     
    $row[] = array(=>'data1'1=>'data2'2=>'data3');
     
    $xls->addRow($row); 

  2. #2
    Junior Member
    Join Date
    Sep 2013
    Posts
    3
    Opps! I was asking How to insert MYSQL Query Result to Arrays

  3. #3
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,889
    That's exactly what you're doing in this line:
    PHP Code:
    while($row=mysql_fetch_array($result)){ 
    That's why it's called "fetch_array".

    If that's not your question (and using question marks are good for marking questions), then you'll need to give more information about what you're trying to do and what you're trying to achieve.

    And I should warn you that you shouldn't be using the MySQL extension.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  4. #4
    Junior Member
    Join Date
    Sep 2013
    Posts
    3
    I'm trying to insert the result of Query to an Array so that xport-xls.class.php can render the value...

    $data = array();
    while($row=mysql_fetch_array($result)) {
    echo $row['data1'];
    echo $row['data2'];
    echo $row['data3'];
    $data[] = $row;
    }


    currently the example given is this and this is working... but said we can use data from SQL query as well so thats what i'm trying to do. Thanks!

    #add a multi dimension array
    $row = array();
    $row[] = array(0 =>'Luke', 1=>'6', 2=>'2ft');
    $xls->addRow($row);

  5. #5
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,429
    Sounds like you just need to call the addRow() method inside the while() loop (perhaps also utilizing the $resulttype parameter to avoid every column being duplicated in the array).

  6. #6
    Senior Member
    Join Date
    Mar 2009
    Posts
    812
    One thing I noticed is you're mixing MySQL and MySQLi functions. Choose only one (hint: choose MySQLi - the extra I is for improved!).
    Declare variables, not war.

Thread Information

Users Browsing this Thread

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

Posting Permissions

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