Jump to content

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

 }


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.

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 by mrMarcus

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