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?

This is a simple way to do it :

mysql_connect("yourhost","yourusername","yourpass");
mysql_select_db("yourdb");

$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

<?php
$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'>
<tr>
<th>yourfield</th>
<th>yourfield2</th>
<th>yourfield3</th>
</tr>";
// 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>";

  mysql_close($con);
?>

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 article has been dead for over six months. Start a new discussion instead.