-2

我有一个显示链接的页面,所以当我单击该链接时,它应该将我带到另一个页面并查询数据库,以便我只能看到该特定链接的信息。但是现在它给了我一个问题,它与我在其他程序中使用的代码相同。我已经尝试了将近 2 个小时来解决这个问题。请下面是任何可以帮助您的代码。

First piece of code or page 
<?php 
$selector1 =("SELECT job_id, job_title, job_description, 
job_category, wantORoffering, address, cell, email, date_registered, 
user_id from h2s_job ORDER BY date_registered DESC LIMIT $offset, $rowsperpage");
$result_selector=$con->prepare($selector1);
$result_selector->execute();
while($row = $result_selector->fetch(PDO::FETCH_ASSOC)){
#substring 
$job_description = $row['job_description'];
$job_description  = wordwrap($job_description , 200);
$job_description  = explode("\n", $job_description );
$job_description  = $job_description [0] . '...';
#substring 
echo '<a href="jobdetails.php?job_id=$job_id"><div id="record" id ="record-">
<strong class="pic"><img src="images/nopic.png" ></strong>
<strong class="job_title"><h4>',$row['job_title'],'</h4></strong></br>
 <strong class ="desc"><p>',$job_description,'</p></strong></br>
  <strong class="contact"><p>',$row['cell'],'</strong></br>
<strong class="time"><p>',$row['date_registered'],'</strong></br>
</div></a>';
}?>



Second page 


<?php 

$selector =("SELECT  job_title, job_description, 
job_category, wantORoffering, address, cell, email, date_registered, 
user_id FROM  h2s_job WHERE job_id =".$_GET['job_id']);
$result_selector=$con->prepare($selector);
$result_selector->execute();
while($row = $result_selector->fetch(PDO::FETCH_ASSOC)){
#substring 
$job_description = $row['job_description'];
echo '<div id="record" id ="record-">
<strong class="pic"><img src="images/nopic.png" ></strong>
<strong class="job_title"><h4>',$row['job_title'],'</h4></strong></br>
 <strong class ="desc"><p>',$job_description,'</p></strong></br>
  <strong class="contact"><p>',$row['cell'],'</strong></br>
<strong class="time"><p>',$row['date_registered'],'</strong></br>
</div></a>';
}
?>

我得到的错误

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column '$job_id' in 'where clause'' in C:\wamp\www\houseCurrent\jobdetails.php:98 Stack trace: #0 C:\wamp\www\houseCurrent\jobdetails.php(98): PDOStatement->execute() #1 {main} thrown in C:\wamp\www\houseCurrent\jobdetails.php on line 98
4

2 回答 2

2

你一开始忘记添加$job_id = $row['job_id'];的概率while

于 2013-03-27T09:43:11.267 回答
1

$job_id 似乎没有定义,并且使用 echo-statement 创建的链接不是您想要的(我期望...) Option1 没有分配 job_id 实际值(它分配字符串'$job_id')。

选项 2 做到了,并将 job_id 分配给值 5。

<?php
$job_id = 5; //example

//OPTION 1 This would output to html => jobdetails.php?job_id=$job_id
echo '<a href="jobdetails.php?job_id=$job_id">test</a>';

//OPTION 2 This would output to html => jobdetails.php?job_id=5
echo '<a href="jobdetails.php?job_id=' . $job_id . '">test</a>';
?>

你可以改变......(选项1)

echo '<a href="jobdetails.php?job_id=$job_id"><div id="record" id ="record-">
<strong class="pic"><img src="images/nopic.png" ></strong>
<strong class="job_title"><h4>',$row['job_title'],'</h4></strong></br>
 <strong class ="desc"><p>',$job_description,'</p></strong></br>
  <strong class="contact"><p>',$row['cell'],'</strong></br>
<strong class="time"><p>',$row['date_registered'],'</strong></br>
</div></a>';

至(选项 2)

echo '<a href="jobdetails.php?job_id=' . $job_id . '"><div id="record" id ="record-">
<strong class="pic"><img src="images/nopic.png" ></strong>
<strong class="job_title"><h4>' . $row['job_title'] . '</h4></strong></br>
 <strong class ="desc"><p>' . $job_description . '</p></strong></br>
  <strong class="contact"><p>' . $row['cell'] . '</strong></br>
<strong class="time"><p>' . $row['date_registered'] . '</strong></br>
</div></a>';

逗号已替换为句点,因为 . 用于字符串的连接。

于 2013-03-27T09:57:06.927 回答