Jump to content

igorek24

Members
  • Posts

    10
  • Joined

  • Last visited

Posts posted by igorek24

  1.  

    See if this does the trick for you

    SELECT DISTINCT username, vehicles.veh_id, year, veh_make.make_title, veh_model.model_title, veh_registration.policy_num, cylinder_count, eng_hp, trans, int_color, ext_color, fuel_tank, date_format(veh_services.date,'%m/%d/%Y') as servdate
    FROM vehicles
    LEFT JOIN (veh_make, veh_model) ON (vehicles.model_id = veh_model.model_id) AND (vehicles.make_id = veh_make.make_id)
    LEFT JOIN (veh_registration) ON (vehicles.reg_id = veh_registration.reg_id)
    JOIN (users) on (vehicles.user_id = users.user_id)
    left JOIN (veh_services) ON (veh_services.veh_id = vehicles.veh_id)
    WHERE users.user_id = 2 
    GROUP BY (veh_id )

    That seems to work just like I want it. Thank you so much

  2. Hi all,

    can someone help me to limit output from SELECT query to unique row only on php page. When I join a veh_services table to vehicles, and there are multiple rows in veh_services with the same veh_id, it outputs multiple rows with the same veh_id.

     

    My query:

    SELECT username, vehicles.veh_id, year, veh_make.make_title, veh_model.model_title, veh_registration.policy_num, cylinder_count, eng_hp, trans, int_color, ext_color, fuel_tank, date_format(veh_services.date,'%m/%d/%Y') as servdate
    FROM vehicles
    LEFT JOIN (veh_make, veh_model) ON (vehicles.model_id = veh_model.model_id) AND (vehicles.make_id = veh_make.make_id)
    LEFT JOIN (veh_registration) ON (vehicles.reg_id = veh_registration.reg_id)
    JOIN (users) on (vehicles.user_id = users.user_id)
    left JOIN (veh_services) ON (veh_services.veh_id = vehicles.veh_id)
    WHERE users.user_id = 2 
    

    I've created a temp user in my phpMyAdmin:

    User: help

    Pass: Password01

     

    Here is my DB typology

    2015-06-09_20-54-33.png

     

    and here is my source code

    and the webpage

  3. 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)
  4.  

    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\">";
    

    phpmyvst.png

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.