I’ve got 2 entries in my database table, however for some reason my PHP/SQL is showing 6 replicates of each.
<?
mysql_select_db($database_database_connection, $database_connection);
$getdevices=("SELECT * FROM Device_tbl");
$getdevicesresult = mysql_query($getdevices, $database_connection) or die(mysql_error());
while($device=mysql_fetch_assoc($getdevicesresult))
{
foreach($device as $devicevalue) { ?>
<div class="hold-cont">
<div class="holder">
<div class="image-hold" >
<img class="image-icon" src="images/android.png"/>
</div>
</div>
<div class="device-name devicename-txt"><? print_r($device['Model']); ?></div>
</div>
<? }}
mysql_close();
?>
That should only return the 2 rows, not 6 for each entry. Any ideas?
You’re looping through the results twice. Get rid of the unnecessary
foreach()call (while()will loop through all of the results of the query).Note: I’ve also changed
print_r(...)toecho ...as$device['Model']is not an array and I’ve changed your short opening tags (<?) to normal ones (<?php) as not all servers supportshort tags(see Are PHP short tags acceptable to use?).