3 Replies - 1799 Views - Last Post: 19 February 2017 - 10:53 AM Rate Topic: -----

#1 hashom   User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 75
  • Joined: 27-November 13

echo table with while loop

Posted 19 February 2017 - 08:55 AM

I'm trying to loop through a database and output data into table but not working any advise
<?php 
$sql = "SELECT * FROM info where ip='$ip2' LIMIT 5";
$result = $conn->query($sql); 
 while($row = $result->fetch_assoc()) {
  
?>	
  <table id="keywords" cellspacing="0" cellpadding="0">
    <thead>
      <tr>
        <th><span>URL</span></th>
        <th><span>Created Date</span></th>
        <th><span>Short </span></th>
        
      </tr>
    </thead>

<tbody>
		
     <tr> 
	  
        <td class="lalign"><?php echo $row["url"];?></td>
        <td><?php echo $row["short"];?></td>
		<td><?php echo $row["date"];?></td>
        <td>1</td>
		
    </tr>

</tbody><?php }?>
</table> 



Is This A Good Question/Topic? 0
  • +

Replies To: echo table with while loop

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 16479
  • View blog
  • Posts: 65,313
  • Joined: 12-June 08

Re: echo table with while loop

Posted 19 February 2017 - 08:59 AM

Are you sure you are even getting rows back?
Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3872
  • View blog
  • Posts: 14,211
  • Joined: 08-August 08

Re: echo table with while loop

Posted 19 February 2017 - 09:14 AM

Deprecated MySQL functions are simpler to use (not counting all the sanitizing you need to add) than PDO or MySQLi prepared statements, but far less secure. That's why they've been deprecated. If you're just learning PHP you should start with
http://www.dreaminco...duction-to-pdo/
or
http://php.net/manua...-statements.php
When dealing with old code that uses deprecated MySQL functions you should replace them if possible. If it's not possible, your experience with PDO or MySQLi will benefit you when dealing with MySQL functions.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: echo table with while loop

Posted 19 February 2017 - 10:53 AM

(Why are you attempting to repeat the whole table per row? But, even then, you are omitting the closing table tag each time, until the last table. Presumably, you should only be repeating the rows.)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1