mysql - One PHP script should have one mysql_query? -


so making android mobile game's server, db using php, mysql.

when user first run game, want compare id game db , check new user or not.

if not new user, want fetch item info got db , send unity client , apply.

so making php script this, question is,

here need 2 times of $sql , mysql_query. first compare id, second fetch item info.

$sql = "select * $table id = '$userid'";  $result = mysql_query($sql) or die('query failed: ' . mysql_error());  echo 'registration complete';  

then, can input these 2 process 1 php script? in case, how can fetch unity? echo 1 result, isn't it?

or should divide 2 php scripts?

please don't use mysql_query. use @ least mysqli (to opinion) better use pdo

to answer question: can make 2 sql statements in same php file. in fact common. code this:

$sql    = "select * user"; $result = mysql_query($sql); if (isset($result[0])) {     $sql    = "select * items user_id = ?";     $result = mysql_query($sql);     // parse result unite items in readable format     echo $result; } else {     echo 'registration succesful'; } 

this example code , won't work should push in right direction.

edit:
return multiple different kinds of data frontend (unity3d) advised bundle data. formatting output in known format, e.g., json, make easier parse data @ frontend.

consider following code:

$response = array(); // code retrieve user in $user using msqli if ($user) {     // retrieve items user using mysqli     $response['items']   = $items;     $response['user']    = $user;     $response['message'] = 'user authenticated'; } else {     // insert user db , save in $user using mysqli     $response['user']    = $user;     $response['message'] = 'user registered'; }  echo json_encode($response); 

Comments