mysql - Why is my PHP Database query returning 6 rows when only 2 entries?

Solution:
You're looping through the results twice. Get rid of the unnecessaryforeach()
call (while()
will loop through all of the results of the query).
<?php
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)){
?>
<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"><?php echo $device['Model']; ?></div>
</div>
<?php
}
mysql_close();
?>
Note: I've also changedprint_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?).
Answer
Solution:
kindly correct the following line
<div class="device-name devicename-txt"><? print_r($device['Model']); ?></div>
with
<div class="device-name devicename-txt"><? echo($devicevalue['Model']); ?></div>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: your system folder path does not appear to be set correctly. please open the following file and correct this: index.php
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.