为什么这个 while 循环在移动到下一个条目之前显示内容两次?我有复视了!双重条目,而不仅仅是单个条目的列表。顺便说一下,我在 Wordpress 中使用 transient 数据。
输出显示如下:
name1
name1
name2
name2
name3
name3
我试图让它像这样渲染:
name1
name2
name3
<?php
$result = mysql_query("SELECT * FROM wp_options WHERE option_name LIKE '%fparent_name_%' ORDER BY option_id DESC");
while ($row = mysql_fetch_array($result))
{
$op_name = $row['option_name']; // get the value of the option
$op_time = substr($op_name, -10); // trim the option to the epoch time
$the_name = get_transient('fparent_name_'.$op_time); // get the name with epoch added
$phptime = new DateTime("@$op_time"); // convert UNIX timestamp to PHP DateTime
echo $the_name." - Submitted: ".$phptime->format('n/j/Y - g:ia'); // print the good stuff
?>
<form name="more" action="" method="post" id="more">
<input type="hidden" value="<?=$op_time;?>" name="timestamp" id="timestamp">
<input type="submit" value="See Details" name="details" id="details">
</form>
<br>
<?php
}
?>
最佳答案
mysql_fetch_array()
返回 MySQL 结果的关联数组和基于数字的数组。使用mysql_fetch_assoc()
相反。
Please, don't use mysql_*
functions in new code 。它们不再维护and are officially deprecated 。请参阅red box ?了解 prepared statements相反,并使用 PDO或MySQLi -this article将帮助您决定哪个。如果您选择 PDO,here is a good tutorial .
关于mysql - while 循环运行两次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15622441/