Page 1 of 1
Link to a single result
Posted: Fri Oct 23, 2009 7:37 pm
by ardan16
Hi again all,
Some direction please, If i search a database and have all results returned in my table. So table could list 25 results is there away to then click on one result and have it open in a seperate page. Done with a link or a button??
Cheers
Re: Link to a single result
Posted: Fri Oct 23, 2009 7:52 pm
by requinix
ardan16 wrote:Done with a link or a button??
Yes. Links are easier.
Example:
Code: Select all
<a href="/path/to/page.php?id=123">Edit</a>
Use $_GET["id"] to get 123.
Re: Link to a single result
Posted: Fri Oct 23, 2009 8:52 pm
by ardan16
Hi tasairis,
No you lost me with this one, sorry still learning.
How I understood it.
view_reports.php
Code: Select all
<?php
require_once ('mysql_connect.php'); // Connect to the db.
// Number of records to show per page:
$display = 10;
// Determine how many pages there are.
if (isset($_GET['np'])) { // Already been determined.
$num_pages = $_GET['np'];
} else { // Need to determine.
// Count the number of records
$query = "SELECT COUNT(*) FROM report ORDER BY id ASC";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_NUM);
$num_records = $row[0];
// Calculate the number of pages.
if ($num_records > $display) { // More than 1 page.
$num_pages = ceil ($num_records/$display);
} else {
$num_pages = 1;
}
} // End of np IF.
// Determine where in the database to start returning results.
if (isset($_GET['s'])) {
$start = $_GET['s'];
} else {
$start = 0;
}
$query = "SELECT(id) AS id, (name) AS name, (phone) AS phone, (dept) AS dept, (loc) AS loc, (shift) AS shift, (ihr) AS ihr, (im) AS im, (iap) As iap, (idate) as idate, (rhr) AS rhr, (rm) AS rm, (rap) As rap, (rdate) as rdate, (desc2) as desc2, (type) as type, (name2) as name2, (witness) as witness FROM report ORDER BY `id` DESC
LIMIT $start, $display";
$result = @mysql_query ($query); // Run the query.
$num = mysql_num_rows($result);
?>
<?php
if ($num > 0) { // If it ran OK, display the records.
echo "<p>You are viewing $num reports at a time.</p>\n";
// Table header.
echo '<center><table border="1px" cellpadding="1" width="90%">
<tr><td align="left"><font size="1" ><b>Report ID</b></font></td><td align="left" ><font size="1" ><b>Name of <br/>Person Reporting</b></font></td><td align="left" ><font size="1" ><b>Phone No <br/>or Extension</b></font></td><td align="left" ><font size="1" ><b>Department</b></font></td><td align="left" ><font size="1" ><b>Location</b></font></td><td align="left" ><font size="1" ><b>Shift</b></font></td><td align="left" ><font size="1" ><b>Time of Incident</b></font></td><td align="left" ><font size="1" ><b>Date of Incident</b></font></td><td align="left" ><font size="1" ><b>Time of Report</b></font></td><td align="left" ><font size="1" ><b>Date of Report</b></font></td><td align="left" ><font size="1" ><b>Description of<br/>Incident or Hazard</b></font></td><td align="left" ><font size="1" ><b>Incident Involving</b></font></td><td align="left" ><font size="1" ><b>Name</b></font></td><td align="left" ><font size="1" ><b>Witness</b></font></td></tr>
';
// Fetch and print all the records.
// Fetch and print all the records.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
// Now build the table row using the face image instead of the face field value
echo '<tr><td align="center" ><font size="1" >' . $row['id'] . '</font></td><td align="left"><font size="1" >' . $row['name'] . '</font></td><td align="center"><font size="1" >' . $row['phone']. '</font></td><td align="center"><font size="1" >' . $row['dept'] .'</font></td><td align="center"><font size="1" >' . $row['loc'] .'</font></td><td align="center"><font size="1" >' . $row['shift'] .'</font></td><td align="center"><font size="1" >' . $row['ihr'] . '</font><font size="1" >:</font><font size="1" >' . $row['im'] . '</font><font size="1" >:</font><font size="1" >' . $row['iap'] . '</font></td><td align="center" ><font size="1" >' . $row['idate'] . '</font></td><td align="center"><font size="1" >' . $row['rhr'] . '</font><font size="1" >:</font><font size="1" >' . $row['rm'] . '</font><font size="1" >:</font><font size="1" >' . $row['rap'] . '</font></td><td align="center" ><font size="1" >' . $row['rdate'] . '</font></td><td align="left" ><font size="1" >' . $row['desc2'] . '</font></td><td align="center" ><font size="1" >' . $row['type'] . '</font></td><td align="center" ><font size="1" >' . $row['name2'] . '</font></td><td align="center" ><font size="1" >' . $row['witness'] . '</font></td><td align="center" ><a href="one.php?id=s">Edit</a></td></tr>';
}
echo '</table></center>';
mysql_free_result ($result); // Free up the resources.
}else { // If it did not run OK.
echo '<p class="error">There are none, or no more reports.</p>';
}
?>
Then one.php (OK not as creative with names as I am with code)
Code: Select all
<?php
require_once ('mysql_connect.php'); // Connect to the db.
// Number of records to show per page:
$query = "SELECT(id) AS id, (name) AS name, (phone) AS phone, (dept) AS dept, (loc) AS loc, (shift) AS shift, (ihr) AS ihr, (im) AS im, (iap) As iap, (idate) as idate, (rhr) AS rhr, (rm) AS rm, (rap) As rap, (rdate) as rdate, (desc2) as desc2, (type) as type, (name2) as name2, (witness) as witness FROM report WHERE id = $s";
$result = @mysql_query ($query); // Run the query.
//$num = mysql_num_rows($result);
?>
<?php
if ($num > 0) { // If it ran OK, display the records.
echo "<p>You are viewing $num reports at a time.</p>\n";
// Table header.
echo '<center><table border="1px" cellpadding="1" width="90%">
<tr><td align="left"><font size="1" ><b>Report ID</b></font></td><td align="left" ><font size="1" ><b>Name of <br/>Person Reporting</b></font></td><td align="left" ><font size="1" ><b>Phone No <br/>or Extension</b></font></td><td align="left" ><font size="1" ><b>Department</b></font></td><td align="left" ><font size="1" ><b>Location</b></font></td><td align="left" ><font size="1" ><b>Shift</b></font></td><td align="left" ><font size="1" ><b>Time of Incident</b></font></td><td align="left" ><font size="1" ><b>Date of Incident</b></font></td><td align="left" ><font size="1" ><b>Time of Report</b></font></td><td align="left" ><font size="1" ><b>Date of Report</b></font></td><td align="left" ><font size="1" ><b>Description of<br/>Incident or Hazard</b></font></td><td align="left" ><font size="1" ><b>Incident Involving</b></font></td><td align="left" ><font size="1" ><b>Name</b></font></td><td align="left" ><font size="1" ><b>Witness</b></font></td></tr>
';
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
// Now build the table row using the face image instead of the face field value
echo '<tr><td align="center" ><font size="1" >' . $row['id'] . '</font></td><td align="left"><font size="1" >' . $row['name'] . '</font></td><td align="center"><font size="1" >' . $row['phone']. '</font></td><td align="center"><font size="1" >' . $row['dept'] .'</font></td><td align="center"><font size="1" >' . $row['loc'] .'</font></td><td align="center"><font size="1" >' . $row['shift'] .'</font></td><td align="center"><font size="1" >' . $row['ihr'] . '</font><font size="1" >:</font><font size="1" >' . $row['im'] . '</font><font size="1" >:</font><font size="1" >' . $row['iap'] . '</font></td><td align="center" ><font size="1" >' . $row['idate'] . '</font></td><td align="center"><font size="1" >' . $row['rhr'] . '</font><font size="1" >:</font><font size="1" >' . $row['rm'] . '</font><font size="1" >:</font><font size="1" >' . $row['rap'] . '</font></td><td align="center" ><font size="1" >' . $row['rdate'] . '</font></td><td align="left" ><font size="1" >' . $row['desc2'] . '</font></td><td align="center" ><font size="1" >' . $row['type'] . '</font></td><td align="center" ><font size="1" >' . $row['name2'] . '</font></td><td align="center" ><font size="1" >' . $row['witness'] . '</font></td></tr>';
}
echo '</table></center>';
mysql_free_result ($result); // Free up the resources.
}else { // If it did not run OK.
echo '<p class="error">There are none, or no more reports.</p>';
}
?>
Re: Link to a single result
Posted: Sat Oct 24, 2009 3:04 am
by ardan16
Hi tasairis,
Ok I seen the errors of my ways. Did get it sorted almost now only a problem geting info to a form.
Thanks for your help