Situation
I want to search data from database.
My logic
If my textfield length is zero then pass 'is not null' value to server side. Otherwise pass the textfield data to server side.
Client side:
UILabel *first=[[UILabel alloc]init];
UILabel *sec=[[UILabel alloc]init];
if (_zip.text.length==0) {
first.text=@"is not null";
}
else
if (_zip.text.length>0) {
first.text=_zip.text;
}
if (_par.text.length==0) {
sec.text=@"is not null";
}
else if (_par.text.length>0){
sec.text=_par.text;
}
NSString *selquery=[NSString stringWithFormat:@"http://localhost/filtering1.php?zipcode=%@&parking=%@",first.text,sec.text];
NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:selquery]];
NSString *str=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@",str);
Server Side
<?php
$host="localhost";
$username="root";
$password="";
$db_name='BuyAndSell';
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$zipcode=$_GET['zipcode'];
$parking=$_GET['parking'];
$sql="SELECT * FROM bas WHERE zipcode='$zipcode' and parking='$parking'";
if ($result = mysql_query($sql)){
$resultArray = array();
$tempArray = array();
while($row = mysql_fetch_object($result)){
$tempArray = $row;
array_push($resultArray, $tempArray);
}
echo json_encode($resultArray);
}
else{
echo "failed query";}
?>