Pergunta

Here is my code.. It doesn't give me an error whale binding, but it will not display anything even though there is more than one row that meets the select statements criteria

    $sql = 'SELECT reply_content FROM ticket_replies WHERE reply_id = ? ORDER BY reply_order ASC';

    $stmt2 = $mysqli->prepare($sql);

    if($stmt2 === false) {
    trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $mysqli->error, E_USER_ERROR);
    }

    $stmt2->bind_param('i', $loggedInUser->user_id);
    $stmt2->execute();
    $stmt2->store_result();
    $stmt2->bind_result($reply_content1);
    $stmt2->fetch();


    if($stmt2->num_rows > 0) {

        while ($stmt2 ->fetch()) {
        echo $reply_content1;
        }   
    }    


    $stmt2->close();
Foi útil?

Solução

You are fetching twice, try commenting out the first one

//$stmt2->fetch();
if($stmt2->num_rows > 0) {
   while ($stmt2 ->fetch()) {
    ...

The way you have it now will move the cursor one more time. But you have only one record, that's why you don't see anyting.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top