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 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. 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) . " " . ' ' . " 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 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>"; } 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() 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. 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 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 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. 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 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)? 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 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 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 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 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. 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. Link to comment https://forums.phpfreaks.com/topic/271312-getting-multiple-data/#findComment-1396211 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.