j.silver 0 Posted November 23, 2016 Report Share Posted November 23, 2016 Hi all, In fetching a result from a table (below code), 1 is also printed after the fetched record (fetched record below). There is no 1 in the table, nor have I accidentally included it in my script. What is it and why does it appear? <?php require 'db/connect.php'; if($result = $db->query("SELECT * FROM user")) { if ($count = $result->num_rows) { $rows = $result->fetch_assoc(); echo '<pre>', print_r($rows), '</pre>'; } } ?> Array([id] => 1[first_name] => Bill[last_name] => John[bio] => I'm a web developer[created] => 2016-11-21 12:50:12)1 Quote Link to post Share on other sites
Ingolme 1,020 Posted November 23, 2016 Report Share Posted November 23, 2016 This is what happens when people don't read the documentation of a function before using it. Read this page: http://php.net/print_r print_r() prints the content of a variable and returns true. So when you echo the return value of print_r() it displays "1" which it the string representation of true. You can remove the echo statement and the code will still work except it won't add "1" to the output. Quote Link to post Share on other sites
justsomeguy 1,135 Posted November 23, 2016 Report Share Posted November 23, 2016 You can also use the second parameter of print_r to return the output instead of printing it. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.