-1

I want to display mysql database data in table format using php. my code is not working. I have data in table and connection is also made. However only the column title gets displayed, and not the database data.

<html>  
<body> 
<table style="width:300px"> 
<tr> <td>Empno</td> <td>Ename</td> <td>address</td> <td>City</td> </tr> 

<?php include("conn.php"); 
$res=mysql_query("select * from info"); 
$res=mysql_query($res); 
$i=1; 
while($row=mysql_fetch_array($res)) { ?> 
<tr> <td><?php echo ($row['empno']);?></td> 
<td><?php echo ($row['ename']);?></td> 
<td><?php echo ($row['address']);?></td> 
<td><?php echo ($row['city']);?></td> </tr> 
<?php $i++; } ?> </table> 
</body> 
</html>
Rick Calder
  • 18,310
  • 3
  • 24
  • 41
daniel
  • 3
  • 3

2 Answers2

0

Could you provide a bit more info about your problem please - maybe a snippet of your PHP code?

For example, are you using mysqli or PDO?

Your rowset from the database should be returned as an array - try a print_r($rowset) and see what you get back.

Also check that there's actually data in there - if you've used a third party application (like Toad for MySQL or MySQL Workbench for example), make sure you've committed the data (if auto-commit is turned off).

Edit: Try this instead

$sql = "SELECT * FROM info"; 
$res = mysql_query($sql);
ash
  • 1,224
  • 3
  • 26
  • 46
  • I am using mysql and not mysqli – daniel Aug 08 '14 at 13:12
  • data is available in db and i am not using any third party application. where should i insert print_r($rowset)? – daniel Aug 08 '14 at 13:15
  • You're preparing your query twice. This is probably what you wanted to do. $sql = "SELECT * FROM info"; $res = mysql_query($sql); – ash Aug 08 '14 at 13:17
0

From your code you are executing two time query :

$res=mysql_query("select * from info"); 
$res=mysql_query($res); // <------ Remove this code

Also what is your file name extension ? It should be .php as you have tag html in your question. If it is in .html change it to .php

On side note don't use mysql_* function since it deprecated see more here

Community
  • 1
  • 1
Rakesh Shetty
  • 4,548
  • 7
  • 40
  • 79