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

Link to comment
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 "<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
Share on other sites

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 by Barand
Link to comment
Share on other sites

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 by Krux20
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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