免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
打印 上一主题 下一主题

我的这个php应该怎么写????哪位帮我看看? [复制链接]

论坛徽章:
0
11 [报告]
发表于 2003-11-28 13:38 |只看该作者

我的这个php应该怎么写????哪位帮我看看?

我改为
<?php
$db = mysql_connect("localhost","root","";
mysql_select_db("test",$db);
$user_query = "select * from logfile limit 20";
$user_result = mysql_query($user_query,$db);
echo "<table border=1>;\n";
echo "<tr>;<td>;srcIP</td>;<td>;dstIP</td>;<td>;prot</td>;<td>;srcport</td>;<td>;dstport</td>;<td>;octets</td>;<td>;packtes</td>;</tr>;\n";
while ($myrow = mysql_fetch_array($user_result))
{
printf("<tr>;<td>;srcIP</td>;<td>;dstIP</td>;<td>;prot</td>;<td>;srcport</td>;<td>;dstport</td>;<td>;octets</td>;<td>;packtes</td>;</tr>;\n", $myrow[srcIP], $myrow[dstIP], $myrow[prot], $myrow[srcport], $myrow[dstport], $myrow[octets], $myrow[packtes]);}
echo "</table>;\n";
?>;

还是不行啊!显示的还是字段!sql语句没执行!

1.jpg (66.43 KB, 下载次数: 13)

结果如下:

结果如下:

论坛徽章:
0
12 [报告]
发表于 2003-11-28 13:56 |只看该作者

我的这个php应该怎么写????哪位帮我看看?

printf("<tr>;<td>;srcIP</td>;<td>;dstIP</td>;<td>;prot</td>;<td>;srcport</td>;<td>;dstport</td>;<td>;octets</td>;<td>;packtes</td>;</tr>;\n", $myrow[srcIP], $myrow[dstIP], $myrow[prot], $myrow[srcport], $myrow[dstport], $myrow[octets], $myrow[packtes]);}

你把这些字段输出到哪了呢?
$tmp = 123456;
printf("TEMP IS %d", $tmp);
printf的格式是这样的~~你没写%d、%s~~~它怎么会有输出呢?
还有,建议用echo~~这样你输出表格的形式要好控制一些~

论坛徽章:
0
13 [报告]
发表于 2003-11-28 15:21 |只看该作者

我的这个php应该怎么写????哪位帮我看看?

原帖由 "mikespook" 发表:
);}

你把这些字段输出到哪了呢?
$tmp = 123456;
printf("TEMP IS %d", $tmp);
printf的格式是这样的~~你没写%d、%s~~~它怎么会有输出呢?
还有,建议用echo~~这样你输出表格的形式要好控制一些~


非常感谢!!!!
现在数据好象可以查询了,但我不知道 printf的格式~~%d、%s~~~怎么会写,我用:printf("<tr>;<td>;%s %s</td>;<td>;%s</tr>;\n",  $myrow[srcIP], $myrow[dstIP], $myrow[prot], $myrow[srcport], $myrow[dstport], $myrow[octets], $myrow[packtes]);
显示不正确,我共有上面7个字段,只显示了2个字段?
如下图:

1.jpg (60.51 KB, 下载次数: 11)

1.jpg

论坛徽章:
0
14 [报告]
发表于 2003-11-28 16:19 |只看该作者

我的这个php应该怎么写????哪位帮我看看?

倒~~~你一共7个字段~~~才用两个%s匹配,那肯定不显示~~~

sprintf
(PHP 3, PHP 4 )

sprintf -- Return a formatted string
Description
string sprintf ( string format [, mixed args])


Returns a string produced according to the formatting string format.

The format string is composed of zero or more directives: ordinary characters (excluding %) that are copied directly to the result, and conversion specifications, each of which results in fetching its own parameter. This applies to both sprintf() and printf().

Each conversion specification consists of a percent sign (%), followed by one or more of these elements, in order:


An optional padding specifier that says what character will be used for padding the results to the right string size. This may be a space character or a 0 (zero character). The default is to pad with spaces. An alternate padding character can be specified by prefixing it with a single quote ('). See the examples below.

An optional alignment specifier that says if the result should be left-justified or right-justified. The default is right-justified; a - character here will make it left-justified.

An optional number, a width specifier that says how many characters (minimum) this conversion should result in.

An optional precision specifier that says how many decimal digits should be displayed for floating-point numbers. This option has no effect for other types than float. (Another function useful for formatting numbers is number_format().)

A type specifier that says what type the argument data should be treated as. Possible types:


% - a literal percent character. No argument is required.  
b - the argument is treated as an integer, and presented as a binary number.  
c - the argument is treated as an integer, and presented as the character with that ASCII value.  
d - the argument is treated as an integer, and presented as a (signed) decimal number.  
u - the argument is treated as an integer, and presented as an unsigned decimal number.  
f - the argument is treated as a float, and presented as a floating-point number.  
o - the argument is treated as an integer, and presented as an octal number.  
s - the argument is treated as and presented as a string.  
x - the argument is treated as an integer and presented as a hexadecimal number (with lowercase letters).  
X - the argument is treated as an integer and presented as a hexadecimal number (with uppercase letters).  




As of PHP version 4.0.6 the format string supports argument numbering/swapping. Here is an example: 例子 1. Argument swapping

$format = "There are %d monkeys in the %s";
printf($format,$num,$location);


This might output, "There are 5 monkeys in the tree". But imagine we are creating a format string in a separate file, commonly because we would like to internationalize it and we rewrite it as: 例子 2. Argument swapping

$format = "The %s contains %d monkeys";
printf($format,$num,$location);


We now have a problem. The order of the placeholders in the format string does not match the order of the arguments in the code. We would like to leave the code as is and simply indicate in the format string which arguments the placeholders refer to. We would write the format string like this instead: 例子 3. Argument swapping

$format = "The %2\$s contains %1\$d monkeys";
printf($format,$num,$location);


An added benefit here is that you can repeat the placeholders without adding more arguments in the code. For example: 例子 4. Argument swapping

$format = "The %2\$s contains %1\$d monkeys.
           That's a nice %2\$s full of %1\$d monkeys.";
printf($format, $num, $location);




See also printf(), sscanf(), fscanf(), and number_format().

Examples
例子 5. sprintf(): zero-padded integers

$isodate = sprintf("%04d-%02d-%02d", $year, $month, $day);


例子 6. sprintf(): formatting currency

$money1 = 68.75;
$money2 = 54.35;
$money = $money1 + $money2;
// echo $money will output "123.1";
$formatted = sprintf("%01.2f", $money);
// echo $formatted will output "123.10"

论坛徽章:
0
15 [报告]
发表于 2003-11-28 22:46 |只看该作者

我的这个php应该怎么写????哪位帮我看看?

原帖由 "mikespook"]args 发表:
)


