0

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) 
9
  • Do you really have table called 1022? Also, you're missing a back-tick: $con->query("DESCRIBE `$teamId`"); Commented Jun 26, 2013 at 18:05
  • Yes. I added the back-tick, but the output is still the same. Commented Jun 26, 2013 at 18:10
  • What exactly are you trying to do? Do you really have a table called 1022? What are you trying to DESCRIBE? Why are you using the id? What is your goal here? What should the output be? Commented Jun 26, 2013 at 18:11
  • I need to know the fields in the tables. Yes, I really have an table called 1022. The type of the id is a varchar(255). The output should the the fields of the tables. Commented Jun 26, 2013 at 18:15
  • 1
    This has made me kind of curious. Why a table with a number? Commented Jun 26, 2013 at 18:28

1 Answer 1

1

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 />";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.