-4

Is there any function in PHP that just prints result of mysqli_fetch_array() as it is on the browser? I want to use it just for checking results of various test queries. I want to print r in the code below

if($db){
    echo "connected";
}

$sql = "select student.Name, student.Branch, student.RollNo FROM student INNER JOIN students_placed ON student.StudentUserId = students_placed.StudentUserId";

$result = mysqli_query($con,$sql);
$r = mysqli_fetch_array($result);
?>
manitg907
  • 15
  • 7

2 Answers2

1

You can use either print_r($r) or var_dump($r). They produce slightly different details about the variables you are displaying.

If you are displaying your code in a web browser, you can also display either one of the above commands a bit more nicely by wrapping it in <pre> tags as follows:

echo "<pre>";
print_r($r);
echo "</pre>";
kojow7
  • 10,308
  • 17
  • 80
  • 135
  • I wanted a function such that it displays the resulting table values along with the field names in a tabular format. But I guess there's no such function defined in the library. I'll have to define such a function for me. Thanks – manitg907 Jun 05 '15 at 05:52
  • You did not specify that in your question. – kojow7 Jun 05 '15 at 05:53
  • Yep it was my fault...sry for inconvenience. – manitg907 Jun 05 '15 at 05:55
  • It sounds like you may not want any further help, but I've updated my answer in case this helps someone else. – kojow7 Jun 05 '15 at 06:01
0

You can use print_r

http://php.net/manual/en/function.print-r.php

or

var_dump

http://php.net/manual/en/function.var-dump.php

For a clear understanding of difference between var_dum and print_r, refer this - php var_dump() vs print_r()

Community
  • 1
  • 1
Manashvi Birla
  • 2,837
  • 3
  • 14
  • 28