Re: array

From: Date: Thu, 27 Sep 2001 07:52:52 +0000
Subject: Re: array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-68957@lists.php.net to get a copy of this message
This should be directed to the PHP list at www.php.net - but - For all of you beginners on the PHP or MySQL Lists, use this as an example. --------------------------------------------------------------------------------------------- //Connect to Database using: mysql_connect() or die() //See http://www.php.net/manual/en/function.mysql-connect.php for specifics //Select your DB using mysql_select_db() or die() //See http://www.php.net/manual/en/function.mysql-select-db.php for specifics //Do a mysql_query() or die() $dbResult = mysql_query("SELECT date, sale_amount FROM sale") or die("Query Failed"); //Get row count $nRows = mysql_num_rows($dbResult); //Scan through result adding items to array for($i=0; $i<$nRows; $i++) {
        //Fetch an object from the current row of the result
        $oRow = mysql_fetch_object($dbResult);
        //Create an array entry
        $aDataArray[$i] = array($oRow->date, $oRow->sale_amount);
} //Free the memory associated with the Database Result mysql_free_result($dbResult); ------------------------------------------------------------------------------------------- Note the clean formatted code??? It helps a lot! The mysql_connect() and mysql_select_db() should probably be placed in a function in a separate file, and required() from a directory outside of the web tree, so you do not have to monkey around with it every script, and increased security. -Jason Garber Lead Programmer - pulseaday.com At 02:18 PM 9/27/2001 +0700, Sommai Fongnamthip wrote:
Hi,
        How could I retrieve data from MySQL and put it to data array? here is example
        Table Sale
        Field1  --> Date
        Field2  --> Sale Amount
        -----------------------
        Date            Sale Amount
        1/1/2001        1000
        1/2/2001        2000
        1/3/2001        3000
        $data_array=array (
                        array('1/1/2001',1000),
                        array('1/2/2001',2000),
                        array('1/3/2001',3000)
        )
        Which command I need to use in PHP?
SF --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual)
  http://lists.mysql.com/           (the list archive)
To request this thread, e-mail <mysql-thread86477@lists.mysql.com> To unsubscribe, e-mail <mysql-unsubscribe-blair=nb.net@lists.mysql.com> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php


« previous php.general (#68957) next »