Jump to content


Photo

seeing double

php

  • Please log in to reply
2 replies to this topic

#1 dogguy2010

dogguy2010

    Newbie

  • New Members
  • Pip
  • 2 posts

Posted 11 July 2013 - 07:40 PM

Can some one please explain to me why the following code echoes the results twice?

 

<?php


    //includes:
    include('connections.php');
    include('my_functions.php');


    //select last record from coupoons table and set applicable variables
    $query = mysql_query("SELECT * FROM coupons ORDER BY coupon_id DESC LIMIT 1") or die(mysql_error());
        while($rows = mysql_fetch_array($query))
        {
            $coupon_id = $rows['coupon_id'];
            $barcode = $rows['barcode'];
            $company_prefix = $rows['company_prefix'];
            $family_code = $rows['primary_purch_family_code'];
echo 'coupon_id ', $coupon_id,'<br>','<br>';
        }     


$query1 = mysql_query("SELECT manufacturers.company_prefix, family_codes.family_code, brands.brand, manufacturers.mfg
FROM (manufacturers INNER JOIN brands ON manufacturers.`company_prefix` = brands.`company_prefix`) INNER JOIN family_codes ON brands.`brand_id` = family_codes.`brand_id`
WHERE (((manufacturers.company_prefix)=$company_prefix) AND ((family_codes.family_code)=$family_code))");
        while ($rows = mysql_fetch_array($query1))
        {
            $mfg = $rows['mfg'];
            $brand = $rows['brand'];
            $family_code = $rows['family_code'];
echo $mfg,$brand,$family_code,'<br>' ;            
        }
?>
 
The results that I want:
 
Keebler100 Calorie Right Bites390
Sunshine100 Calorie Right Bites390
 
The results I am getting:
 
Keebler100 Calorie Right Bites390
Sunshine100 Calorie Right Bites390
Keebler100 Calorie Right Bites390
Sunshine100 Calorie Right Bites390
 
I am new to this and am probably missing something very simple, but I can not figure it out.
Please help.


#2 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,576 posts
  • LocationBonita, FL

Posted 11 July 2013 - 08:04 PM

Probably your SELECT query is returning duplicates. We can't answer why to that without knowing more about each of the tables and the data contained within them. A quick fix might be to just change it from SELECT to SELECT DISTINCT
Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#3 web_craftsman

web_craftsman

    Advanced Member

  • Members
  • PipPipPip
  • 50 posts
  • LocationUkraine

Posted 11 July 2013 - 10:43 PM

Try to change your second INNER JOIN to LEFT JOIN






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com