php - MySql : Can I use query results in nested queries as a variable? -
i'm trying save server resources , reduce number of queries
what need use variable holding query result in query nested query
$names = ("select * table username 'm%'");
this return names starting m
in table
later want use $names
nested query
$myname = ("select * $names username='mohammad'");
i saw answer suggests create temp table first query result in memory not need, because i'll keep $names
long time , can't keep table in memory time, drawn server resources.
i tried syntax above , many ways similar didn't work
i don't want in 1 query because execute nested query every time need use $names
$myname = ("select * ("select * table username 'm%'") username='mohammad'");
because need first result separate variable use in other places of script.
edit
i need first query because i'll many queries based on like
$name = ("select * $names username='many'"); $name = ("select * $names username='mando'");
and on
you can retrieve list of names this:
$names = $database->query("select * table username 'm%'");
then loop through names retrieved , handle each 1 @ time:
$count = $names->rowcount(); for($i = 0; $i < $count; $i++) { if($names[$i]['username'] == "mohammed") { // } }
Comments
Post a Comment