scm22ri Posted October 1, 2012 Share Posted October 1, 2012 Hi Everyone, What I'm trying to accomplish is this, I want to display the vehicles every user is selling but for some reason I'm getting duplicate information. I think the answer to my question is the array_unique function but I'm having a hard time trying to figure out where the function should go? Any help would be appreciated, thanks! http://www.whatsmyowncarworth.com/for-sale/mysql/mysql-command.php <?php include_once "init.php"; echo "<table border='1'>"; echo "<tr> <th>User ID</th> <th>First Name</th> <th>Last Name</th> <th>Car Desc ID</th> <th>Price</th> <th>Mileage</th> <th>Transmission</th> <th>Color</th> <th>Year</th> <th>Make</th> <th>Model</th> </tr>"; $query = "SELECT users.user_id, users.firstname, users.lastname, prices.car_desc_id, prices.price, \n" . "\n" . "prices.mileage, prices.transmission, prices.color, car_desc.year, car_desc.make, car_desc.model\n" . "\n" . "FROM users, prices, car_desc\n" . "\n" . "WHERE prices.car_desc_id LIMIT 0, 30 "; // $result = array_unique($query); // $query = "SELECT * FROM car_desc ORDER BY id ASC"; $thedude = mysql_query($query) or die(mysql_error()); // $result = array_unique($thedude); while ($row = mysql_fetch_array($thedude)) { $user_id = ($row['user_id']); $firstname = ($row['firstname']); $lastname = ($row['lastname']); $car_desc_id = ($row['car_desc_id']); $price = ($row['price']); $mileage = ($row['mileage']); $transmission = ($row['transmission']); $color = ($row['color']); $year = ($row['year']); $make = ($row['make']); $model = ($row['model']); // keeps getting the next row until there are no more to get /*while ($row = mysql_fetch_array($result))*/ { // Print out the contents of each row into a table ?> <tr> <td><?php echo "$user_id"; ?></td> <td><?php echo "$firstname"; ?></td> <td><?php echo "$lastname"; ?></td> <td><?php echo "$car_desc_id"; ?></td> <td><?php echo "$price"; ?></td> <td><?php echo "$mileage"; ?></td> <td><?php echo "$transmission"; ?></td> <td><?php echo "$color"; ?></td> <td><?php echo "$year"; ?></td> <td><?php echo "$make"; ?></td> <td><?php echo "$model"; ?></td> </tr> <?php } /*echo "</table>";*/ } /*else*/ { /*trigger_error(mysql_error()); // for development only; remove when in production*/ } ?> Quote Link to comment https://forums.phpfreaks.com/topic/268968-array_unique-question-regarding-mysql-query/ Share on other sites More sharing options...
Barand Posted October 1, 2012 Share Posted October 1, 2012 Not surprising you get too much data. You are joining 3 tables without any join criteria therefore you get every row in each table joined with every row in the other tables. You need to specify joins eg FROM a INNER JOIN b ON a.key = b.key Quote Link to comment https://forums.phpfreaks.com/topic/268968-array_unique-question-regarding-mysql-query/#findComment-1382068 Share on other sites More sharing options...
ManiacDan Posted October 1, 2012 Share Posted October 1, 2012 MySQL and PHP are separate languages. If your MySQL programs (queries) are wrong, fix them, don't try to have PHP automatically correct the wrong output from MySQL. JOIN conditions are your answer. Quote Link to comment https://forums.phpfreaks.com/topic/268968-array_unique-question-regarding-mysql-query/#findComment-1382080 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.