I have a database called "App" and a table called appinfo.

I am able to connect to the database. It has only two entries since I am just trying to learn how to use php and sql together.

The first column in the appinfo table is called ID followed by 10 other columns. The ID is auto_increment.

So my question is how do i display one record's all of the columns in the database in a web page using php?

9 Years
Discussion Span
Last Post by desiguru

This is a simple way to do it :


$result = mysql_query(SELECT * FROM tablename LIMIT 1);
while($row = mysql_fetch_array($result)){ 
  $var1 = $row["yourfield1"];
  $var2 = $row["yourfield2"];
  $var10 = $row["yourfield10"];
echo "$var1 <br> $var2 .....  <br> $var10";

hope it help


I am a newbie to PHP but I am a VB programmer so it is not so strange. I had the same problem so here is my code displaying in a box on screen

$con = mysql_connect("connection","user","password");
if (!$con)
  die('Could not connect: ' . mysql_error());
  print "Connected to MySQL<br>";

mysql_select_db("yourdatabase", $con);
  $result = mysql_query("SELECT * FROM yourtable ORDER BY yourfield");
// make box and name the fields in html
 echo "<table border='1'>
// fill box with data
while($row = mysql_fetch_array($result))
  echo "<tr>";
  echo "<td>" . $row['yourfield'] . "</td>";
  echo "<td>" . $row['yourfield2'] . "</td>";
  echo "<td>" . $row['yourfield2'] . "</td>";
  echo "</tr>";
echo "</table>";

print "Please feel free to useTrevor<br>";


This code if you place your info in the sections in bold will work .. enjoy :-)


Thanks to both of you, I finally figured it out. Have a great day.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.