Returns a string produced according to the formatting string format.

The format string is composed of zero or more directives: ordinary characters (excluding %) that are copied directl..........


很感谢你的回答!!以前没弄过程序的,问题估计有点弱智。别见怪!呵呵!
我现在改为:
printf("<tr>;<td>;%d</td>;<td>;%d</td>;<td>;%d</td>;<td>;%d</td>;<td>;%d</td>;<td>;%d</td>;<td>;%d</td>;</tr>;\n",  $myrow[源IP地址], $myrow[目的IP地址], $myrow[协议类型], $myrow[源端口], $myrow[目的端口], $myrow[字节数], $myrow[包大小]);

其他字端都对,ip地址段我不知道用什么参数?ip地址字段我定义的是varchar

还有,你说的用echo怎么写?

结果见下图:

1.jpg (65.84 KB, 下载次数: 11)

1.jpg

论坛徽章:
0
16 [报告]
发表于 2003-11-29 00:00 |只看该作者

我的这个php应该怎么写????哪位帮我看看?

用%s来写varchar类型字段~~~~
echo "<tr>;<td>;$myrow[源IP地址]</td>;</tr>;";

论坛徽章:
0
17 [报告]
发表于 2003-11-29 00:00 |只看该作者

我的这个php应该怎么写????哪位帮我看看?

用%s来写varchar类型字段~~~~
echo "<tr>;<td>;$myrow[源IP地址]</td>;</tr>;";

论坛徽章:
0
18 [报告]
发表于 2003-11-29 12:39 |只看该作者

我的这个php应该怎么写????哪位帮我看看?

[quote]原帖由 "mikespook"]]</td>;</tr>;";[/quote 发表:


我用printf("<tr>;<td>;%s</td>;<td>;%s</td>;<td>;%d</td>;<td>;%d</td>;<td>;%d</td>;<td>;%d</td>;<td>;%d</td>;</tr>;\n",  $myrow[源IP地址], $myrow[目的IP地址], $myrow[协议类型], $myrow[源端口], $myrow[目的端口], $myrow[字节数], $myrow[包大小]);

和echo "<tr>;<td>;$myrow[源IP地址]</td>;<td>;$myrow[目的IP地址]</td>;<td>;$myrow[协议类型]</td>;<td>;$myrow[源端口]</td>;<td>;$myrow[目的端口]</td>;<td>;$myrow[字节数]</td>;<td>;$myrow[包大小]</td>;</tr>;";
两种都试了,显示的结果如下图:(还有,ip地址如192.168.0.23用varchar型可以吗)

1.jpg (48.65 KB, 下载次数: 11)

1.jpg

论坛徽章:
0
19 [报告]
发表于 2003-11-29 19:14 |只看该作者

我的这个php应该怎么写????哪位帮我看看?

我觉得更像你表格的问题~~~~

你看了输出的网页原代码了么?如果没显示,应该是空的表格~~但是实际上你这是表格少了两列~~~

论坛徽章:
0
20 [报告]
发表于 2003-11-29 20:37 |只看该作者

我的这个php应该怎么写????哪位帮我看看?

我看网页源代码是:没显示出来,但这两列数据在数据库表里能看到啊 !

<table border=1>;
流量前30位排名<tr>;<td>;源IP地址</td>;<td>;目的IP地址</td>;<td>;协议类型</td>;<td>;源端口</td>;<td>;目的端口</td>;<td>;字节数</td>;<td>;包大小</td>;</tr>;
<tr>;<td>;</td>;<td>;</td>;<td>;1</td>;<td>;711</td>;<td>;9000</td>;<td>;139</td>;<td>;445607</td>;</tr>;<tr>;<td>;</td>;<td>;</td>;<td>;1</td>;<td>;711</td>;<td>;9000</td>;<td>;139</td>;<td>;43221</td>;</tr>;<tr>;<td>;</td>;<td>;</td>;<td>;1</td>;<td>;711</td>;<td>;9000</td>;<td>;8080</td>;<td>;33411</td>;</tr>;<tr>;<td>;</td>;<td>;</td>;<td>;1</td>;<td>;135</td>;<td>;9000</td>;<td>;8080</td>;<td>;33411</td>;</tr>;<tr>;<td>;</td>;<td>;</td>;<td>;1</td>;<td>;80</td>;<td>;9000</td>;<td>;8080</td>;<td>;4506</td>;</tr>;<tr>;<td>;</td>;<td>;</td>;<td>;6</td>;<td>;80</td>;<td>;9000</td>;<td>;8080</td>;<td>;4506</td>;</tr>;<tr>;<td>;</td>;</tr>;</table>;
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP