Krux20 Posted November 28, 2012 Share Posted November 28, 2012 Hi, For some reason I keep getting multiple data when I run the following code: $result = mysqli_query($con,'SELECT Bike.BikeCode,Bike.Manufacturer,Bike.Model,Bike.FrameMaterial,Bike.Description,Bike.Price, BikeImages.SourcePath, BikeImages.BikeCode FROM Bike,BikeImages WHERE Bike.BikeCode = BikeImages.BikeCode'); http://tinypic.com/r/vdiee1/6 Quote Link to comment https://forums.phpfreaks.com/topic/271312-getting-multiple-data/ Share on other sites More sharing options...
mrMarcus Posted November 28, 2012 Share Posted November 28, 2012 You have more code. Please post it. Quote Link to comment https://forums.phpfreaks.com/topic/271312-getting-multiple-data/#findComment-1395993 Share on other sites More sharing options...
Krux20 Posted November 28, 2012 Author Share Posted November 28, 2012 function products () { $con = mysqli_connect("localhost","root",""); mysqli_select_db($con,"bicycle"); if (!$con) { die('Could not connect: ' . mysql_error()); } $result = mysqli_query($con,'SELECT Bike.BikeCode,Bike.Manufacturer,Bike.Model,Bike.FrameMaterial,Bike.Description,Bike.Price, BikeImages.SourcePath, BikeImages.BikeCode FROM Bike,BikeImages WHERE Bike.BikeCode = BikeImages.BikeCode'); //$images = mysqli_query($con,'SELECT BikeImages.SourcePath,Bike.BikeCode FROM BikeImages,Bike WHERE BikeImages.BikeCode = Bike.BikeCode'); echo " "; while ($row = mysqli_fetch_array($result)) { echo "" . "" . "" ."" ."" . "" . "" . ""; } BikeCode Manufacturer Model FrameMaterial Description Price " . $row['BikeCode'] . " " . $row['Manufacturer'] . " " . $row['Model'] ." " .$row['FrameMaterial'] ." " . $row['Description'] . " " . number_format($row ['Price'], 2) . " " . ' ' . " Quote Link to comment https://forums.phpfreaks.com/topic/271312-getting-multiple-data/#findComment-1395995 Share on other sites More sharing options...
MDCode Posted November 28, 2012 Share Posted November 28, 2012 It's not going to help if you take information out of your page Quote Link to comment https://forums.phpfreaks.com/topic/271312-getting-multiple-data/#findComment-1395997 Share on other sites More sharing options...
Krux20 Posted November 28, 2012 Author Share Posted November 28, 2012 function products () { $con = mysqli_connect("localhost","root",""); mysqli_select_db($con,"bicycle"); if (!$con) { die('Could not connect: ' . mysql_error()); } $result = mysqli_query($con,'SELECT Bike.BikeCode,Bike.Manufacturer,Bike.Model,Bike.FrameMaterial,Bike.Description,Bike.Price, BikeImages.SourcePath, BikeImages.BikeCode FROM Bike,BikeImages WHERE Bike.BikeCode = BikeImages.BikeCode'); //$images = mysqli_query($con,'SELECT BikeImages.SourcePath,Bike.BikeCode FROM BikeImages,Bike WHERE BikeImages.BikeCode = Bike.BikeCode'); echo "<table border='1'> <tr> <th> BikeCode </th> <th> Manufacturer </th> <th> Model </th> <th> FrameMaterial </th> <th> Description </th> <th> Price </th> </tr>"; while ($row = mysqli_fetch_array($result)) { echo "<tr>" . "<td>" . $row['BikeCode'] . "</td>" . "<td>" . $row['Manufacturer'] . "</td>" ."<td>" . $row['Model'] ."</td>" ."<td>" .$row['FrameMaterial'] ."</td>" . "<td>" . $row['Description'] . "</td>" . "<td>" . number_format($row ['Price'], 2) . "<td>" . '<form action="cart.php?add='.$row['BikeCode'] .'" method="POST"><input type="submit" value="Add" name="add"> </form>' . "</td>" . "</tr>"; } Quote Link to comment https://forums.phpfreaks.com/topic/271312-getting-multiple-data/#findComment-1396005 Share on other sites More sharing options...
AyKay47 Posted November 28, 2012 Share Posted November 28, 2012 What results are you expecting? Also, use mysqli_error() instead of mysql_error() Quote Link to comment https://forums.phpfreaks.com/topic/271312-getting-multiple-data/#findComment-1396012 Share on other sites More sharing options...
Pikachu2000 Posted November 28, 2012 Share Posted November 28, 2012 What results are you expecting? Also, use mysqli_error() instead of mysql_error() mysqli_connect_error() would be the correct function to use where mysql_error() currently is in the code. Quote Link to comment https://forums.phpfreaks.com/topic/271312-getting-multiple-data/#findComment-1396014 Share on other sites More sharing options...
AyKay47 Posted November 28, 2012 Share Posted November 28, 2012 ya Quote Link to comment https://forums.phpfreaks.com/topic/271312-getting-multiple-data/#findComment-1396015 Share on other sites More sharing options...
mrMarcus Posted November 28, 2012 Share Posted November 28, 2012 (edited) Do you have multiple, identical records in your table? From the image you provided, it seems the last 2 records are not identical. Please check and be 100% certain your table does not contain duplicates. Edited November 28, 2012 by mrMarcus Quote Link to comment https://forums.phpfreaks.com/topic/271312-getting-multiple-data/#findComment-1396017 Share on other sites More sharing options...
Krux20 Posted November 28, 2012 Author Share Posted November 28, 2012 Hi, Yes, I do have duplicates data since there are two images for one product. So, the ID for the item is linked to the Images of the product. http://tinypic.com/r/33yqefl/6 Quote Link to comment https://forums.phpfreaks.com/topic/271312-getting-multiple-data/#findComment-1396033 Share on other sites More sharing options...
Barand Posted November 29, 2012 Share Posted November 29, 2012 Do you have more than one image for each bike (like 2 images where you are getting the bike data listed twice)? Quote Link to comment https://forums.phpfreaks.com/topic/271312-getting-multiple-data/#findComment-1396073 Share on other sites More sharing options...
Krux20 Posted November 29, 2012 Author Share Posted November 29, 2012 Example: SourcePath BikeCode "Images/IMAGE1.jpg" MAB2012-5 "Images/IMAGE2.jpg" MAB2012-5 Quote Link to comment https://forums.phpfreaks.com/topic/271312-getting-multiple-data/#findComment-1396191 Share on other sites More sharing options...
Barand Posted November 29, 2012 Share Posted November 29, 2012 (edited) That isn't "duplicate" data, that's the way joins work - matching data from one table is joined the matching data from the other, so bike data is joined to each image. Try SELECT DISTINCT ... and only select fields for the bike records - that's all you are listing Edited November 29, 2012 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/271312-getting-multiple-data/#findComment-1396199 Share on other sites More sharing options...
Krux20 Posted November 29, 2012 Author Share Posted November 29, 2012 (edited) Yes, but I have the BikeCode in the Bike table and I have the SourcePath in another table called BikeImages. How can I access get the sourcepath and the BikeCode from the two tables without repeating data. Edited November 29, 2012 by Krux20 Quote Link to comment https://forums.phpfreaks.com/topic/271312-getting-multiple-data/#findComment-1396209 Share on other sites More sharing options...
Barand Posted November 29, 2012 Share Posted November 29, 2012 You have to accept that is how it works and adjust your processing code. How you adjust depends on how you want to display. Quote Link to comment https://forums.phpfreaks.com/topic/271312-getting-multiple-data/#findComment-1396211 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.