Pause to read database record and start to see next record
Posted: Wed Feb 02, 2011 11:26 am
Hi,
I am trying to view one record of a database at a time. The following code shows all records at once. Is there any way to interrupt the 'while-loop' at the end of each record and then resume showing the next record by using a 'next record' button. This could be a php or javascript solution. I've tried using a javascript 'alert()' script just to see if it works (really bad way). It doesn't. I've also tried sleep() (equally bad) which doesn't work either. Both hang up firefox. Thanks in advance for your help.
RP
I am trying to view one record of a database at a time. The following code shows all records at once. Is there any way to interrupt the 'while-loop' at the end of each record and then resume showing the next record by using a 'next record' button. This could be a php or javascript solution. I've tried using a javascript 'alert()' script just to see if it works (really bad way). It doesn't. I've also tried sleep() (equally bad) which doesn't work either. Both hang up firefox. Thanks in advance for your help.
RP
Code: Select all
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html401/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Contacts</title>
<link rel="stylesheet " type=g"text/css" href="css/frontend.css" />
<link rel="stylesheet " type="text/css" href="css/connect.css" />
</head>
<body>
<div class="header">
<h1><img src="../images/AmericanFlag2.png" alt="Company logo" height="90px" />
Rick and Polly’s Pharmaceuticals</h1>
<h3> Name Selector </h3>
</div>
<?php
require_once "db-drugs.inc";
require_once "functions.inc";
$name=$_GET[name];
switch($name) {
case "rick":
$id="PatientId='1'";
break;
case "polly":
$id="PatientId='2'";
break;
case "all":
$id="PatientId='1' OR PatientId='2'";
break;
}
if (!($cxn = @ mysqli_connect($hostName, $username, $password, $database))) showerror($cxn);
$ddatafields=getTableFields($cxn, $table);
$query="SELECT * FROM $table WHERE $id ;";
if (!($resultId = @ mysqli_query ($cxn, $query)))
showerror($cxn);
printf("<fieldset>\n");
printf("<legend>Pharmaceuticals</legend>\n");
printf("<form action=\"\">\n");
/* [b]The following shows all records of the database at once. I would like to pause at the end of each record and then resume
with the following record by clicking a 'next record' button. I don't want to use sleep() as there is no control over various periods of looking.[/b]
*/
while($row = @ mysqli_fetch_assoc($resultId)) {
// $row = @ mysqli_fetch_assoc($resultId);
printf("<input type='hidden' name='Id' id='Id'></input><br>\n");
printf("<input type='hidden' name='PatientId' id='PatientId'></input>\n");
printf("<input type='hidden' name='DoctorId' id='DoctorId'></input>\n");
printf("<input type='hidden' name='Pharmacy' id='PharmacyId'></input>\n");
printf("<ul>");
for($i=4;$i<count($ddatafields)-1;$i++) {
printf("<li><label for=%s>%s</label>\n", $ddatafields[$i], $colhead[$i]);
printf("<input type='text' size=50 name=%s id=%s value='%s'></input></li>\n\n", $ddatafields[$i], strtolower($ddatafields[$i]), $row[$ddatafields[$i]] );
}
printf("<li><label for=%s>%s</label>\n", $ddatafields[$i], $colhead[$i]);
printf("<textarea rows='4' cols='70' name=%s id=%s>%s</textarea></li>\n\n", $ddatafields[$i], strtolower($ddatafields[$i]), $row[$ddatafields[$i]] );
/*[b]tried using sleep() and javascript alert() here but that hangs up everything![/b]*/
}
printf("</ul>\n");
printf("</form>\n");
printf("</fieldset>\n");
?>
</body>
</html>