Forum Moderators: coopster
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Displaying in an HTML table</title> </head>
<body>
<table border="1">
<tr>
<th>Location</th>
<th>Job Name</th>
<th>Job Description</th>
<th>Effective Date</th>
</tr>
<?php
//Include our login information
include('db_login.php');
// Connect
$connection = mysql_connect("localhost", "user", "pass");
if (!$connection){
die("Could not connect to the database:
<br />". mysql_error());
}
// Select the database
$db_select = mysql_select_db("mydatabase"); if (!$db_select){
die ("Could not select the database:
<br />". mysql_error());
}
// Assign the query
$query = "SELECT * FROM hr";
// Execute the query
$result = mysql_query($query);
if (!$result){
die ("Could not query the database:
<br />". mysql_error());
}
// Fetch and display the results
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
$location = $row["location"];
$job_name = $row["job_name"];
$job_description = $row['job_description'];
$effective_date = $row['effective_date'];
echo "<tr>";
echo "<td>$location</td>";
echo "<td>$job_name</td>";
echo "<td>$job_description</td>";
echo "<td>$effective_date</td>";
echo "</tr>";
}
// Close the connection
mysql_close($connection);
?>
</table>
</body>
</html>
So if the user clicks on job_name, then another page will open with the matching job_description.
$job_id = $row['job_id'];
echo "<td><a href=\"job_description.php?job_id=$job_id\">$job_name</a></td>";
"SELECT job_description FROM hr WHERE job_id=".$_GET['job_id'];
I know that it's now passing the data along to job_description.php, because I'm getting a unique job_description.php?id= , but it's not printing the "job_description"
i think you may be misunderstanding me. it's not exactly passing the job_description along the URL, but the job_id(identifier) of the job that is selected which will be used to retrieve the job's description. if your table is set up to have these fields then you should find what you're looking for very easily. just query using the job_id (identifier).
job_id ¦ location ¦ job_name ¦ job_description ¦ effective_date
in job_description.php (or whatever file you want to call it) you will run a query that selects the "job description" using the job_id that is provided from the link on the previous page.
job_description.php
//header
//make database connection
//gets the job_id from $_GET
//queries job_id against db and get the job_description that is associated.
//displays the job_description/results from query