just need a starting point. help..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

just need a starting point. help..

Post by crazytopu »

hi, the following code displays data that it retrieves from the DB table. Can anybody help me a bit telling how can I show this data in a html table? I wanna use a html table coz i can easily integrate a html table with other tags and images. but if i leave everything with php code to display the retrieved data i dont get the flexibility.


To make it even clearer, the following piece of code display data in a very simple table where I am unable to put any link besides the table whereby users can navigate to the other pages. This simple table simply restricts my navigation. Obviously i can use the back <- button of the browser, but i want to give my page a consistent look. So, just like other pages i wanna put some links[i.e: home, insert data, delete data..etc] on the page where the retrived data will be displayed.

Code:

Code: Select all

<?php
<html>
<head><title>Show Book List in Library Stock</title></head>
<body>

<h3>List Of Available Books</h1>
<?php


$db = mysql_connect("localhost", "root");

mysql_select_db("library",$db);


$result = mysql_query("SELECT * FROM book",$db);



echo "<table border=2>\n";



echo "<tr><td>call_no</td><td>title</td><td>author1</td><td>author2</td><td>publisher</td><td>isbn</td><td>price</td><td>no_of_page</td><td>edition</td><td>category</td></tr>\n";



while ($myrow = mysql_fetch_row($result)) {



		printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n",
		$myrow[0], $myrow[1], $myrow[2],$myrow[3],$myrow[4],$myrow[5], $myrow[6],$myrow[7],$myrow[8],$myrow[9]);


}

echo "</table>\n";


?>

</body>



</html>


?>
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

i'm not sure if you are wanting just to be able to display a table of information, or a navigation system.

so, i'm going with the table concept..

if you are wanting to be able to create the table without php, why not just exit php , create the table,a nd then re-enter into php when you need?

ie :

Code: Select all

<html> 
<head><title>Show Book List in Library Stock</title></head> 
<body> 

<h3>List Of Available Books</h1> 
<?php 

$db = mysql_connect("localhost", "root"); 
mysql_select_db("library",$db) or die(mysql_error());
$result = mysql_query("SELECT * FROM book",$db); 

?>

<table border=2> 
  <tr>
    <td>call_no</td>
    <td>title</td>
    <td>author1</td>
    <td>author2</td>
    <td>publisher</td>
    <td>isbn</td>
    <td>price</td>
    <td>no_of_page</td>
    <td>edition</td>
    <td>category</td>
  </tr>
<?php
while ($myrow = mysql_fetch_row($result)) 
{
   echo '<tr>';
   for($i=0; $i<10; $i++)
   {
      echo '<td>'.$myrow[$i].'</td>';
   }
   echo '</tr>';
} 
?>

</table>
</body> 
</html>
Post Reply