igorek24 Posted May 31, 2015 Share Posted May 31, 2015 Hi all,I'm new to this forum and jest started to learn php. I'm working on a project and when I echoing data from database, for some reason it's doubling it self on html page.Here is the source code: https://git.theigor.net/igorek24/phpMyVST/blob/master/www/index.phpand page: http://dev.phpmyvst.com/Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/296574-newbie-same-row-from-db-printed-twice/ Share on other sites More sharing options...
QuickOldCar Posted May 31, 2015 Share Posted May 31, 2015 Because you echo out 2 in the while loop. You have this 2 times in the loop echo "<br><div class=\"col-md-4 \"><ul class=\"list-group\">"; echo "<li class=\"list-group-item\"><strong>Number of Cylinders:</strong> $vehicle[cylender_count]</li>"; echo "<li class=\"list-group-item\"><strong>Displacement:</strong> $vehicle[eng_size]</li>"; echo "<li class=\"list-group-item\"><strong>Horsepower:</strong> $vehicle[eng_hp]</li>"; echo "<li class=\"list-group-item\"><strong>Transmission:</strong> $vehicle[transmission]</li>"; echo "<li class=\"list-group-item\"><strong>Color(extr/intr):</strong> $vehicle[ext_color]/$vehicle[int_color] </li>"; echo "<li class=\"list-group-item\"><strong>Fuel Tank Capacity:</strong> $vehicle[fuel_tank_capacity] Gal.</li>"; echo "</ul></div>"; Quote Link to comment https://forums.phpfreaks.com/topic/296574-newbie-same-row-from-db-printed-twice/#findComment-1512941 Share on other sites More sharing options...
igorek24 Posted May 31, 2015 Author Share Posted May 31, 2015 (edited) Because you echo out 2 in the while loop. You have this 2 times in the loop echo "<br><div class=\"col-md-4 \"><ul class=\"list-group\">"; echo "<li class=\"list-group-item\"><strong>Number of Cylinders:</strong> $vehicle[cylender_count]</li>"; echo "<li class=\"list-group-item\"><strong>Displacement:</strong> $vehicle[eng_size]</li>"; echo "<li class=\"list-group-item\"><strong>Horsepower:</strong> $vehicle[eng_hp]</li>"; echo "<li class=\"list-group-item\"><strong>Transmission:</strong> $vehicle[transmission]</li>"; echo "<li class=\"list-group-item\"><strong>Color(extr/intr):</strong> $vehicle[ext_color]/$vehicle[int_color] </li>"; echo "<li class=\"list-group-item\"><strong>Fuel Tank Capacity:</strong> $vehicle[fuel_tank_capacity] Gal.</li>"; echo "</ul></div>"; Hi QuickOldCar, Thanks for the reply. There are three columns and the data is similar (I just don't have anything in the database so I just added same columns from database). As you can see , there is two same rows of three columns on the page and i cant figure out how to fix this. As you can see that image is being echoed once but there is two on the page. if (isset ($vehicle["veh_image"])) { echo "<br/><img src=\"$vehicle[veh_image]\" alt=\"VEHICLE_THUMB\" class=\"img-thumbnail\">"; } else { echo "<br/><img src=\"images/no_photo_icon.png\" alt=\"VEHICLE_THUMB\" class=\"img-thumbnail\">"; Edited May 31, 2015 by igorek24 Quote Link to comment https://forums.phpfreaks.com/topic/296574-newbie-same-row-from-db-printed-twice/#findComment-1512945 Share on other sites More sharing options...
igorek24 Posted May 31, 2015 Author Share Posted May 31, 2015 Here is the page without style: http://dev.phpmyvst.com/test.php Quote Link to comment https://forums.phpfreaks.com/topic/296574-newbie-same-row-from-db-printed-twice/#findComment-1512946 Share on other sites More sharing options...
CroNiX Posted June 1, 2015 Share Posted June 1, 2015 I'm thinking its your query returning duplicate results. Have you checked what's actually being returned in the resultset? Quote Link to comment https://forums.phpfreaks.com/topic/296574-newbie-same-row-from-db-printed-twice/#findComment-1512947 Share on other sites More sharing options...
igorek24 Posted June 1, 2015 Author Share Posted June 1, 2015 (edited) I'm thinking its your query returning duplicate results. Have you checked what's actually being returned in the resultset? Here is the var_damp (which is printed twice as well): http://dev.phpmyvst.com/test.php array (size=16) 'odometer_read' => string '25000' (length=5) 'service_type' => string 'brake replacement' (length=17) 'year' => string '2011' (length=4) 'make' => string 'Audi' (length=4) 'model' => string 'Q5' (length=2) 'vin' => string 'WTP20155565626667' (length=17) 'veh_image' => string 'images/audi_q5.png' (length=18) 'ext_color' => string 'White' (length=5) 'int_color' => string 'Balck' (length=5) 'body_type' => string 'SUV' (length=3) 'cylender_count' => string '4' (length=1) 'eng_size' => string '2.0' (length=3) 'eng_hp' => null 'fuel_type' => string 'GAS' (length=3) 'fuel_tank_capacity' => string '16' (length=2) 'transmission' => string '6 Speed Automatic' (length=17) Edited June 1, 2015 by igorek24 Quote Link to comment https://forums.phpfreaks.com/topic/296574-newbie-same-row-from-db-printed-twice/#findComment-1512948 Share on other sites More sharing options...
igorek24 Posted June 1, 2015 Author Share Posted June 1, 2015 Figured it out. It was my query. Thanks everyone. Quote Link to comment https://forums.phpfreaks.com/topic/296574-newbie-same-row-from-db-printed-twice/#findComment-1512951 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.