Jump to content
#FlattenTheCurve ×
sigmahokies

try to print on page from table in database

Recommended Posts

Hi everyone,

 

I am trying to make it simply, but seem error come repeatedly, I could not figure why it went wrong. I am trying to get print (echo) to visible the print before I build other script. but resilt said "Notice: Array to strong conversion in" what did I do wrong?

 

Thanks,

Gary

 

<!doctype html><html><body><table><?php require("require2.php"); $show = "show tables from XXXX";$table = mysqli_query($GaryDB, $show);$array = array();while($array = mysqli_fetch_array($table)) {  echo $array;}?></table></body></html>

Share this post


Link to post
Share on other sites

You can't use echo for an array, try using print_r or var_dump if you do want to output the whole array.

A lot of times a good way to do this type of thing is to assign the output of print_r to a variable and then use a pre tag.

 

$output = print_r($array, true);

//Where you want to see your output
echo "<pre>$output</pre>\n";

Share this post


Link to post
Share on other sites

...assign the output of print_r to a variable and then use a pre tag.

 

You could also output it all together. I typically use the following line, which I stole from someone here at PHPFreaks:  :happy-04:

print '<pre>' . print_r($array, true) . '</pre>';

Share this post


Link to post
Share on other sites

Sure cyberRobot. I've seen people wrap that in a function as well that they include. The main point I wanted to make was that you can capture the output to a variable rather than just have it echo out wherever you are in the code. Sometimes this is helpful when you are trying to avoid messing up existing output with debug info.

Share this post


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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.