Clickable Link
Moderator: General Moderators
Clickable Link
I am displaying the values in a database and I want to make one of the field clickable. For example, if I have 1995 displayed, I want the users to click on it and it reurrns all the data for 1995.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
you'll need a script that can handle taking some information from the url via the $_GET superglobal that'd tell it which field to filter and requery for.. the following thread has a lot of these details:
viewtopic.php?t=25082&highlight=%2Aquery
viewtopic.php?t=25082&highlight=%2Aquery
Hi,
Thanks for the link. I am very new to this, can you tell me where to make the changes?
Thanks for the link. I am very new to this, can you tell me where to make the changes?
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
</HEAD>
<BODY>
<?php
if ($selCrsOrDept == "G" and $selGender == "S")
{
echo "Please selecet a select gender";
}
else {
$db = mysql_connect("server","test","pass")
or die("001 - Connection Failed");
mysql_select_db("tetdb", $db);
// start table
echo '<center><table border="1">';
echo '<tr>';
echo '<center><strong>Gender:</strong> ' . $selGender . '<br></center>';
echo '<center><strong>College:</strong> ' . $filterCollege . ' <br></center>';
echo '<tr>';
echo '<center><table border="1">';
echo '<tr>';
echo '</tr>';
echo '<tr>';
echo '<th>Gender</th>';
echo '<th>Major</th>';
echo '<th>Head_Count</th>';
echo '<th>Career</th>';
echo '<th>Faculty</th>';
echo '<th>College</th>';
echo '<th>Attendance</th>';
echo '<th>System Of Study</th>';
echo '<th>Term</th>';
echo '</tr>';
// query database
$result = mysql_query("select * from tbl_regist_cube_term_heads where gender = '$selGender' and college= '$filterCollege'group by major , career", $db);
// loop through records, printing new row for each
while ($myrow = mysql_fetch_array($result)) {
printf("<tr><td>%s</td>\n",$myrow['gender']);
printf("<td>%s</td>\n",$myrow['major']);
printf("<td>%s</td>\n",$myrow['head_count']);
printf("<td>%s</td>\n",$myrow['career']);
printf("<td>%s</td>\n",$myrow['faculty']);
printf("<td>%s</td>\n",$myrow['college']);
printf("<td>%s</td>\n",$myrow['attendance']);
printf("<td>%s</td>\n",$myrow['system_of_study']);
printf("<td>%s</td></tr>\n",$myrow['univ_term']);
// close table
}
echo '</table></center>';
}
?>
</Body>
</html>- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
$result = mysql_query("select * from tbl_regist_cube_term_heads where gender = '$selGender' and college= '$filterCollege'group by major , career", $db);I got this sample taken from the web to work, but how to a make the actual data clickable?
This has clickable columns...
This has clickable columns...
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
/* set the allowed order by columns */
$default_sort = 'major';
$allowed_order = array ('faculty', 'college','attendance');
/* if order is not set, or it is not in the allowed
* list, then set it to a default value. Otherwise,
* set it to what was passed in. */
if (!isset ($_GET['order']) ||
!in_array ($_GET['order'], $allowed_order)) {
$order = $default_sort;
} else {
$order = $_GET['order'];
}
/* connect to db */
mysql_connect ('host,'user,'pass');
mysql_select_db ('db');
/* construct and run our query */
$query = "SELECT * FROM tbl_regist_cube_term_heads ORDER BY $order";
$result = mysql_query ($query);
/* make sure data was retrieved */
$numrows = mysql_num_rows($result);
if ($numrows == 0) {
echo "No data to display!";
exit;
}
/* now grab the first row and start the table */
$row = mysql_fetch_assoc ($result);
echo "<TABLE border=1>\n";
echo "<TR>\n";
foreach ($row as $heading=>$column) {
/* check if the heading is in our allowed_order
* array. If it is, hyperlink it so that we can
* order by this column */
echo "<TD><b>";
if (in_array ($heading, $allowed_order)) {
echo "<a href="{$_SERVER['PHP_SELF']}?order=$heading">$heading</a>";
} else {
echo $heading;
}
echo "</b></TD>\n";
}
echo "</TR>\n";
/* reset the $result set back to the first row and
* display the data */
mysql_data_seek ($result, 0);
while ($row = mysql_fetch_assoc ($result)) {
echo "<TR>\n";
foreach ($row as $column) {
echo "<TD>$column</TD>\n";
}
echo "</TR>\n";
}
echo "</TABLE>\n";
?>
</body>
</html>Code: Select all
# do u have some errors ??
# change the following line
#echo "<a href="{$_SERVER['PHP_SELF']}?order=$heading">$heading</a>";
#into
echo "<a href="?order=$heading">$heading</a>";whats with the heading part.
cuase you could simply doing something like this.
cuase you could simply doing something like this.
Code: Select all
while ($row = mysql_fetch_assoc ($result)) {
// rest of code
echo "<a href="?order=$row['heading']">$row['heading']</a>";