在网页上打印两个表格标题 [英] Two Table headings printed on webpage

查看:140
本文介绍了在网页上打印两个表格标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在做的是从两个表格中获取数据,并在下面运行脚本后打印出额外的标题然后将某些参数放入表格中。最后的echo $结果只是看看$ result中还有什么,它在额外的头部之前和头部之后打印出一个值。





  extract(shortcode_atts(array(
countryid=>'',
),$ atts));


//设置变量
//从示例表中获取所有数据

$ joburl =http:// www .x.co.za /工作/视图/;
$ 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)
或die(mysql_error());

echo< table border ='1'>;
echo< tr>< th>第< th>第< th>第< th< th< th>行业< / th>< / tr>

//继续获取下一行,直到没有更多的元素获得

为止($ row = mysql_fetch_array($ result)){

//将每行的内容打印到表格中

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'];
回显< / td>< / tr>;
}
echo< / table>;
echo $ result;
}


解决方案

p>

将表头行和关闭表的标记置于以下条件中

  $ count = mysql_num_rows($ result); 

if($ count> 0){
echo< table border ='1'>;
echo< tr>< th>第< th>第< th>第< th< th< th>行业< / th>< / tr>
}
//你的while循环
while(...){
....
}
if($ count> 0) {
echo< / table>;
}


I have to following problem, after running script below it prints out an extra header at the end?

What I am doing is getting data from two tables, with certain parameters then placing them into a table. The echo $result at the end is just to see what is still inside $result and it prints out a value before the extra header as well as right after the header.

How can I get around that?

        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;
    }

解决方案

Ok Try as below

Put your header line and close tag of table into below condition

    $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>";
    }  

这篇关于在网页上打印两个表格标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