Jump to content

Getting Multiple Data


Krux20

Recommended Posts

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

   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) . " " . ' ' . "



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

 }


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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.