if (isset($_REQUEST['query'])) {
$query = $_REQUEST['query'];
$sql = mysql_query ("SELECT * FROM country WHERE country LIKE '%{$query}%'");
$array = array();
while ($row = mysql_fetch_assoc($sql)) {
$array[] = $row['country'];
}
echo json_encode ($array); //Return the JSON Array
}
class Sales extends DB\SQL\Mapper {
public function __construct(DB\SQL $db) { parent::__construct($db,'sales'); } public function searchProduct($query) { return $this->db->exec( 'SELECT name FROM products WHERE name=?', $query ); }
}
<?php
class SalesController extends Controller {
function beforeroute(){ $f3 = Base::instance(); $f3->set('html_title','Sales'); }
public function searchProduct($f3) { $objSales = new Sales($this->db); $aProduct = $objSales->searchProduct($f3->get('PARAMS.query')); print_r($aProduct); /* actual output Array ( [0] => Array ( [name] => Product1 )
[1] => Array ( [name] => Product2 )
) */
/* required output */
$result = array(); $result['0'] = 'Product1'; $result['1'] = 'Product2'; print_r($result);
/* outputs Array ( [0] => Product1 [1] => Product2 ) */
}}
$aProduct = array(array("name" => 'product1'),array("name" => 'product2'));
array_walk_recursive($aProduct,function($v, $k) use (&$result){ $result[] = $v; });
print_r ($result[0]); // product1
print_r ($result[1]); // product2
$objSales = new Sales($this->db);
$aProduct = $objSales->searchProduct($f3->get('PARAMS.query'));
$finalArray = array();
for($i = 0;$i<count($aProduct);$i++){ // GET ALL OBJECT FROM ARRAY
foreach($aProduct[$i] as $key=>$value){ // GET ALL KEY FROM OBJECT
$finalArray[$i] = $aProduct[$i][$key];
}
}
echo json_encode($finalArray); //Return the JSON Array
hi anatol,
i have mention the link to my f3 ecommere site under your post under the f3 sample application thread. did you get it?
i would like to take this opportunity to thank you personally for the help you have provided me throughout.
have a wonderful new year ahead.
br
karthick
Hey karthick,
I only know of -> cast to convert an object result to an array. In this caseI would do something like:
$aProduct = array(array("name" => 'product1'),array("name" => 'product2'));
array_walk_recursive($aProduct,function($v, $k) use (&$result){ $result[] = $v; });
print_r ($result[0]); // product1
print_r ($result[1]); // product2
--But I´m using mostly the mapper not exec, other will know better.And uff, the original code looks vunerable ;)
cheers,
– anatol
-- You've received this message because you are subscribed to the Google Groups group. To post to this group, send an email to f3-fra...@googlegroups.com. To unsubscribe from this group, send an email to f3-framework...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/f3-framework?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "Fat-Free Framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/f3-framework/lIDry_jKBdw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to f3-framework...@googlegroups.com.
To post to this group, send email to f3-fra...@googlegroups.com.
Visit this group at https://groups.google.com/group/f3-framework.
To view this discussion on the web visit https://groups.google.com/d/msgid/f3-framework/dc428fbe-adc1-413c-b791-30f2afb183aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Dear Anatol,
Thanks for the wishes.
I have seen ikkez mention it somewhere. Then the sign up sounded little bit complicated for me. I will definitely try it next time.
Cheers.
--
-- You've received this message because you are subscribed to the Google Groups group. To post to this group, send an email to f3-fra...@googlegroups.com. To unsubscribe from this group, send an email to f3-framework...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/f3-framework?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "Fat-Free Framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/f3-framework/lIDry_jKBdw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to f3-framework...@googlegroups.com.
To post to this group, send email to f3-fra...@googlegroups.com.
Visit this group at https://groups.google.com/group/f3-framework.
To view this discussion on the web visit https://groups.google.com/d/msgid/f3-framework/c84156a5-b56b-4837-b4fd-8f9c23819119%40googlegroups.com.