{"id":637,"date":"2012-08-29T12:24:27","date_gmt":"2012-08-29T12:24:27","guid":{"rendered":"http:\/\/codeatelier.wordpress.com\/?p=263"},"modified":"2012-08-29T12:24:27","modified_gmt":"2012-08-29T12:24:27","slug":"getting-records-from-multiple-result-sets-in-php","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/getting-records-from-multiple-result-sets-in-php\/","title":{"rendered":"Getting Records from Multiple Result sets in PHP"},"content":{"rendered":"<p><strong>Table Structure<\/strong><\/p>\n<pre>\n CREATE TABLE Areas(AreaName VARCHAR(255),\n                    PinCode VARCHAR(255))\n                    \nINSERT INTO Areas(AreaName, PinCode)\n          VALUES('Teynampet',   '6000018'), \n                ('Ramapuram',   '6000089'),\n                ('TNagar',      '6000017'), \n                ('Mylapore',    '6000014'), \n                ('Gopalapuram', '6000087')\n<\/pre>\n<p><strong>Procedure which returns multiple result sets<\/strong><\/p>\n<pre>\n DROP PROCEDURE IF EXISTS mp_test1;\n CREATE PROCEDURE mp_test1()\n BEGIN\n   SELECT AreaName FROM Areas;\n   SELECT PinCode FROM Areas; \n END \n<\/pre>\n<p><strong>Procedure Call<\/strong><\/p>\n<pre>\n CALL mp_test1()\n<\/pre>\n<p><strong>PHP Code To retrieve Records from Multiple Resultsets<\/strong><\/p>\n<pre>\n   $mysqli\t= new mysqli('localhost', 'root', '', 'test','3306');\n\t\n   $query = \"CALL mp_test1()\";\n\t\n   $i = 0;\t\n\t\n   if ($mysqli-&gt;multi_query($query)) \n   {\n    do {\t\t\n\t\/* store first result set *\/\n        if ($result = $mysqli-&gt;use_result()) \n\t{\n\t  $j = 0;\n\t  \n          while ($row = $result-&gt;fetch_row()) \n\t  {\n\t     $arrResult[$i][$j] = $row[0];\n\t     $j++;\n\t  }\n\t\t\t\t\n   \t  $result-&gt;close();\n         }\n\t\t\t\n\tif($mysqli-&gt;more_results()) \n\t{\n  \t  $i = $i + 1;\n\t}\t\t\t \n     } while ($mysqli-&gt;next_result());\n   }\n\t\n   print \"<pre>\";\n   print_r($arrResult);\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Table Structure CREATE TABLE Areas(AreaName VARCHAR(255), PinCode VARCHAR(255)) INSERT INTO Areas(AreaName, PinCode) VALUES(&#8216;Teynampet&#8217;, &#8216;6000018&#8217;), (&#8216;Ramapuram&#8217;, &#8216;6000089&#8217;), (&#8216;TNagar&#8217;, &#8216;6000017&#8217;), (&#8216;Mylapore&#8217;, &#8216;6000014&#8217;), (&#8216;Gopalapuram&#8217;, &#8216;6000087&#8217;) Procedure which returns multiple result sets DROP PROCEDURE IF EXISTS mp_test1; CREATE PROCEDURE mp_test1() BEGIN SELECT AreaName FROM Areas; SELECT PinCode FROM Areas; END Procedure Call CALL mp_test1() PHP Code To retrieve Records&hellip; <a href=\"https:\/\/codethataint.com\/blog\/getting-records-from-multiple-result-sets-in-php\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[93,92],"tags":[],"class_list":["post-637","post","type-post","status-publish","format-standard","hentry","category-php","category-procedures-php"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/637","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=637"}],"version-history":[{"count":0,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/637\/revisions"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=637"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}