Jump to content

sending mysql query results to another page by link


jobs1109

Recommended Posts

Hi,

 

I am trying to send mysql query to another page by link.  I would like users to be able to click

on a link from mysql query result and then be able to see more details on a second page for the row selected in the link. Here is an example of what I am trying to do.  http://www.jobberbase.com/demo/.  In my code when I go to second page it does not show the correct row of data when link is clicked. Here is my code .

 

 

first page with mysql query results.

 



<?php
session_start();
?>



// Post variables

<?php
$_SESSION['Keyword_Search']    = $_POST['Keyword_Search']; 
$_SESSION['Jobcategory']      = $_POST['Jobcategory'];
$Keyword_Search =  $_SESSION['Keyword_Search'];
$Jobcategory =  $_SESSION['Jobcategory'];
// echo $Keyword_Search; will be used in future
// echo $Jobcategory; will be used in future


include'../../DB-Connect101/DB-Connect101.php';


// getting data from table "Jobs-table"



$query = "SELECT * FROM Jobs-table"; 

$result = mysql_query("	SELECT 	 'id', `JobTitle`,	  `Company`,	  `Salary`,	  `Description`,	  `CompanyURL`,	  `PhoneNumber`,	  `Requirements`,	  `JobCategory`,	  `JobType`,	  `Apply_To`,	  `Email`,	  `State`,	  `Address`,	  `Country`,	  `Zipcode`	FROM	  `Jobs-table` ") or die(mysql_error());while ($row = mysql_fetch_array($result)) { 	echo 'Job Title: <a href="http://www.hiringinhilo.com/Hilo-Jobs/Job-Search-Form/Getting-Data-From-Database/Job-Details/Job-Details.php">'.$row['JobTitle'].'</a><br /><br />';	}

?>




 

 

 

Here is the second page when results for selected row should be displayed.

 



<?php
session_start();
?>


<?php
include'../../../DB-Connect101/DB-Connect101.php';

$Keyword_Search =  $_SESSION['Keyword_Search'];
$Jobcategory =  $_SESSION['Jobcategory'];
// echo $Keyword_Search;
// echo $Jobcategory;


?>
<br>
<br>
<br>

<?php

$id = $_SESSION['id']; 
$query = "SELECT * FROM Jobs-table where id=$id"; 

$result = mysql_query("	SELECT 	`id`,  `JobTitle`,	  `Company`,	  `Salary`,	  `Description`,	  `CompanyURL`,	  `PhoneNumber`,	  `Requirements`,	  `JobCategory`,	  `JobType`,	  `Apply_To`,	  `Email`,	  `State`,	  `Address`,	  `Country`,	  `Zipcode`	FROM	  `Jobs-table` ORDER BY id ASC")
or die(mysql_error());
$row = mysql_fetch_array($result);


echo "ID: ".$row['id'];
echo "<br>Job Title: ".$row['JobTitle'];
echo "<br> Company: ".$row['Company'];
echo " <br>Salary: ".$row['Salary'];
echo "<br> Description: ".$row['Description'];
echo "<br> Company-URL: ".$row['CompanyURL'];
echo "<br> Phone-Number: ".$row['Phone-Number'];
echo "<br> Address: ".$row['Address'];
echo "<br> Requirements: ".$row['Requirements'];
echo "<br> Job-Type: ".$row['JobType'];
echo "<br> JobCategory: ".$row['JobCategory'];
echo "<br><br><br><br><br>";

?>







 

 

why is my code not working ? please help

You want your url to look like this

 

http://www.hiringinhilo.com/Hilo-Jobs/Job-Search-Form/Getting-Data-From-Database/Job-Details/Job-Details.php?id=$row['id']

 

Then on the display page, get that ID number using $_GET['id']

 

On another note, you should only select columns from your database that you plan on using. You can shorten your initial query to

"SELECT `id`, `JobTitle` FROM `Jobs-table`"

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.