php - Trying to get a while loop inside another while loop, but it is not working together -
this question has answer here:
- commands out of sync; can't run command now 11 answers
i trying make while()
loop, data database, , need make loop based on 1 of variables given last while()
loop.
there no typo's far can see, keep getting
fatal error: call member function bind_param() on boolean in ... on line 77."
this code: (image better structure: http://imgur.com/0dfhorb)
<?php $sql = 'select raised_id, user_id, project_id, amount cf_donations order raised_id desc limit 6'; $stmt = $connection->prepare($sql); $stmt->bind_result($rid, $uid, $pid, $amount); $stmt->execute(); while($stmt->fetch()){ ?> <?php $userinfoquery = 'select first_name, last_name, profile_image cf_users user_id = ?'; $stamt = $connection->prepare($userinfoquery); $stamt->bind_param('i', $uid); $stamt->bind_result($firstname, $lastname, $image); $stamt->execute(); while($stamt->fetch()){ ?> <div class="donationdiv"> <p><?= $amount ?>$</p> </div> <?php } ?> <?php } ?>
any highly appreciated!
as written here: commands out of sync; can't run command now
you can't have 2 simultaneous queries because mysqli
uses unbuffered queries default (for prepared statements; it's opposite vanilla mysql_query
). can either fetch first 1 array , loop through that, or tell mysqli
buffer queries (using $stmt->store_result()
).
(answered @rasclatt)
Comments
Post a Comment