gpt4 book ai didi

使用 HTML 表格的 PHP 循环

转载 作者:行者123 更新时间:2023-11-28 00:10:05 25 4
gpt4 key购买 nike

晚上好,

我使用的代码如下:

<?php
/**
* The template for displaying all pages.
* Template Name: addserverindexoci
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages
* and that other 'pages' on your WordPress site will use a
* different template.
*
* @package WordPress
* @subpackage Twenty_Twelve
* @since Twenty Twelve 1.0
*/

get_header(); ?>




<div id="primary" class="site-content">
<div id="content" role="main">



<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php comments_template( '', true ); ?>

<?php endwhile; // end of the loop. ?>

<table border="2" bordercolor="#000000" style="background-color:#FFFFFF" width="160%" cellpadding="1" cellspacing="0">
<td><font face="Arial, Helvetica, sans-serif">Server Name</font</td>
<td><font face="Arial, Helvetica, sans-serif">Server Address</font</td>
<td><font face="Arial, Helvetica, sans-serif">Server Port</font</td>
<td><font face="Arial, Helvetica, sans-serif">Server Description</font</td>
<td><font face="Arial, Helvetica, sans-serif"> Status</font</td>

<?php

mysql_connect("localhost", "", "") or die (mysql_error());
#echo "Connected to MYSQL ";
mysql_select_db("starforg_search") or die (mysql_error());
#echo "Connected to Data Base";
$query = "SELECT * FROM ";
$result = mysql_query ($query) or die (mysql_error());

$num=mysql_numrows($result);

mysql_close();


$i=0;
while ($i < $num) {


$value = mysql_result($result,$i,"servername");
$value2 = mysql_result($result,$i,"serveraddress");
$value3 = mysql_result($result,$i,"portnumber");
$value4 = mysql_result($result,$i,"description");

ob_start();

if (!$socket = @fsockopen($value2, $value3, $errno, $errstr, 1))
{
echo "&nbsp;<font color='red'><CENTRE><strong> Server Is Offline!</strong></CENTRE></font>";
}
else
{
echo "&nbsp;<font color='green'><CENTRE><strong> Server Is Online!</strong></CENTRE></font>";

fclose($socket);
}
$status = ob_get_contents();
ob_end_clean();
?>


<tr>
<td><font face="Arial, Helvetica, sans-serif"><? echo $value; ?></font</td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $value2; ?></font</td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $value3; ?></font</td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $value4; ?></font</td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $status; ?></font</td>



<?
$i++;

}

?>

</div><!-- #primary -->


<?php get_footer(); ?>

我想要什么现在,正如您从 while 循环中看到的那样,我正在尝试显示所选字段内的所有数据。

发生了什么我想一直循环直到所有数据都显示出来,但是数据会转到我假设的页面底部,因为我没有使用 html 的结束标记,例如 。问题是,如果我为表格输入结束标记,它只会循环一次并在字段中显示 for 数据集,其余数据将不会采用表格格式。

问题我怎样才能让循环继续显示字段中的所有数据,并使页脚干净整洁,

注意:对不起,如果这有点粗糙我今天生病了:(

最佳答案

这是怎么回事?

<table border="2" bordercolor="#000000" style="background-color:#FFFFFF" width="160%" cellpadding="1" cellspacing="0">  
<tr>
<td><font face="Arial, Helvetica, sans-serif">Server Name</font</td>
<td><font face="Arial, Helvetica, sans-serif">Server Address</font</td>
<td><font face="Arial, Helvetica, sans-serif">Server Port</font</td>
<td><font face="Arial, Helvetica, sans-serif">Server Description</font</td>
<td><font face="Arial, Helvetica, sans-serif"> Status</font</td>
</tr>
<?php

mysql_connect("localhost", "", "") or die (mysql_error());
#echo "Connected to MYSQL ";
mysql_select_db("starforg_search") or die (mysql_error());
#echo "Connected to Data Base";
$query = "SELECT * FROM tablename";
$result = mysql_query ($query) or die (mysql_error());

$num=mysql_numrows($result);

mysql_close();


$i=0;
while ($i < $num) {


$value = mysql_result($result,$i,"servername");
$value2 = mysql_result($result,$i,"serveraddress");
$value3 = mysql_result($result,$i,"portnumber");
$value4 = mysql_result($result,$i,"description");

ob_start();

if (!$socket = @fsockopen($value2, $value3, $errno, $errstr, 1))
{
echo "&nbsp;<font color='red'><CENTRE><strong> Server Is Offline!</strong></CENTRE></font>";
}
else
{
echo "&nbsp;<font color='green'><CENTRE><strong> Server Is Online!</strong></CENTRE></font>";

fclose($socket);
}
$status = ob_get_contents();
ob_end_clean();
?>


<tr>
<td><font face="Arial, Helvetica, sans-serif"><? echo $value; ?></font</td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $value2; ?></font</td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $value3; ?></font</td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $value4; ?></font</td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $status; ?></font</td>
</tr>


<?
$i++;

}

?>
</table>

而且我没有在您的查询中找到表名 $query = "SELECT * FROM ";

关于使用 HTML 表格的 PHP 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15847093/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com