Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Irving, TX (Dallas, Fort Worth)

    Unanswered: Return MySQL rows in array


    I've been working on a OOP method that is supposed to return the rows of a MySQL query. I have to have the data array in the format:

    $rows = array('row'=>rownum, 'fld1'=>fldval, .... 'fldn'=>fldval);
    What I have encountered are the two problems of either:

    $rows = array('0'=>fldval, 'fld0'=>fldval, '1'=>fldval, 'fld1'=>fldval, .... 'n'=>fldval, 'fldn'=>fldval);
    single row of:

    $rows = array('fld0'=>fldval, 'fld1'=>fldval, .... 'fldn'=>fldval);
    Little frustrated as every PHP mysql function I have tried has some sort to goofy crap flaw and will not do a straight out process.

    I assume there is a good example somewhere, that can get me past the crap limitations, but haven't found anything useful yet!

    I've tried all of the following:

        $row = mysql_result($db_res,$n);
        $row = mysql_fetch_array($db_res);
        $row = mysql_fetch_assoc($db_res);
        $row = mysql_fetch_object($db_res);
        $row = mysql_fetch_row($db_res);
    None have worked successfully!

    For getting out the bogus "numeric" array entries. I wrote:
        foreach ($row as $k => $v) {
           if (is_numeric($k)) { continue; }        
           $result[$k] = $v;    
        }  // end foreach
        $row     $row = array_push($row, 'row'=>$rownum, $result);
    Just need $row to actually contain the entire row of data and be able to loop through it, which none of the methods I tried do.

    Hoping someone has a link!



  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    not knowing what technique you are using to retrieve the data fromMySQl, but...

    the old style
    @mysql_query returns a query resource (think object)
    that in turn returns an array holding the results of the query.
    MySQLI does things in a slightly different way (uses $mysqli->use_result()) but is effectively the same under the covers

    so I'd suggest at present if their are any crap limitations its probably down to your usage of PHP not PHP itsself
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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