php - xcode ios split nsarray object into two separate objects -


hi im making mysql database user can search other users, when searching want return user "id" , "name" since there users same name, include id. here .php

edit: since didn't answer wanted, thought didn't make clear enough, i'm thinking in other way try it. let's id in index 0 , name in index 1, , on.. see php edit comment.

   $result = mysql_query("select `id`,`name` `user` `name` '$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 first attempt, note: edit example, i'm thinking make id, , name separate, in xcode separate them again 2 different arrays lets say, id's in id array kinda jumping on 1 index every time "jumping on names", , names in name array again jumping on ids.

    // edit: echo "%id///";     // edit: echo "%name///";     }   }else{    echo "fail";     } 

and 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];     // execute php code     nsdata  *urldata = [nsdata datawithcontentsofurl:[nsurl urlwithstring:findurl]];      // receive 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 "1,somename" "2,somename" , on. want split object name in tableviewcell title, , id in tableviewcell subtitle, , want apply each row.

is there easier way, or did wrong?

you didn't wrong, think have 1 more step go. loop through results , split strings this:

nsstring * tempitem = [friendsarray objectatindex:i]; //where each index, possibly in loop nsarray * splitobject = [tempitem componentsseparatedbystring:@","]; 

now, splitobject's first object id , second object name. can turn loop , need. there many different ways pass data around, i'll leave 1 you.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -