Jump to content

Unknown Printed Charector

Recommended Posts

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?



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>';
[id] => 1
[first_name] => Bill
[last_name] => John
[bio] => I'm a web developer
[created] => 2016-11-21 12:50:12
Link to post
Share on other sites

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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...