我必须遵循以下问题,在运行下面的脚本后,它会在末尾打印出一个额外的标题?
我正在做的是从两个表中获取数据,然后使用某些参数将它们放入表中。最后的echo $结果只是为了查看$ result内部的内容,它会在额外标题之前以及标题之后打印出一个值。
我怎样才能解决这个问题?
extract(shortcode_atts(array(
"countryid"=>'',
), $atts));
// Setting up variables
// Get all the data from the "example" table
$joburl = "http://www.x.co.za/job/view/";
$result = mysql_query("SELECT wpjb_job.company_name , wpjb_job.job_category , wpjb_job.job_country ,
wpjb_job.job_title , wpjb_job.job_slug ,
wpjb_category.id , wpjb_category.title
FROM wpjb_job
INNER JOIN wpjb_category ON wpjb_job.job_category = wpjb_category.id
WHERE job_country='$countryid'
AND(is_filled='0' AND is_active='1')
ORDER BY job_title")
or die(mysql_error());
echo "<table border='1'>";
echo "<tr> <th>Job</th> <th>Company</th> <th>Industry</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo '<a href ="http://www.x.co.za/job/view/'.$row['job_slug'].'"> '.$row['job_title'].' </a>';
echo "</td><td>";
echo $row['company_name'];
echo "</td><td>";
echo $row['title'];
echo "</td></tr>";
}
echo "</table>";
echo $result;
}
答案 0 :(得分:0)
好的,请尝试以下
将标题行和表格的关闭标记放入以下条件
$count = mysql_num_rows($result);
if($count > 0){
echo "<table border='1'>";
echo "<tr> <th>Job</th> <th>Company</th> <th>Industry</th> </tr>";
}
//your while loop
while(...) {
....
}
if($count > 0){
echo "</table>";
}