简体   繁体   中英

Use of sql-statement result in other sql-statement

I'm trying to use the id I'm getting from the prior sql-statement to fetch the table information for that id, but $query3 always returns FALSE and I can't seem to figure out. I am connected to the database and I do have the permissions to access this table. The id is also correct in each case.

CODE

global $con;
$query = $con->prepare("SELECT * FROM allTeams WHERE Coach = ?");
$query->bind_param('s',$username);
$query->execute();
$query->bind_result($Id,$time,$day,$coach,$hCoach);

$date = date('d-m');
$array = array();

while($row = $query -> fetch())
{
    var_dump($Id);
    echo "<br />";
    $teamId = strval($Id);
    $query3 = $con -> query("DESCRIBE `$teamId`");
    var_dump($query3);
    echo "<br />";
}

OUTPUT

int(1022) 
bool(false) 
int(1023) 
bool(false) 
int(2033) 
bool(false) 

You are trying to run a query on the same $con object, while one is already open. You can't do that.

What you need to do is call store_result to close the first query before you can run new ones.

global $con;
$query = $con->prepare("SELECT * FROM allTeams WHERE Coach = ?");
$query->bind_param('s',$username);
$query->execute();
$query->store_result();
$query->bind_result($Id,$time,$day,$coach,$hCoach);

$date = date('d-m');
$array = array();

while($row = $query -> fetch())
{
    var_dump($Id);
    echo "<br />";
    $teamId = strval($Id);
    $query3 = $con -> query("DESCRIBE `$teamId`");
    var_dump($query3);
    echo "<br />";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM