hi im making mysql database where user can search for other users, when searching i want it to return user "id" and "name" since there could be users with the same name, so i include id. here is my .php
EDIT: since i didn't get answer i wanted, i thought i didn't make it clear enough, now i'm thinking in the other way to try it. Let's say ID will be in index 0 and NAME in index 1, and so on.. see my php edit comment.
$result = mysql_query("SELECT `id`,`name` FROM `user` WHERE `name` LIKE '$search%'");
mysql_close($con);
$numrows = mysql_num_rows($result);
if ($numrows!=0){
while ($row = mysql_fetch_assoc ($result)){
$id = $row['id'];
$name = $row['name'];
echo ("$id,$name///");
Above on is my first attempt, note: edit is an example, what i'm thinking is make id, and name separate, then in Xcode separate them again to two different arrays lets say, all ID's will be in ID array by kinda jumping over one index every time "jumping over names", and NAMES in name array again jumping over ids.
// EDIT: echo "%id///";
// EDIT: echo "%name///";
}
}else{
echo "fail";
}
and then in Xcode
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
if ([searchUsers.text length] != 0) {
NSString *FindURL = [NSString stringWithFormat:@"http://localhost/search.php?search=%@",searchUsers.text];
// to execute php code
NSData *URLData = [NSData dataWithContentsOfURL:[NSURL URLWithString:FindURL]];
// to receive the returend value
NSString *DataResult = [[NSString alloc] initWithData:URLData encoding:NSUTF8StringEncoding];
NSArray *FriendsArray = [DataResult componentsSeparatedByString:@"///"];
userlist = [[NSMutableArray alloc] initWithArray:FriendsArray];
//[self searchDidSearch];
[self.tableView reloadData];
}
}
The result is like "1,somename" "2,somename" and so on. What i want is to split object so that NAME will be in the tableviewcell title, and ID in tableviewcell subtitle, and i want to apply that for each row.
Is there an easier way, or did i do something wrong?