2

晚上所有,

我使用的代码如下:

<?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 的结束标记,例如 < /tr>。问题是如果我为表格输入结束标签,它只会循环一次并在字段中显示 for 数据集,其余数据将不是表格格式。

问题 如何让循环继续显示字段中的所有数据,并显示页脚干净整洁,

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

4

3 回答 3

1

这有什么问题?

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

于 2013-04-06T05:03:25.563 回答
1
<?php while($row=mysql_fetch_array($result)){ ?>
<tr>
    <td><font face="Arial, Helvetica, sans-serif"><? echo $row['servername']; ?></font</td>
     . 
     .
</tr>

<? } ?>

你也可以这样使用。

于 2013-04-06T05:06:12.240 回答
0
$query = "SELECT * FROM your table name";
$result = mysql_query ($query) or die (mysql_error());

$num=mysql_numrows($result);
while($row = mysql_fetch_array($result))
{
  ob_start();

if (!$socket = @fsockopen( $row['serveraddress'], $row['portnumber'], $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 $row['servername']; ?></font</td>
    <td><font face="Arial, Helvetica, sans-serif"><? echo $row['serveraddress']; ?></font</td>
    <td><font face="Arial, Helvetica, sans-serif"><? echo $row['portnumber']; ?></font</td>
    <td><font face="Arial, Helvetica, sans-serif"><? echo $row['description']; ?></font</td>
    <td><font face="Arial, Helvetica, sans-serif"><? echo $status; ?></font</td>
<?php
 }

mysql_close();




?> 

试试这个

于 2013-04-06T05:15:29.410 回答