From: Don Wieland on 22 Jan 2010 21:28 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 was assuming this will return an array in my PHP when I call it: /** *Get All Office Hours Cut-off YEARS */ $db->next_result(); $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! Don Wieland D W D a t a C o n c e p t s ~~~~~~~~~~~~~~~~~~~~~~~~~ donw(a)dwdataconcepts.com Direct Line - (949) 305-2771 Integrated data solutions to fit your business needs. Need assistance in dialing in your FileMaker solution? Check out our Developer Support Plan at: http://www.dwdataconcepts.com/DevSup.html Appointment 1.0v9 - Powerful Appointment Scheduling for FileMaker Pro 9 or higher http://www.appointment10.com For a quick overview - http://www.appointment10.com/Appt10_Promo/Overview.html
From: Jochem Maas on 23 Jan 2010 03:04 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>";
|
Pages: 1 Prev: Formatting Decimals Further Help Next: Subversion Ubuntu client |