Page 1 of 1

refresh

Posted: Sun Apr 18, 2004 8:40 pm
by Ducca
I,ve written some code that includes a form to input data,that is stored in a table in a database ,
i then display it on another page when i click the submit button

this all works fine

I then have a link in a nav bar that should display the contents of the database in a table , but it only shows the first data entry,

how can i make the page refresh,
i,ve tried the various bits of code i,ve read from some of the posts on here but struggling
can anyone help
thanx in advance
ducca

Code: Select all

<HTML>
<HEAD>
<LINK REL=stylesheet TYPE="text/css" HREF="wmd.css">
<HTML>
<TITLE>reading  Data from a Database</TITLE>
</HEAD>
<BODY><center>

<?php


// Set the variables for the database access:

$host="localhost";
$user="Paul";
$password="";
$database = "auction";
$TableName = "auctiondata";



$connection = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");

$db = mysql_select_db($database,$connection)
or die ("Couldn't select database");




 $query = "SELECT * FROM auctionData";
  $result = mysql_query($query)
       or die ("Couldn't execute query.");

  /* Display results in a table */

print ("<TABLE BORDER=1 WIDTH="95%" CELLSPACING=2 CELLPADDING=2 ALIGN=CENTER>\n");
print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
print ("<th ALIGN=CENTER VALIGN=TOP>AuctionId</th>\n");
print ("<th ALIGN=CENTER VALIGN=TOP>Name</th>\n");
print ("<th ALIGN=CENTER VALIGN=TOP>Item</th>\n");
print ("<th ALIGN=CENTER VALIGN=TOP> Item Description</th>\n");
print ("<th ALIGN=CENTER VALIGN=TOP>Startprice</th>\n");
print ("<th ALIGN=CENTER VALIGN=TOP>Startdate</th>\n");
print ("<th ALIGN=CENTER VALIGN=TOP>Expiresdate</th>\n");
print ("</TR>\n");

 while ($row = mysql_fetch_array($result))  
 &#123;
     extract($row);

print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>$auctionId</TD>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>$userId</TD>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>$item</TD>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>$itemDesc</TD>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>$startPrice</TD>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>$startDate</TD>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>$expiresDate</TD>\n");
print ("<TR>\n");
 &#125;
  echo "</table>\n";
mysql_close ($connection);
?>
</center>
</body>
</html>
<!--$datastring=-->

Posted: Sun Apr 18, 2004 8:46 pm
by John Cartwright

Code: Select all

<?php
<HTML> 
<HEAD> 
<LINK REL=stylesheet TYPE="text/css" HREF="wmd.css"> 
<HTML> 
<TITLE>reading  Data from a Database</TITLE> 
</HEAD> 
<BODY><center> 

<?php 


// Set the variables for the database access: 

$host="localhost"; 
$user="Paul"; 
$password=""; 
$database = "auction"; 
$TableName = "auctiondata"; 



$connection = mysql_connect($host,$user,$password) 
or die ("couldn't connect to server"); 

$db = mysql_select_db($database,$connection) 
or die ("Couldn't select database"); 




$query = "SELECT * FROM auctionData"; 
  $result = mysql_query($query) 
       or die ("Couldn't execute query."); 

  /* Display results in a table */ 

print ("<TABLE BORDER=1 WIDTH="95%" CELLSPACING=2 CELLPADDING=2 ALIGN=CENTER>\n"); 
print ("<TR ALIGN=CENTER VALIGN=TOP>\n"); 
print ("<TD ALIGN=CENTER VALIGN=TOP>AuctionId</th>\n"); 
print ("<TD ALIGN=CENTER VALIGN=TOP>Name</th>\n"); 
print ("<TD ALIGN=CENTER VALIGN=TOP>Item</th>\n"); 
print ("<TD ALIGN=CENTER VALIGN=TOP> Item Description</th>\n"); 
print ("<TD ALIGN=CENTER VALIGN=TOP>Startprice</th>\n"); 
print ("<TD ALIGN=CENTER VALIGN=TOP>Startdate</th>\n"); 
print ("<TD ALIGN=CENTER VALIGN=TOP>Expiresdate</th>\n"); 
print ("</TR>\n"); 

while ($row = mysql_fetch_array($result))  
{ 
     $auctionId     = $row['auctionId'];
     $userId         = $row['userId'];
     $item            = $row['item'];
     $itemDesc     = $row['itemDesc'];
     $startPrice     = $row['startPrice'];
     $startDate     = $row['startDate'];
     $expiresDate = $row['expiresDate'];

print ("<TR ALIGN=CENTER VALIGN=TOP>\n"); 
print ("<TD ALIGN=CENTER VALIGN=TOP>$auctionId</TD>\n"); 
print ("<TD ALIGN=CENTER VALIGN=TOP>$userId</TD>\n"); 
print ("<TD ALIGN=CENTER VALIGN=TOP>$item</TD>\n"); 
print ("<TD ALIGN=CENTER VALIGN=TOP>$itemDesc</TD>\n"); 
print ("<TD ALIGN=CENTER VALIGN=TOP>$startPrice</TD>\n"); 
print ("<TD ALIGN=CENTER VALIGN=TOP>$startDate</TD>\n"); 
print ("<TD ALIGN=CENTER VALIGN=TOP>$expiresDate</TD>\n"); 
print ("</TR>\n"); 
} 
  echo "</table>\n"; 
mysql_close ($connection); 
?> 
</center> 
</body> 
</html> 
<!--$datastring=-->
?>
I'm not sure if the use of extract to get the array is appropriate in this situation. Try assigning each row a variable name as I have done.

BTW watch your table code, you were writting th and not closing one of your tr's... explorer will allow this both other browsers wont