0

我必须解决问题,在下面运行脚本后,它会在最后打印出一个额外的标题?

我正在做的是从两个表中获取数据,并带有某些参数,然后将它们放入一个表中。最后的 echo $result 只是为了查看 $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;
    }
4

1 回答 1

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>";
    }  
于 2012-10-16T19:09:05.857 回答