我正在寻找一个PHP等效于我在ASP中使用的rs.MoveNext
我只使用了大约一个星期的PHP(尽管我已经使用ASP 12年了,但我绝对不是一个专家),所以请容忍我的这一点…我正在尝试将我的经典ASP网站转换为PHP。到目前为止,我已经能够找到我的大多数问题的答案,但我被困在这一个 我正在寻找与ASP中使用的.MoveNext函数等效的PHP。我正在寻找一个PHP等效于我在ASP中使用的rs.MoveNext,php,asp-classic,Php,Asp Classic,我只使用了大约一个星期的PHP(尽管我已经使用ASP 12年了,但我绝对不是一个专家),所以请容忍我的这一点…我正在尝试将我的经典ASP网站转换为PHP。到目前为止,我已经能够找到我的大多数问题的答案,但我被困在这一个 我正在寻找与ASP中使用的.MoveNext函数等效的PHP。 $result = mysql_query ("SELECT sName, sURL FROM gktw_spcFriends ORDER BY sName ASC", $con) or die(mysql_erro
$result = mysql_query ("SELECT sName, sURL FROM gktw_spcFriends ORDER BY sName ASC", $con) or die(mysql_error());
$sSpecialFriends = "";
if (mysql_num_rows($result))
$row = mysql_fetch_array($result);
{
$sSpecialFriends = $sSpecialFriends."<table width=".Chr(34)."98%".Chr(34).">" ."\n";
do
{
$i=0;
$sSpecialFriends = $sSpecialFriends."<td valign=".Chr(34)."top".Chr(34).">" ."\n";
$sSpecialFriends = $sSpecialFriends."<p>" ."\n";
do
{
//Check for URL
if ($row['sURL'] != "")
{
$sSpecialFriends = $sSpecialFriends . "<a href='". str_replace("&", "&", $row['sURL']) . "' target=" . Chr(34) . "_blank" . Chr(34) . ">"."\n";
$sSpecialFriends = $sSpecialFriends . "" . str_replace("&", "&", $row['sName']) . "" ."\n";
$sSpecialFriends = $sSpecialFriends . "</a>" ."\n";
$sSpecialFriends = $sSpecialFriends . "<br>" ."\n";
}
//Otherwise just list their name
else
{
$sSpecialFriends = $sSpecialFriends . "" . str_replace("&", "&", $row['sName']) . "" ."\n";
$sSpecialFriends = $sSpecialFriends . "<br>" ."\n";
}
$i=$i+1;
}
while ($i<100);
$sSpecialFriends = $sSpecialFriends . "</td>" ."\n";
}
while($row = mysql_fetch_array($result));
$sSpecialFriends = $sSpecialFriends . "</table>" ."\n";
}
mysql_close($con);
在这个例子中,我有一个大约450条记录的表,虽然我希望所有记录都显示出来,但我只希望每列有100条记录。这可能不是很好的代码,但对我来说很有用
set rsSpecial = Server.CreateObject("ADODB.recordset")
'Grab all the Supporters Names and Website URLs Order by Name
rsSpecial.Open "SELECT sName, sURL FROM gktwspcf ORDER BY sName ASC", conn
if not rsSpecial.EOF then
sSpecialFriends = sSpecialFriends & "<table width=" & Chr(34) & "98%" & Chr(34) & ">" & vbCrLf
Do
i=0
sSpecialFriends = sSpecialFriends & "<td valign=" & Chr(34) & "top" & Chr(34) & ">" & vbCrLf
sSpecialFriends = sSpecialFriends & "<p>" & vbCrLf
Do
if rsSpecial("sURL") <> "" Then
sSpecialFriends = sSpecialFriends & "<a href='"& Replace(rsSpecial("sURL"), "&", "&") & "' target=" & Chr(34) & "_blank" & Chr(34) & ">"
sSpecialFriends = sSpecialFriends & "" & Replace(rsSpecial("sName"), "&", "&") & ""
sSpecialFriends = sSpecialFriends & "</a>"
sSpecialFriends = sSpecialFriends & "<br>" & vbCrLF
'Otherwise just list their name
else
sSpecialFriends = sSpecialFriends & "" & Replace(rsSpecial("sName"), "&", "&") & ""
sSpecialFriends = sSpecialFriends & "<br>" & vbCrLF
end if
i=i+1
rsSpecial.MoveNext
Loop Until i=100 or rsSpecial.EOF
sSpecialFriends = sSpecialFriends & "</td>" & vbCrLf
Loop Until rsSpecial.EOF
sSpecialFriends = sSpecialFriends & "</table>" & vbCrLf
end if
rsSpecial.Close
Set rsSpecial=Nothing
set rsSpecial=Server.CreateObject(“ADODB.recordset”)
“按姓名顺序获取所有支持者的姓名和网站URL
rsSpecial.打开“通过sName ASC从gktwspcf订单中选择sName,sURL”,康涅狄格州
如果不是rsSpecial.EOF,则
ssspecialfriends=ssspecialfriends&&vbCrLf
做
i=0
ssspecialfriends=ssspecialfriends&&vbCrLf
ssspecialfriends=ssspecialfriends&“”&vbCrLf
做
如果是特殊(“sURL”)“那么
SSSpecialFriends=SSSpecialFriends&“”
ssspecialfriends=ssspecialfriends&“
”&vbCrLF
否则,只需列出他们的名字
其他的
ssspecialfriends=ssspecialfriends&&Replace(rsSpecial(“sName”)、“&”、“&;”&“
ssspecialfriends=ssspecialfriends&“
”&vbCrLF
如果结束
i=i+1
rsSpecial.MoveNext
循环直到i=100或rsSpecial.EOF
ssspecialfriends=ssspecialfriends&&vbCrLf
循环到rsSpecial.EOF
ssspecialfriends=ssspecialfriends&&vbCrLf
如果结束
特别节目,结束
设置rsSpecial=Nothing
我似乎找不到一个很好的例子来说明如何在PHP中重新创建一个嵌套循环,以便移动到下一条记录。这就是我到目前为止所拥有的——它显示了每条记录,100倍,100列宽我想我需要找个地方插入与MoveNext相当的PHP。
$result = mysql_query ("SELECT sName, sURL FROM gktw_spcFriends ORDER BY sName ASC", $con) or die(mysql_error());
$sSpecialFriends = "";
if (mysql_num_rows($result))
$row = mysql_fetch_array($result);
{
$sSpecialFriends = $sSpecialFriends."<table width=".Chr(34)."98%".Chr(34).">" ."\n";
do
{
$i=0;
$sSpecialFriends = $sSpecialFriends."<td valign=".Chr(34)."top".Chr(34).">" ."\n";
$sSpecialFriends = $sSpecialFriends."<p>" ."\n";
do
{
//Check for URL
if ($row['sURL'] != "")
{
$sSpecialFriends = $sSpecialFriends . "<a href='". str_replace("&", "&", $row['sURL']) . "' target=" . Chr(34) . "_blank" . Chr(34) . ">"."\n";
$sSpecialFriends = $sSpecialFriends . "" . str_replace("&", "&", $row['sName']) . "" ."\n";
$sSpecialFriends = $sSpecialFriends . "</a>" ."\n";
$sSpecialFriends = $sSpecialFriends . "<br>" ."\n";
}
//Otherwise just list their name
else
{
$sSpecialFriends = $sSpecialFriends . "" . str_replace("&", "&", $row['sName']) . "" ."\n";
$sSpecialFriends = $sSpecialFriends . "<br>" ."\n";
}
$i=$i+1;
}
while ($i<100);
$sSpecialFriends = $sSpecialFriends . "</td>" ."\n";
}
while($row = mysql_fetch_array($result));
$sSpecialFriends = $sSpecialFriends . "</table>" ."\n";
}
mysql_close($con);
$result=mysql\u query(“按sName ASC从gktw\u spcFriends订单中选择sName、sURL,$con)”或die(mysql\u error());
$ssspecialfriends=“”;
if(mysql_num_行($result))
$row=mysql\u fetch\u数组($result);
{
$sSpecialFriends=$sSpecialFriends.“\n”;
做
{
$i=0;
$sSpecialFriends=$sSpecialFriends.“\n”;
$sSpecialFriends=$sSpecialFriends.“”\n”;
做
{
//检查URL
如果($row['sURL']!=“”)
{
$sSpecialFriends=$sSpecialFriends.“\n”;
$sSpecialFriends=$sSpecialFriends.“
”\n”;
}
//否则只需列出他们的名字
其他的
{
$sSpecialFriends=$sSpecialFriends.“.str_替换(&)”,“&;”,$row['sName'])。”。“\n”;
$sSpecialFriends=$sSpecialFriends.“
”\n”;
}
$i=$i+1;
}
虽然($i欢迎使用StackOverflow,Matt。除非您使用的是ADODB库,否则PHP不会真正像那样工作。下面的PHP脚本会在MOVENEXT这样的记录中循环:
// Get all the data from the "example" table
$result = mysql_query("SELECT * FROM example")
or die(mysql_error());
echo "<table border='1'>";
echo "<tr> <th>Name</th> <th>Age</th> </tr>";
// keeps getting the next row until there are no more to get
while ($row = mysql_fetch_array($result)) {
echo "<tr><td>";
echo $row['name'];
echo "</td><td>";
echo $row['age'];
echo "</td></tr>";
}
echo "</table>";
mysql_close($dbConn);
我建议使用更简单的顶级版本。$row=mysql\u fetch\u array($result);
?这是一个答案、注释还是问题?抱歉,我认为这很明显……我太懒了,无法写出正确的答案。$row=mysql\u fetch\u array($result)
获取下一条记录,并将其分配给$row
,这可能是您所需要的。对不起,对于已经这样做超过一周的人(并且有任何天赋)来说,这可能是显而易见的。我只是不知道该放在哪里。它是有效的,谢谢你的帮助。我的假设是这是你的代码,既然你已经知道如何获取记录集中的下一行,我可以指出它。