how to display records in PHP from stored procedure Mysql -


i m creating stored procedure multiple select statement,as shows below:

delimiter $$  drop procedure if exists `testsp` $$ create definer=`root`@`localhost` procedure `testsp`(  ) begin select area_id,areaname area; select loc_id,locname location; end $$  delimiter ; 

this shows 2 different results..though want display different in php. php code:

$res = $mysqli->query("call testsp()");   while($row = $res->fetch_assoc())    {    $arr[] = $row['area_id'];    $arr[] = $row['areaname'];    $arr1[] = $row['loc_id'];    $arr1[] = $row['locname'];    }    echo '{"users":'.json_encode($arr).'}';    echo '{"users":'.json_encode($arr1).'}'; 

when try display $arr1,its showing null values...so how display second result sets in php.

you have 1 option use union all combine 2 queries.

like :

select 1 type, area_id id ,areaname name area union  select 2 type , loc_id id ,locname name location;  

another option use cursor, loop on sql queries using cursor.

then insert results of each loop temporary table , select * table when you're done looping.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -