Jump to content

Display Incorrect


yangkai9999

Recommended Posts

Hello,there is display problem.When I first time load the code, the display for each of field at first row are all 1, the second row are all 2.If I click refresh button, then display the correct information.Where is the problem of the code?thank you,code:<html> <head> <link rel="stylesheet" type="text/css" href="example.css"/> <script type="text/javascript" src="sortable.js"></script> <title>Browse all records from P2</title> </head> <body><?php$hostname='localhost';$user='root';$pass='Openit4me';$dbase='mytest';$connection = mysql_connect("$hostname" , "$user" , "$pass") or die ("Can't connect to MySQL");$db = mysql_select_db($dbase , $connection) or die ("Can't select database.");/// Variables//$WHERE = "WHERE county = 'Cornwall' AND accom = 'Hotel' "; /// Your sql statement$max_results = 2; /// Number of results per pageif(!isset($_GET['pg'])){ $pg = 1; } else { $pg = $_GET['pg']; } $from = (($pg * $max_results) - $max_results); /// Count total$totals = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM mytest.p2 "),0); $total_pgs = ceil($totals / $max_results);/// Page limiter & result builder$sql = "SELECT * FROM mytest.p2 LIMIT $from, $max_results";$result1 = mysql_query($sql); $num_sql = mysql_num_rows ($result1);$result_disp = mysql_query( "SELECT * FROM mytest.p2 LIMIT $from, $max_results" ) or die("SELECT Error: ".mysql_error());echo "Results: $totals <br>";echo "Viewing page $pg of $total_pgs<br>";// Build paginator if($pg > 1){ $prev = ($pg - 1); // Previous Link //$paginator ="<a href="".$_SERVER['PHP_SELF']."?pg=$prev">"Previous page</a>""; }$paginator ="<a href=\"{$_SERVER['PHP_SELF']}?pg=$prev\">Previous page</a>";}for($i = 1; $i <= $total_pgs; $i++){ /// Numbersif(($pg) == $i) { $paginator .= "<i>$i</i> "; } else { //$paginator .="<a href="".$_SERVER['PHP_SELF']."?pg=$i">$i</a> "; }}$paginator .="<a href=\"{$_SERVER['PHP_SELF']}?pg=$i\">$i</a> "; }}if($pg < $total_pgs){ $next = ($pg + 1); // Next Link //$paginator .="<a href="".$_SERVER['PHP_SELF']."?pg=$next">"Next page."</a>"; }$paginator .="<a href=\"{$_SERVER['PHP_SELF']}?pg=$next\">Next page.</a>"; }echo "$paginator<br><br>"; echo " <table class='sortable' id='sortabletable' align=center height=50 ><tr><th width=100><font face=arial size=2/><div align=center><strong>Patient ID</strong></div></font></th> <th width=100><font face=arial size=2/><div align=center><strong>Name</strong></div></font></th> <th width=100><font face=arial size=2/><div align=center><strong>Education</strong></div></font></th> <th width=248><font face=arial size=2/><div align=center><strong>Address</strong></div></font></th> <th width=100><font face=arial size=2/><div align=center><strong>Family number</strong></div></font></th> <th width=100><font face=arial size=2/><div align=center><strong>Test order</strong></div></font></th> </tr>";/// Display resultsif ($num_sql > 0 ) {$i=0;while ($i < $num_sql) { $row= mysql_fetch_array($result_disp); echo "<tr>"; echo "<td><font face=arial size=2/>". $row[ 'P_ID' ] ."</font></td>"; echo "<td><font face=arial size=2/>". $row[ 'v1' ] ."</font></td>"; echo "<td><font face=arial size=2/>". $row[ 'V2' ] ."</font></td>"; echo "<td><font face=arial size=2/>". $row[ 'V3' ] ."</font></td>"; echo "<td><font face=arial size=2/>". $row[ 'V4' ] ."</font></td>"; echo "<td><font face=arial size=2/>". $row[ 'V5' ] ."</font></td>"; echo "</tr>";++$i;} echo "</table>";}echo "<br>$paginator";?> <p> </p><p> </p><p> </p> <! go back to main page> <form action="./index.html"> <p><input type="submit" value="Back to Home Page" name="Back to Home Page" /n> </p> </form> </body></html>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...