Jump to content

Recommended Posts

Ok this is a real simple one. I dont know why I cant get it working, I can normally do loops etc to echo data in table but this isnt working...

 

  $conn = db_connect();
  $result = $conn->query("SELECT * FROM notice_board");
  $result2 = $conn->query("SELECT COUNT(*) FROM notice_board");
  $row = $result->fetchObject();
  $column = $result2->fetchColumn();

  $i = 0;
  while($i < $column)
  {
    echo '<tr>';
    echo '<td>'.$row->id.'</td><td>'.$row->type.'</td><td>'.$row->entry.'</td><td>'.$row->sl.'</td><td>'.$row->tp.'</td><td>'.$row->notes.'</td><td>'.$row->changes.'</td>';
    echo '</tr>';
    $i++;
  }

  $conn = NULL;

 

This will produce a table with 3 rows in it with all the columns, the only problem is that it is repeating the first row in the database table.

 

So the id is just listed as number 1. Not 1,2,3.

 

Here is the output.

1	buy	1.9865	1.9865	1.9865	1.9865	
1	buy	1.9865	1.9865	1.9865	1.9865	
1	buy	1.9865	1.9865	1.9865	1.9865	

 

There is only three rows in the database so it has echoed the correct number of rows, just not each row.

Link to comment
https://forums.phpfreaks.com/topic/148461-solved-echo-all-data-in-mysql-table/
Share on other sites

  $conn = db_connect();
  $result = $conn->query("SELECT * FROM notice_board");
  $result2 = $conn->query("SELECT COUNT(*) FROM notice_board");

  while($row = $result->fetchObject())
  {
    $column = $result2->fetchColumn();
    echo '<tr>';
    echo '<td>'.$row->id.'</td><td>'.$row->type.'</td><td>'.$row->entry.'</td><td>'.$row->sl.'</td><td>'.$row->tp.'</td><td>'.$row->notes.'</td><td>'.$row->changes.'</td>';
    echo '</tr>';
  }

  $conn = NULL;

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.