Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    845
    Rep Power
    0

    Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given


    Guys,

    This is my line 74:

    PHP Code:
    $rows_num mysqli_num_rows($result); 
    and this is my line 157:

    PHP Code:
    mysqli_free_result($result); 
    As you can see, there is only 1 param and it is: $result.
    So, why do I get these errors ?

    Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\test\notices.php on line 74
    Result set has 0 rows.


    Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\test\notices.php on line 157


    From past experience, I reckon I getting them because the $result is holding no value and php is counting the value as FALSE. Is this correct ?
    Now, how to fix this ? I must make sure the $result is holding value, right ? But, why is it not holding any value ?
    The mysql tbl names are correct.

    PHP Code:

    <?php 

    //Required PHP Files. 
    include 'config.php'
    include 
    'header.php'

    //Check if User is already logged-in or not. Get the login_check() FUNCTION to check. 
    if (login_check() === FALSE
    {
        
    //Redirect User to Log-in Page after 2 secs. 
        
    header("refresh:2; url=login.php"); 
        exit(); 

    else 

        
    $user $_SESSION["user"]; 
        
        
    $id $_SESSION["id"]; 
        
    $account_activation_status $_SESSION["account_activation_status"]; 
        
    $id_video_verification_status $_SESSION["id_video_verification_status"]; 
        
    $id_video_verification_url $_SESSION["id_video_verification_url"]; 
        
    $sponsor_username $_SESSION["sponsor_username"]; 
        
    $recruits_number $_SESSION["recruits_number"]; 
        
    $on_day_number_on_7_days_wish_list $_SESSION["on_day_number_on_7_days_wish_list"]; 
        
    $primary_website_domain $_SESSION["primary_website_domain"]; 
        
    $primary_website_email $_SESSION["primary_website_email"]; 
        
    $username $_SESSION["username"]; 
        
    $first_name $_SESSION["first_name"]; 
        
    $middle_name $_SESSION["middle_name"]; 
        
    $surname $_SESSION["surname"]; 
        
    $gender $_SESSION["gender"]; 
        
    $age_range $_SESSION["age_range"]; 
        
    $religion $_SESSION["religion"]; 
        
    $marital_status $_SESSION["marital_status"]; 
        
    $working_status $_SESSION["working_status"]; 
        
    $profession $_SESSION["profession"]; 
        
        
    $recipient_username $user;

        
    ?> 
        <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional/EN"> 
        <html> 
        <head> 
          <meta content="text/html; charset=ISO-8859-1"  http-equiv="content-type"> 
        <title><?php $user ?>Notices in <?php $server_time ?> time.</title>
        </head> 
        <body> 
        <br> 
        <center><span style="font-weight: bold;"><?php $user ?>Notices in <?php $server_time ?> time.</span></center> 
        <br> 
        <br> 
        
    <?php 
        
    if (!$conn)
    {
        
    $error mysqli_connect_error();
        
    $errno mysqli_connect_errno();
        print 
    "$errno$error\n";
        exit();
    }

    $query "SELECT id,date_and_time,recipient_username,sender_username,message FROM notices WHERE recipient_username = ?";

    if (
    $stmt mysqli_prepare($conn$query)) {

        
    /* bind param */
        
    mysqli_stmt_bind_param($stmt,'s',$recipient_username);
        
        
    /* execute statement */
        
    mysqli_stmt_execute($stmt);    

        
    /* bind result variables */
        
    $result mysqli_stmt_bind_result($stmt,$id,$date_and_time,$recipient_username,$sender_username,$message);
        
    $rows_num mysqli_num_rows($result);
        
    printf("Result set has %d rows.\n",$rows_num);
      
        
    ?> 
        <table width="1500" border="0" cellpadding="5" cellspacing="2" bgcolor="#666666"> 
        <?php if($rows_num) {?> 
        <tr name="headings"> 
        <td bgcolor="#FFFFFF" name="column-heading_submission-number">Submission Number</td> 
        <td bgcolor="#FFFFFF" name="column-heading_logging-server-date-&-time">Date & Time in <?php $server_time ?></td> 
        <td bgcolor="#FFFFFF" name="column-heading_username">To</td> 
        <td bgcolor="#FFFFFF" name="column-heading_gender">From</td> 
        <td bgcolor="#FFFFFF" name="column-heading_age-range">Notice</td> 
        </tr> 
        
        <?php while($row mysqli_stmt_fetch($stmt)){ ?>     
        <tr name="user-details"> 
        <td bgcolor="#FFFFFF" name="submission-number"><?php printf("%s %s\n"$id); ?></td> 
        <td bgcolor="#FFFFFF" name="logging-server-date-&-time"><?php printf("%s %s\n"$date_and_time); ?></td> 
        <td bgcolor="#FFFFFF" name="username"><?php printf("%s %s\n"$recipient_username); ?></td> 
        <td bgcolor="#FFFFFF" name="gender"><?php printf("%s %s\n"$sender_username); ?></td> 
        <td bgcolor="#FFFFFF" name="age-range"><?php printf("%s %s\n"$age_range); ?></td> 
        </tr> 
        <?php ?> 
        <tr name="pagination"> 
        <td colspan="10" bgcolor="#FFFFFF"> Result Pages: 
        <?php 
        
            
    if($rows_num <= $page_size
            { 
                echo 
    "Page 1";  
            } 
            else 
            { 
                for(
    $i=1;$i<=$page_count;$i++) 
                echo 
    "<a href=\"{$_SERVER['PHP_SELF']}?page_number={$i}\">{$i}</a>  "
            }     
            
    ?>     
        </td> 
        </tr> 
        <?php } else { ?> 
        <tr> 
        <td bgcolor="FFFFFF">No record found! Try another time.</td> 
        </tr> 
        <?php }?> 
        </table> 
        <br> 
        <br> 
        <center><span style="font-weight: bold;"><?php $user ?>Notices in <?php $server_time ?> time.</span></center> 
        <br> 
        <br> 
    </div> 
    <br> 
        <?php 
        
    if ($rows_num<1){
            echo 
    "Rows yielded: 0<br>";
            echo 
    "$user$user<br>";
            echo 
    "recipient_username: $recipient_username<br>";        
        }
        else
        {
            echo 
    "number of rows yielded: $rows_num<br>";        
        }
        if (!
    $stmt){
            echo 
    "Results yielded: 0<br>";
            echo 
    "$user<br>";
            echo 
    "recipient_username: $recipient_username<br>";    
            
        }
        else
        {
            
    //FOLLOWING ECHOES CHECK WHETHER $RESULTS GOT PULLED OR NOT
            
    echo 'Results yielded $id:'; echo "$id<br>"
            echo 
    'Results yielded $date_and_time:'; echo "$date_and_time<br>"
            echo 
    'Results yielded $recipient_username:'; echo "$recipient_username<br>"
            echo 
    'Results yielded $sender_username:'; echo "$sender_username<br>"
            echo 
    'Results yielded $message:'; echo "$message<br>";    
        }
        echo 
    "Rows Num: $rows_num";?><br>
    </body> 
    </html> 
    <?php 

    // Free result set
    mysqli_free_result($result);

    //close statement
    mysqli_stmt_close($stmt);
    }

    //close connection
    mysqli_close($conn);

    }

    ?>
    Last edited by UniqueIdeaMan; March 1st, 2018 at 03:17 AM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,468
    Rep Power
    653
    You've already encountered this problem and were told what is wrong before. $result is NOT a mysqli_result. Guess what you forgot to execute. AGAIN!
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2016
    Posts
    142
    Rep Power
    66
    1st, go read the php.net documentation for mysqli_stmt_bind_result(). You will find that the value it returns has nothing to do with the query result. It's either a boolean true or false value, depending on if the mysqli_stmt_bind_result() statement worked or failed.

    2nd, go read the php.net documentation for the msyqli stmt class. You will find that mysqli_num_rows() and mysqli_free_result() are not part of that class. You will find by reading this part of the documentation what the correct statements are and you will also find that in order to get the number of rows for a mysqli prepared query that you must use mysqli_stmt_store_result() first.

    3rd, go and learn the much simpler and more consistent php PDO extension. It eliminates all this BS with the mysqli extension.

    Comments on this post

    • UniqueIdeaMan agrees : I agree. getting tired of all this mysqli BS.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    845
    Rep Power
    0
    Originally Posted by gw1500se
    You've already encountered this problem and were told what is wrong before. $result is NOT a mysqli_result. Guess what you forgot to execute. AGAIN!
    Saying things at the top of my head here without researching any links. Are you referring I got this wrong:

    PHP Code:
    <?php while($row mysqli_stmt_fetch($stmt)){ ?>
    It should have been ... ?
    PHP Code:
    <?php while($row mysqli_stmt_fetch($result)){ ?>
    The latter did not work and so I switched it to former.
    Now, got to do what DSmabismad is saying. So, bear with me.

    Thanks both of you.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2016
    Posts
    142
    Rep Power
    66
    Are you referring I got this wrong:
    No. mysqli_stmt_fetch($stmt) is correct, which you can learn from examining the php.net documentation for that particular statement. The parameter it takes is a mysqli stmt object (yes, you are still using objects when using the mysqli procedural statements.) The value it returns is either a Boolean true or false, depending on if there was a row to be fetched or not. Assigning the return value to the variable $row is pointless for this particular usage since you are not using $row, nor is it needed for the while() statement to work.

    The problem that gw1500se is probably referring to is using mysqli_stmt_get_result(), which has it own consistency problems, and in which case you wouldn't be using mysqli_stmt_bind_result() and mysqli_stmt_fetch().

    The latter did not work and so I switched it to former.
    This is where the php.net documentation comes in handy. The documentation for any particular statement shows what if any inputs there are, what processing the statement does, and what result is returned.

    Now, got to do what DSmabismad is saying.
    If by that, you mean using the much simpler and more consistent PDO extension, the following is all the code you will need for any SELECT query that you expect to match a set of zero or more rows and use the result -

    PHP Code:
    // assuming you have a PDO connection in $pdo and are using exceptions to handle database statement errors -

    // form the sql query statement. note: PDO has a ? place-holder, so no changes are needed in the sql when using PDO
    $query "SELECT id,date_and_time,recipient_username,sender_username,message FROM notices WHERE recipient_username = ?";

    // prepare the query
    $stmt $pdo->prepare($query);

    // execute the prepared query, supplying any input values for the place-holders as an array
    $stmt->execute([$recipient_username]);

    // fetch all the data from the query into a php array variable
    $result $stmt->fetchAll(); // note: even the mysqli result fetch_all() is a f***ed up mess to use

    // at this point, $result is either an array containing all of the result set rows or it is an empty array

    // get a count of the number of rows in the result set
    $rows_num count($result);


    // to loop over the result set, use a foreach loop -
    foreach($result as $row)
    {
        
    // reference elements in $row here - i.e. $row['id'], $row['date_and_time'], ...

    }

    // if you have fetched a large amount of data, you can unset($result) here to free up memory 
    And if you are wondering why we keep telling you to use PDO because it is more consistent than the msyqli extension, one of the many things is because the result from a non-prepared query and a prepared query are accessed the same way.

    If the above query does not have any input values, the code becomes -

    PHP Code:
    // assuming you have a PDO connection in $pdo and are using exceptions to handle database statement errors -

    // form the sql query statement. note: PDO has a ? place-holder, so no changes are needed in the sql when using PDO
    $query "SELECT id,date_and_time,recipient_username,sender_username,message FROM notices";

    // prepare the query
    $stmt $pdo->query($query);

    // fetch all the data from the query into a php array variable
    $result $stmt->fetchAll(); // note: even the mysqli result fetch_all() is a f***ed up mess to use

    // at this point, $result is either an array containing all of the result set rows or it is an empty array

    // get a count of the number of rows in the result set
    $rows_num count($result);


    // to loop over the result set, use a foreach loop -
    foreach($result as $row)
    {
        
    // reference elements in $row here - i.e. $row['id'], $row['date_and_time'], ...

    }

    // if you have fetched a large amount of data, you can unset($result) here to free up memory 
    The only things that changed in the code are $pdo->prepare($query) becomes $pdo->query($query) and to remove the ->execute() call. A more advanced technique would be to extend the PDO class with a general purpose query method that accepts the sql query statement and an optional array of input values and does this using conditional logic.

    Comments on this post

    • UniqueIdeaMan agrees : Thanks for the hard work in typing all this code sample!!! :)
    Last edited by DSmabismad; March 1st, 2018 at 09:45 AM.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    845
    Rep Power
    0
    Originally Posted by DSmabismad
    No. mysqli_stmt_fetch($stmt) is correct, which you can learn from examining the php.net documentation for that particular statement. The parameter it takes is a mysqli stmt object (yes, you are still using objects when using the mysqli procedural statements.) The value it returns is either a Boolean true or false, depending on if there was a row to be fetched or not. Assigning the return value to the variable $row is pointless for this particular usage since you are not using $row, nor is it needed for the while() statement to work.

    The problem that gw1500se is probably referring to is using mysqli_stmt_get_result(), which has it own consistency problems, and in which case you wouldn't be using mysqli_stmt_bind_result() and mysqli_stmt_fetch().



    This is where the php.net documentation comes in handy. The documentation for any particular statement shows what if any inputs there are, what processing the statement does, and what result is returned.



    If by that, you mean using the much simpler and more consistent PDO extension, the following is all the code you will need for any SELECT query that you expect to match a set of zero or more rows and use the result -

    PHP Code:
    // assuming you have a PDO connection in $pdo and are using exceptions to handle database statement errors -

    // form the sql query statement. note: PDO has a ? place-holder, so no changes are needed in the sql when using PDO
    $query "SELECT id,date_and_time,recipient_username,sender_username,message FROM notices WHERE recipient_username = ?";

    // prepare the query
    $stmt $pdo->prepare($query);

    // execute the prepared query, supplying any input values for the place-holders as an array
    $stmt->execute([$recipient_username]);

    // fetch all the data from the query into a php array variable
    $result $stmt->fetchAll(); // note: even the mysqli result fetch_all() is a f***ed up mess to use

    // at this point, $result is either an array containing all of the result set rows or it is an empty array

    // get a count of the number of rows in the result set
    $rows_num count($result);


    // to loop over the result set, use a foreach loop -
    foreach($result as $row)
    {
        
    // reference elements in $row here - i.e. $row['id'], $row['date_and_time'], ...

    }

    // if you have fetched a large amount of data, you can unset($result) here to free up memory 
    And if you are wondering why we keep telling you to use PDO because it is more consistent than the msyqli extension, one of the many things is because the result from a non-prepared query and a prepared query are accessed the same way.

    If the above query does not have any input values, the code becomes -

    PHP Code:
    // assuming you have a PDO connection in $pdo and are using exceptions to handle database statement errors -

    // form the sql query statement. note: PDO has a ? place-holder, so no changes are needed in the sql when using PDO
    $query "SELECT id,date_and_time,recipient_username,sender_username,message FROM notices";

    // prepare the query
    $stmt $pdo->query($query);

    // fetch all the data from the query into a php array variable
    $result $stmt->fetchAll(); // note: even the mysqli result fetch_all() is a f***ed up mess to use

    // at this point, $result is either an array containing all of the result set rows or it is an empty array

    // get a count of the number of rows in the result set
    $rows_num count($result);


    // to loop over the result set, use a foreach loop -
    foreach($result as $row)
    {
        
    // reference elements in $row here - i.e. $row['id'], $row['date_and_time'], ...

    }

    // if you have fetched a large amount of data, you can unset($result) here to free up memory 
    The only things that changed in the code are $pdo->prepare($query) becomes $pdo->query($query) and to remove the ->execute() call. A more advanced technique would be to extend the PDO class with a general purpose query method that accepts the sql query statement and an optional array of input values and does this using conditional logic.
    Thanks man!
    I really appreciate the code sample as I can now use that as my learning purpose on pdo.
    I can see, it looks shorter compared to mysqli. I was planning on starting pdo in 2-4wks time but I might aswell start in 2 days instead.
    So, you agree pdodelusions.com, like Benanamen here and a lot of others in other forums stated, is the best point for me to start on pdo or do you have a better site for beginners on pdo ?

    Out of curiosity, I want to see how much the pdo differs compared to the mysqli when you try coding it to do what I'm intending to do on my original post. I got the mysqli version coded wrong and still drowning after all the hints here from people. Since you have now kindly given me the code how I could have coded had I used pdo, I now want to see the mysqli version. That would tell me where I went wrong by showing a sample and I could aline both code side by side and compare how much they differ. How easy the pdo is. So, if you don't mind, may we see a mysqli version ?
    The pdo always seemed harder for me compared to mysqli. But, I'm taking your word for it that it is simpler. But you know how it is, if we can see 2 comparisons side by side then it helps more in the subconscious (get rid of the itch at the back of my head/thoughts) to what the seniors say. Makes it 100+% believable and not just 100%.
    I literally copied the code from here after referencing to my db tbl but it still did not work:
    PHP: mysqli_stmt::bind_result - Manual
    Last edited by UniqueIdeaMan; March 6th, 2018 at 04:53 AM.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    845
    Rep Power
    0
    DSMabismad,

    Let me see if I understood you correct or not.
    I ditched mysqli_get_result because I know you have to have some driver installed for it to work and it has very big limitations. And so, using mysqli_stmt_fetch instead. You hinted using mysqli_stmt_get_result, I should not be using mysqli_stmt_fetch or mysqli_stmt_bind_result.
    Ok, so now sticking to using mysqli_stmt_bind_result and mysqli_stmt_fetch instead. But wait, did you say another day to use the mysqli_num_rows then to use the mysqli_stmt_store_results instead of mysqli_stmt_bind_result ? If so, I've started experimenting with these now.
    So, I'm now narrowing things down. Breaking my code up so it's easy to pin-point and solve the problem.
    My code is now looking like this to print the number of rows. We'll deal with printing the row results later on the next post. Ok ?

    PHP Code:
    <?php 

    //Required PHP Files. 
    include 'config.php'
    include 
    'header.php'

    //Check if User is already logged-in or not. Get the login_check() FUNCTION to check. 
    if (login_check() === FALSE
    {
        
    //Redirect User to Log-in Page after 2 secs. 
        
    header("refresh:2; url=login.php"); 
        exit(); 

    else 

        
    $user $_SESSION["user"]; 
        
        
    $id $_SESSION["id"]; 
        
    $account_activation_status $_SESSION["account_activation_status"]; 
        
    $id_video_verification_status $_SESSION["id_video_verification_status"]; 
        
    $id_video_verification_url $_SESSION["id_video_verification_url"]; 
        
    $sponsor_username $_SESSION["sponsor_username"]; 
        
    $recruits_number $_SESSION["recruits_number"]; 
        
    $on_day_number_on_7_days_wish_list $_SESSION["on_day_number_on_7_days_wish_list"]; 
        
    $primary_website_domain $_SESSION["primary_website_domain"]; 
        
    $primary_website_email $_SESSION["primary_website_email"]; 
        
    $username $_SESSION["username"]; 
        
    $first_name $_SESSION["first_name"]; 
        
    $middle_name $_SESSION["middle_name"]; 
        
    $surname $_SESSION["surname"]; 
        
    $gender $_SESSION["gender"]; 
        
    $age_range $_SESSION["age_range"]; 
        
    $religion $_SESSION["religion"]; 
        
    $marital_status $_SESSION["marital_status"]; 
        
    $working_status $_SESSION["working_status"]; 
        
    $profession $_SESSION["profession"]; 
        
        
    $recipient_username $user;

        
    ?> 
        <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional/EN"> 
        <html> 
        <head> 
          <meta content="text/html; charset=ISO-8859-1"  http-equiv="content-type"> 
        <title><?php $user ?>Notices in <?php $server_time ?> time.</title>
        </head> 
        <body> 
        <br> 
        <center><span style="font-weight: bold;"><?php $user ?>Notices in <?php $server_time ?> time.</span></center> 
        <br> 
        <br> 
        
    <?php 
        
    if (!$conn)
    {
        
    $error mysqli_connect_error();
        
    $errno mysqli_connect_errno();
        print 
    "$errno$error\n";
        exit();
    }

    $query "SELECT id,date_and_time,recipient_username,sender_username,message FROM notices WHERE recipient_username = ?";

    if (
    $stmt mysqli_prepare($conn$query)) {

        
    /* bind param */
        
    mysqli_stmt_bind_param($stmt,'s',$recipient_username);
        
        
    /* execute statement */
        
    mysqli_stmt_execute($stmt);    

        
            
    $result mysqli_stmt_store_result($stmt);
        
    $rows_num mysqli_stmt_num_rows($stmt);
        
    printf("Result set has %d rows.\n",$rows_num);
      
    }
    }
    ?>
    So far, the error is gone when it comes to printing the number of rows fetched. And so, this is a good starting point. I am now getting somewhere thanks to DSMabismad and gw100se.
    I get printed:
    Result set has 6 rows.

    So far so good as I see no errors. Now, let's try printing or echoing the row data on my next post.
    Last edited by UniqueIdeaMan; March 7th, 2018 at 02:58 AM.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    845
    Rep Power
    0
    Why couldn't you guys just tell me that the errors I have been facing was due to a typo or using an old function ? That would have saved me 2wks time of debugging and 2wks time of harrassing you guys and driving you all crazy ?

    Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, object given in C:\xampp\htdocs\test\notices.php on line 107

    The above vanished as soon as I replaced:
    mysqli_num_rows
    with:
    mysqli_stmt_num_rows

    ??? Damn php manual showing me outdated stuff!!!!
    PHP: mysqli_result::$num_rows - Manual
    There is says:
    mysqli_num_rows

    I now use:
    mysqli_stmt_num_rows
    and this PROBLEM SOLVED!
    Maybe, you guys forgot and overlooked like me ? Maybe, the outdated page in manual got you to overlook things too ? Nevermind. I am making some progress thanks to DSmabismad and gw1500se. And NO THANKS to the IDIOTIC MANUAL !!!
    2wks of my time WASTED!
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2016
    Posts
    142
    Rep Power
    66
    Ok, so now sticking to using mysqli_stmt_bind_result and mysqli_stmt_fetch instead. But wait, did you say another day to use the mysqli_num_rows then to use the mysqli_stmt_store_results instead of mysqli_stmt_bind_result ? If so, I've started experimenting with these now.
    No, mysqli_stmt_store_result() is used so that mysqli_stmt_num_rows() will work, this is in addition to, not instead of mysqli_stmt_bind_result(). Each of these statements do something different, that you can learn by reading the php.net documentation for each of them.

    And reading the php.net documentation will also tell you what value is returned by each statement. $result in the following line of your posted code does not have anything to do with the result set from the query -

    PHP Code:
    $result mysqli_stmt_store_result($stmt); 
    The value returned by mysqli_stmt_store_result() is either a Boolean true or false, depending on if that statement executed successfully or if it failed due to an error. Remove $result = from that line of code.
    Last edited by DSmabismad; March 6th, 2018 at 10:11 AM.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2016
    Posts
    142
    Rep Power
    66
    There's nothing wrong with the php manual. It's you jumping to conclusions and mixing statements that are not used together. And we have been telling you when you have been using the wrong statements.

    There are three mysqli classes/objects. They are mysqli, mysqli result, and mysqli stmt.

    mysqli_result_num_rows is part of the mysqli result class. mysqli_stmt_num_rows is part of the msyqli stmt class.

    The mysqli stmt class is used with prepared queries. The mysqli result class is used with non-prepared queries OR with a prepared query when mysqli_stmt_get_result() can be used, which converts a prepared query's mysqli stmt to a mysqli result.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    845
    Rep Power
    0
    Originally Posted by DSmabismad
    There's nothing wrong with the php manual. It's you jumping to conclusions and mixing statements that are not used together. And we have been telling you when you have been using the wrong statements.

    There are three mysqli classes/objects. They are mysqli, mysqli result, and mysqli stmt.

    mysqli_result_num_rows is part of the mysqli result class. mysqli_stmt_num_rows is part of the msyqli stmt class.

    The mysqli stmt class is used with prepared queries. The mysqli result class is used with non-prepared queries OR with a prepared query when mysqli_stmt_get_result() can be used, which converts a prepared query's mysqli stmt to a mysqli result.
    Everything is VERY CLEAR NOW! Yes, you did tell me to look into class and I forgot.
    I haven't forgotten about this though:
    SELECT COUNT(*) AS total rows FROM table WHERE AND php
    Gonna research more on that.

    What you told me in this post in 4 lines would have taken me 4 chapters or 4 pages (atleast) of the manual to learn and I would have got confused reading tonnes of readings.
    Therefore, you getting straight to the point has done me a great favour and done future newbies to this thread a great service.
    But, I'm afraid you will have to pay a price for your generosity. I will now hold onto you and bug you more and squeeze as much as I can from you. Don't worry, I won't go too far to suck your blood dry but I will drain you until I feel satisfied that I have learnt enough before jumping onto pdo.
    As for pdo, I'll drain the life out of Benanamen. That should punish him enough for pointing me towards pdo and harassing me in many forums to start on it. Lol!

    One question, what do they represent ?
    PHP Code:
    <td bgcolor="#FFFFFF" name="age-range"><?php printf("%s %s\n"$age_range); ?></td>
    Getting error:
    Warning: printf(): Too few arguments in C:\xampp\htdocs\test\notices.php on line 96
    Warning: printf(): Too few arguments in C:\xampp\htdocs\test\notices.php on line 97
    and so on for each columns row.

    Switching to the likes of the following got rid of all errors:
    PHP Code:
    <td bgcolor="#FFFFFF" name="age-range"><?php printf("%s"$age_range); ?></td>
    Frankly, I don't know what "%s %s\n" means. I guessing the "\n" means "new line" or escape. Don't see why escaping is necessary here so guessing it means "new line".
    Guessing the "%s" means "space". Right ?
    Anyway, seeing great improvements on my work today after understanding a few things. I'll bug you tomorrow with all the rest opf my questions so do stay tuned.
    I've decided now that you've earnt a badge here and I'll drop you a PM to checkout my php web app that I am converting to Android mobile app so smart fone users can earn money with it and get out of poverty (from unemployment, bankruptcy, etc.) Your help is speeding up my project. I got a couple of questions which need clearing tomorrow and then I reckon my project is finished thanks to you and gw1500se but mostly to YOU.
    Stay curious to know what all the fuss is about. About my web->mobile app.

    EDIT: Figured-out what they mean! They mean "placeholder":
    %s %s
    It means 2 place-holders. See, I'm progressing tonight. Yeah, I know, roll your eyes. I should have known that right from the beginning. Frankly, I did. Then, I forgot. I did say that, I learn and then forget dbl faster! Lol! Still guessing the /n part means new line. But, new line on this case seems absurd, unless you can enlighten me here again tonight for the 3rd time.
    Last edited by UniqueIdeaMan; March 6th, 2018 at 10:48 AM.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    845
    Rep Power
    0
    YEEHA!
    Ok. I've managed to echo row data on html tbl without any errors. 1-2wks of struggle has come to an end.
    Now, just need to deal with the pagination part and DSmabismad, gw1500se and Sepodati is gonna aid me here and thanks to them all this 13mnths project will come to an end! Can you believe it ? I started working on this project in early feb 2017 and now it's march 2018 and my birthday soon. I will take this web app as my bday gift to myself or better I'll take the helps from you guys as my bday gift!
    Gonna build a birthday site where same bday ppl send wishes to each other and each wish they read earns them money. Hope you guys earn a million on your bdays!

    Will pester you guys tomorrow to help me finish the pagination via PREP STMT. I got the non-PREP version working. Now, just got to convert that part of the code to PREP STMT and then this project is COMPLETE!
    I'll be a free man from this energy draining project! And can start on pdo. Gave Benanaman and a lot of guys promise I'll start on it and nearly 1yr and failed to start on it due to this life draining project. Nevertheless, it's worth it. It will financially help the broken people in society.
    Take care!
    Last edited by UniqueIdeaMan; March 12th, 2018 at 06:04 AM.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    845
    Rep Power
    0
    Here's my update so far. Seems like I fixed the pagination part by copying parts of the code from the non-prep version (who'se code I came across online about 2yrs ago).
    But, my learning on the pagination is not complete and so I will bug you guys tomorrow night or day to explain some lines of code and you guys would be kind enough to do it.
    Nevertheless, here's is the working code ...

    PHP Code:
    <?php 

    //Required PHP Files. 
    include 'config.php'
    include 
    'header.php'

    //Check if User is already logged-in or not. Get the login_check() FUNCTION to check. 
    if (login_check() === FALSE
    {
        
    //Redirect User to Log-in Page after 2 secs. 
        
    header("refresh:2; url=login.php"); 
        exit(); 

    else 

        
    $user $_SESSION["user"]; 
        
        
    $id $_SESSION["id"]; 
        
    $account_activation_status $_SESSION["account_activation_status"]; 
        
    $id_video_verification_status $_SESSION["id_video_verification_status"]; 
        
    $id_video_verification_url $_SESSION["id_video_verification_url"]; 
        
    $sponsor_username $_SESSION["sponsor_username"]; 
        
    $recruits_number $_SESSION["recruits_number"]; 
        
    $on_day_number_on_7_days_wish_list $_SESSION["on_day_number_on_7_days_wish_list"]; 
        
    $primary_website_domain $_SESSION["primary_website_domain"]; 
        
    $primary_website_email $_SESSION["primary_website_email"]; 
        
    $username $_SESSION["username"]; 
        
    $first_name $_SESSION["first_name"]; 
        
    $middle_name $_SESSION["middle_name"]; 
        
    $surname $_SESSION["surname"]; 
        
    $gender $_SESSION["gender"]; 
        
    $age_range $_SESSION["age_range"]; 
        
    $religion $_SESSION["religion"]; 
        
    $marital_status $_SESSION["marital_status"]; 
        
    $working_status $_SESSION["working_status"]; 
        
    $profession $_SESSION["profession"]; 
        
        
    $recipient_username $user;

        
    ?> 
        <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional/EN"> 
        <html> 
        <head> 
          <meta content="text/html; charset=ISO-8859-1"  http-equiv="content-type"> 
        <title><?php $user ?>Notices in <?php $server_time ?> time.</title>
        </head> 
        <body> 
        <br> 
        <center><span style="font-weight: bold;"><?php $user ?>Notices in <?php $server_time ?> time.</span></center> 
        <br> 
        <br> 
        
    <?php 
        
    if (!$conn)
    {
        
    $error mysqli_connect_error();
        
    $errno mysqli_connect_errno();
        print 
    "$errno$error\n";
        exit();
    }
        
        
        
    $query "SELECT id,date_and_time,recipient_username,sender_username,message FROM notices WHERE recipient_username = ?";

    if (
    $stmt mysqli_prepare($conn$query)) {

        
    /* bind param */
        
    mysqli_stmt_bind_param($stmt,'s',$recipient_username);
        
        
    /* execute statement */
        
    mysqli_stmt_execute($stmt);    

        
    /* bind result variables */
        
    $result_2 mysqli_stmt_bind_result($stmt,$id,$date_and_time,$recipient_username,$sender_username,$message);    
        
    $result mysqli_stmt_store_result($stmt);
        
        
    $rows_num mysqli_stmt_num_rows($stmt);
        
    printf("Result set has %d rows.\n",$rows_num);
      
    }

        
    $page_count 10
        
    $page_size ceil($rows_num $page_count); 
        
    //Get the Page Number, Default is 1 (First Page) 
        
    $page_number $_GET["page_number"]; 
        if (
    $page_number == ""$page_number 1
            
    $offset = ($page_number -1) * $page_size
            
            
    $query .= " limit {$offset},{$page_size}"
            
    //$result_2 = mysqli_query($conn,$query);
            
    $result mysqli_stmt_store_result($stmt);
        
      
        
    ?> 
        <table width="1500" border="0" cellpadding="5" cellspacing="2" bgcolor="#666666"> 
        <?php if($rows_num) {?> 
        <tr name="headings"> 
        <td bgcolor="#FFFFFF" name="column-heading_submission-number">Submission Number</td> 
        <td bgcolor="#FFFFFF" name="column-heading_logging-server-date-&-time">Date & Time in <?php $server_time ?></td> 
        <td bgcolor="#FFFFFF" name="column-heading_to">To</td> 
        <td bgcolor="#FFFFFF" name="column-heading_from">From</td> 
        <td bgcolor="#FFFFFF" name="column-heading_notice">Notice</td> 
        </tr> 
        
        <?php while($row mysqli_stmt_fetch($stmt)){ ?>     
        <tr name="user-details"> 
        <td bgcolor="#FFFFFF" name="submission-number"><?php printf("%s"$id); ?></td> 
        <td bgcolor="#FFFFFF" name="logging-server-date-&-time"><?php printf("%s"$date_and_time); ?></td> 
        <td bgcolor="#FFFFFF" name="username"><?php printf("%s"$recipient_username); ?></td> 
        <td bgcolor="#FFFFFF" name="gender"><?php printf("%s"$sender_username); ?></td> 
        <td bgcolor="#FFFFFF" name="age-range"><?php printf("%s"$message); ?></td> 
        </tr> 
        <?php ?> 
        <tr name="pagination"> 
        <td colspan="10" bgcolor="#FFFFFF"> Result Pages: 
        <?php 
        
        $rows_num 
    mysqli_stmt_num_rows($stmt);
            if(
    $rows_num <= $page_size
            { 
                echo 
    "Page 1";  
            } 
            else 
            { 
                for(
    $i=1;$i<=$page_count;$i++) 
                echo 
    "<a href=\"{$_SERVER['PHP_SELF']}?page_number={$i}\">{$i}</a>  "
            }     
            
    ?>     
        </td> 
        </tr> 
        <?php } else { ?> 
        <tr> 
        <td bgcolor="FFFFFF">No record found! Try another time.</td> 
        </tr> 
        <?php }?> 
        </table> 
        <br> 
        <br> 
        <center><span style="font-weight: bold;"><?php $user ?>Notices in <?php $server_time ?> time.</span></center> 
        <br> 
        <br> 
    </div> 
    <br> 
    <br>
    </body> 
    </html> 
    <?php 

    // Free result set
    mysqli_stmt_free_result($stmt);

    //close statement
    mysqli_stmt_close($stmt);
    }

    //close connection
    mysqli_close($conn);

    ?>
    I have commented-out some lines of code without completely ridding these lines so you can see which functions I was experimenting with tonight.
    I know the $result and $result_2 is confusing. I will deal with these 2 tomorrow. I hope tomorrow night will be my final night with this pagination experimentation with PREP STMT for 2wks.
    Don't worry. I will either have $result or $result_2 but not both, unless necessary to keep both. Frankly, will try ridding them both, if that is possible. As for now, just showing my update, even though a little buggy. Showing what is working, so far.

    EDIT: Ignore the outdated html. Will fix them at the end.
    Last edited by UniqueIdeaMan; March 7th, 2018 at 03:05 AM.
  26. #14
  27. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,956
    Rep Power
    4575
    PHP Code:
    $page_count 10;  
    $page_size ceil($rows_num $page_count);  
    //Get the Page Number, Default is 1 (First Page)  
    $page_number $_GET["page_number"];  
    if (
    $page_number == ""$page_number 1;  
    $offset = ($page_number -1) * $page_size;  
    $query .= " limit {$offset},{$page_size}"
    MOST people approach the problem, such as having 15 results, by showing 10 on the first page and 5 on the second. Your solution sure is unique.

    Comments on this post

    • UniqueIdeaMan agrees : How-about showing us how to mend the code with your sample code ? Buddy!
    -- Cigars, whiskey and wild, wild women. --
  28. #15
  29. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,956
    Rep Power
    4575
    Originally Posted by UniqueIdeaMan
    I've managed to echo row data on html tbl ... this 13mnths project will come to an end
    lol....
    -- Cigars, whiskey and wild, wild women. --
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo