How to print the value of a single cell using MySQL and PHP? -
this returns blank page:
<?php $con=mysqli_connect("xxx.x.xx.x","user","password","db"); // check connection if (mysqli_connect_errno()) { echo "failed connect mysql: " . mysqli_connect_error(); } $result = mysqli_query($con,"select column table id=1"); print $result; mysqli_close($con); ?>
and returns data:
<?php $con=mysqli_connect("xxx.x.xx.x","user","password","db"); // check connection if (mysqli_connect_errno()) { echo "failed connect mysql: " . mysqli_connect_error(); } $result = mysqli_query($con,"select * table"); while($row = mysqli_fetch_array($result)) { echo $row['column_1'] . " " . $row['column_2']; echo "<br>"; } mysqli_close($con); ?>
what wrong first block of code prevents returning data?
http://php.net/manual/en/mysqli.query.php
tells me mysqli_query
returns mysqli_query
object. not primitive value string or int.
the exact line says is:
returns false on failure. successful select, show, describe or explain queries mysqli_query() return mysqli_result object. other successful queries mysqli_query() return true.
hence first block not work because first block assumes value in column
automatically returned.
in fact, if used same select column table id=1
, still have use while loop extract values because still mysqli_result object getting back.
by while loop mean this:
while($row = mysqli_fetch_array($result)) { echo $row['column_1']; echo "<br>"; }
i hope answers question.
Comments
Post a Comment