Reputation: 3
Why is this while loop showing the content two times before moving to the next entry? I've got double vision! Double entries instead of just a list of single entries. I'm using transient data with Wordpress by the way.
The output shows like this:
name1
name1
name2
name2
name3
name3
I'm trying to have it render like this:
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
}
?>
Upvotes: 0
Views: 685
Reputation: 219894
mysql_fetch_array()
returns both an associative and numeric based array of your MySQL results. Use mysql_fetch_assoc()
instead.
Please, don't use mysql_*
functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.
Upvotes: 1