gpt4 book ai didi

php - 如何计算while语句运行php和sql的次数

转载 作者:行者123 更新时间:2023-12-04 04:38:30 24 4
gpt4 key购买 nike

嗨,我试图找出我的 while 语句运行了多少次,但我不知道如何执行此操作,我需要知道这是为了查看已输出到我的屏幕的行数,然后只显示一条消息找到号码后显示在屏幕上。我的代码很长。抱歉英语不好,提前致谢。

<?php
try {
$serverName = "127.0.0.0.0";
$connectionInfo = array( "Database"=>"database", "UID"=>"uid", "PWD"=>"pwd");
$conn = sqlsrv_connect( $serverName, $connectionInfo );
if( $conn === false )
{
die( print_r( sqlsrv_errors(), true));
}
$sql = "SELECT TOP 10 [company]
,[partnum]
,[description]
FROM [database].[uid].[table]
WHERE Part.partnum LIKE ? or Part.description LIKE ?";
/* Set parameter values. */
$params = array( "%" . str_replace(" ","%",$_POST["part"] ). "%", "%" . str_replace(" ","%",$_POST["part"] ) . "%");

$x = true;
/*echo print_r($params, true);*/
$stmt = sqlsrv_query( $conn, $sql, $params );

if( $stmt === false)
{
die( print_r( sqlsrv_errors(), true) );
}

while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) )
{

if($x == true)
{
echo"<form action=\"locations.php\" method=\"post\">";
echo"<input type=\"hidden\" name=\"part\" id=\"3\" value=\"".$row['partnum']."\">";
echo"<input type=\"hidden\" name=\"lon1\" id=\"1\" value=\"".$_POST["lon1"]."\">";
echo"<input type=\"hidden\" name=\"lat1\" id=\"2\" value=\"".$_POST["lat1"]."\">";
echo"<button type=\"submit\">";
echo "<div style=\"font-family:verdana;font-weight:bold;color:#3083FF;font-size:20px;width:100%;text-align:center;margin:0; padding:0;\">";
echo $row['partnum']."<br/>";
echo "</div>";
echo"<img style=\"width:50%;\"; src=\"productimages/".$row['partnum'].".jpg\" alt=\"Save icon\" onError=\"this.src='productimages/noimage.jpg'\"/>";
echo "<div style=\"font-family:verdana;color:#3083FF;font-size:20px;width:100%;text-align:center;margin:0; padding:0;\">";
echo $row['description'];
echo "</div>";
echo"</button>";
echo"</form>";

}

}

sqlsrv_free_stmt( $stmt);
} catch (Exception $e)
{
echo 'Caught exception: ', $e->getMessage(), "\n";
}
?>

最佳答案

$i = 0;

while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) )
{

if($x == true)
{
echo"<form action=\"locations.php\" method=\"post\">";
echo"<input type=\"hidden\" name=\"part\" id=\"3\" value=\"".$row['partnum']."\">";
echo"<input type=\"hidden\" name=\"lon1\" id=\"1\" value=\"".$_POST["lon1"]."\">";
echo"<input type=\"hidden\" name=\"lat1\" id=\"2\" value=\"".$_POST["lat1"]."\">";
echo"<button type=\"submit\">";
echo "<div style=\"font-family:verdana;font-weight:bold;color:#3083FF;font-size:20px;width:100%;text-align:center;margin:0; padding:0;\">";
echo $row['partnum']."<br/>";
echo "</div>";
echo"<img style=\"width:50%;\"; src=\"productimages/".$row['partnum'].".jpg\" alt=\"Save icon\" onError=\"this.src='productimages/noimage.jpg'\"/>";
echo "<div style=\"font-family:verdana;color:#3083FF;font-size:20px;width:100%;text-align:center;margin:0; padding:0;\">";
echo $row['description'];
echo "</div>";
echo"</button>";
echo"</form>";

}
$i++;
}

echo $i;

关于php - 如何计算while语句运行php和sql的次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19296635/

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