jeudi 1 janvier 2015

How to use "INNER JOIN" query to match the user's Profile to his Email In iPhone

My PHP Code:



<?PHP

$email=$_GET['Email'];

include("Connection.php");

$query="Select * from Api INNER JOIN Api_User
ON Api_User.Email = Api.Email where Api_User.Email='$email'";

$result=mysql_query($query,$conn);

while ($row1 = mysql_fetch_array($result)){
$users[]=$row1;
}

$body = array();

if (!empty($users))
$body['users'] = $users;

if (!empty($body))
echo json_encode ($body);

include("dbClose.php");
?>


My Xcode Code:



#pragma Get User Information (This is the Profile for the user!):

-(void)getUserURL{

NSURL *url = [NSURL URLWithString:JSON];
NSLog(@"jsonreturn#########=%@",url);
NSError *error = nil;
NSData *jsondata = [NSData dataWithContentsOfURL:url];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsondata options:0 error:&error];
//NSArray *users = [dic objectForKey:@"users"];
//NSDictionary *firstUser = [users objectAtIndex:0];
for (NSDictionary *obj in [dic objectForKey:@"users"]) {

user_Mail.text = [NSString stringWithFormat:@"%@", [obj valueForKey: @"Email"]];
NSLog(@"Dictionary data is %@",obj);
}

}


My Xcode Log from the data:



2015-01-01 18:02:26.870 Dictionary data is (null)


My MySql Order is two Tables: Api = first table Api_User = second table


Image (Api) structure : link 1


Image (Api_User) structure :[link 2][2]


Ok so as you can see I got a few problems here first of all my php code i'm trying to match each user to his account so he can see his email he had login with in is profile ViewController in the app... Then in Xcode i'm trying to get the json_encode from the php code and turn into NSDictionray without making an array to store, when I did it with the array it worked but I could only use "objectAtIndex" as you can see in the comment (//objectAtIndex) but it only get me the users i put the number of him from the mysql for example user 1,2,3 and It dont use $GET to match users with the email so now my qustion is how can I match each user to is spesifc info he have in my database to the iphone so he can see is details in a profile viewcontroller with NSDictionray and INNER JOIN qurey?



  • I have in mysql two tables one names Api and one name Api_User the idea is to match between the email and userID to the current user that is logged in, (with $GET Email) and then to show him is profile and display is email into a uitext with NSDictionray.


*In other words I got my registreation where its just $POST Email for instance ok, then Login and now I need Profile code so users can see their info in the ios app.


*Also please have look on this quastion to for better understading me: link




Aucun commentaire:

Enregistrer un commentaire