Wednesday, 15 September 2010

php - encoding JSON response using multiple tables -



php - encoding JSON response using multiple tables -

i have android project can type keyword in edittext field , search mysql database using php retreive proper json response.

now added 2 more spinners text fields create more specific search in database. 2 other fields located in same database in diferent tables. ( 2 other tables contain id 1 6 , strings each id. value displayed in main table these 2 others id )

so i'm sending 3 keywords ( keyword, keyword2 , keyword3 ) php . how create apropriate search test in browser ? effort below displays null result. can see tried adding keyword2 , keyword3 , union include 2 more selects .

<?php //error_reporting(e_all); error_reporting(0); require_once('db_config.php'); $conn = mysql_connect($db_server, $db_user, $db_password) or die(mysql_error()); $db= mysql_select_db($db_database, $conn); $keyword=$_get["keyword"]; $keyword2=$_get["keyword2"]; $keyword3=$_get["keyword3"]; // $sql ="select marca,imagempequena,marcatotal,actividade,datainicio empresa marca '%$keyword%' , ficha '%1' "; $sql = "(select marca,imagempequena,marcatotal,actividade,datainicio empresa marca '%$keyword%' , ficha '%1') union (select investimento investimento investimento '%$keyword2%' ) union (select sector sector sector '%$keyword3%' )"; header('content-type: application/json; charset=utf-8'); mysql_query('set character_set_connection=utf8'); mysql_query('set character_set_client=utf8'); mysql_query('set character_set_results=utf8'); $rs = mysql_query($sql,$conn); $response["empresa"] = array(); while ($row=mysql_fetch_assoc($rs)) { $i=0; foreach($row $key => $value) { if (is_string($key)) { $fields[mysql_field_name($rs,$i++)] = $value; } } $json_result[] = $fields; } // success $response["success"] = 1; $response = json_encode($json_result); echo($response); ?>

php mysql json

No comments:

Post a Comment