Re: Weird Array Issue...

From: Date: Sat, 23 Jan 2010 08:04:36 +0000
Subject: Re: Weird Array Issue...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-301374@lists.php.net to get a copy of this message
Op 1/23/10 3:28 AM, Don Wieland schreef: > Hi, > > I have defined a stored procedure in my mySQL DB and when I call the > procedure in my mySQL browser it returns the CORRECT results: > > DROP PROCEDURE IF EXISTS Get_OHC_Years; > DELIMITER $$ > CREATE DEFINER=donw@` PROCEDURE > Get_OHC_Years`() > BEGIN > SELECT (YEAR(ohc_Date)) as ohc_year FROM Office_Hours_Cuttoff GROUP BY > YEAR(ohc_Date) ORDER BY YEAR(ohc_Date) ASC; > END > $$ > > It returns: > -- ohc_year-- > 2010 > 2009 > 2008 > 2007 I doubt it will return the values in the order you have shown. > > I was assuming this will return an array in my PHP when I call it: > > /** > *Get All Office Hours Cut-off YEARS > */ > $db->next_result(); this call to next_result() seems strange. > $years = $db->query("CALL Get_OHC_Years()") or die("Records not > found."); > $yRow = $years->fetch_array(); > echo "<pre>"; > print_r($yRow); > echo "</pre>"; > > But the result it returns on my page is: > > Array ( > [0] => 2007 > [ohc_year] => 2007 > > What am I missing? Thanks! the bit where you actually RTM or source? you seem to be assuming what the fetch_array() call does, not being able to tell exactly what kind of object $db is I'll hazard a guess that fetch_array() is a wrapper method for mysql_fetch_array() - you'd want mysql_fetch_assoc() instead, and you'll need to loop to fetch all the rows. maybe try something like: echo "<pre>"; while ($yRow = $years->fetch_assoc()) print_r($yRow); echo "</pre>";

« previous php.general (#301374) next »