Jump to content

Display 1 Row for each?


Chevy

Recommended Posts

if ($act == "search"){

        $uitem_select = mysql_query("SELECT * FROM `useritems` WHERE `itemid`='$itemiid' AND `location`='Gone'");

            if (mysql_num_rows($uitem_select) == "0"){
               error("No Swaps!", "There are no swaps currently available for that item!", "trades.php");
            }
        else {

      echo '<table id="table1" cellspacing="1" width="530"><tr>
<td id="td1" align="center"><b>Search The Swap Center</b></td>
</tr><tr>
<td align="center">Select a lot from below to view it!<br><br>';


         while ($searchitem = mysql_fetch_array($uitem_select)){
                  
                $traderarray = mysql_fetch_array(mysql_query("SELECT * FROM `trades` WHERE `item1`='$searchitem' OR `item2`='$searchitem' OR `item3`='$searchitem' OR `item4`='$searchitem' OR `item5`='$searchitem' OR `item6`='$searchitem'"));

                 echo '<a href="trades.php?type='.$traderarray['owner'].'"><b>Lot #'.$traderarray['id'].'</b></a> owned by <a href="profile.php?user='.$traderarray['owner'].'"><b>'.$traderarray['owner'].'</b>
</a><br>';

         }

      echo '<br><br><a href="trades.php">Back To Swap Center</a></td></tr></table>';

   include("footer.php");
   die;
           }
   
}

 

Okay basically, this is what it is displaying:

 

Lot #7 owned by Chevy

Lot #7 owned by Chevy

Lot #7 owned by Chevy

Lot #7 owned by Chevy

Lot #7 owned by Chevy

 

That is because the trade has 5 items all the same...how do I make it so if the lot # has more than one item of the same, it does not post?

 

Say I have 3 lots with the same item and 1 has 3 of that item...

 

Right not it would be:

 

 

Lot #1

Lot #1

Lot #1

Lot #2

Lot #3

 

I just want it to be:

 

 

Lot #1

Lot #2

Lot #3

 

Any ideas?  ???

Link to comment
Share on other sites

Now I am getting this:

 

Lot # owned by

 

This is my script:

 

if ($act == "search"){

         $uitem_select = mysql_query("SELECT * FROM `useritems` WHERE `itemid`='$itemiid' AND `location`='Gone' GROUP BY `itemid`") or die(mysql_error());

            if (mysql_num_rows($uitem_select) == "0"){
               error("No Swaps!", "There are no swaps currently available for that item!", "trades.php");
            }
        else {

      echo '<table id="table1" cellspacing="1" width="530"><tr>
<td id="td1" align="center"><b>Search The Swap Center</b></td>
</tr><tr>
<td align="center">Select a lot from below to view it!<br><br>';


         while ($searchitem = mysql_fetch_array($uitem_select)){
                  
                $trader = mysql_query("SELECT * FROM `trades` WHERE `item1`='{$searchitem['id']}' OR `item2`='{$searchitem['id']}' OR `item3`='{$searchitem['id']}' OR `item4`='{$searchitem['id']}' OR `item5`='{$searchitem['id']}' OR `item6`='{$searchitem['id']}'");
                $tradebarray = mysql_fetch_array($trader);

            
                 echo '<a href="trades.php?type='.$tradebarray['owner'].'"><b>Lot #'.$tradebarray['id'].'</b></a> owned by <a href="profile.php?user='.$tradebarray['owner'].'"><b>'.$tradebarray['owner'].'</b>
</a><br>';
           

         }

      echo '<br><a href="trades.php">Back To Swap Center</a></td></tr></table>';

   include("footer.php");
   die;
           }
   
}

Link to comment
Share on other sites

Did I use the wrong query?

 

SELECT DISTINCT id, owner FROM `trades` WHERE `item1`='{$searchitem['id']}' OR `item2`='{$searchitem['id']}' OR `item3`='{$searchitem['id']}' OR `item4`='{$searchitem['id']}' OR `item5`='{$searchitem['id']}' OR `item6`='{$searchitem['id']}'

 

The important bit is the DISTINCT keyword

 

PS that table needs normalizing

Link to comment
Share on other sites

This almost works,

 

                $trader = mysql_query("SELECT * FROM `trades` WHERE `item1`='{$searchitem['id']}' OR `item2`='{$searchitem['id']}' OR `item3`='{$searchitem['id']}' OR `item4`='{$searchitem['id']}' OR `item5`='{$searchitem['id']}' OR `item6`='{$searchitem['id']}' GROUP BY `item1`,`item2`,`item3`,`item4`,`item5`,`item6`");
                $tradebarray = mysql_fetch_array($trader);

 

But now I still get a lot of the same ID's like:

 

Lot #8 owned by Chevy

Lot #9 owned by Test

Lot #8 owned by Chevy

Lot #8 owned by Chevy

Lot #8 owned by Chevy

Lot #8 owned by Chevy

Lot #8 owned by Chevy

Lot #9 owned by Test

Link to comment
Share on other sites

try DISTINCT?

 

$trader = mysql_query("SELECT DISTINCT * FROM `trades` WHERE `item1`='{$searchitem['id']}' OR `item2`='{$searchitem['id']}' OR `item3`='{$searchitem['id']}' OR `item4`='{$searchitem['id']}' OR `item5`='{$searchitem['id']}' OR `item6`='{$searchitem['id']}' GROUP BY `item1`,`item2`,`item3`,`item4`,`item5`,`item6`");
                $tradebarray = mysql_fetch_array($trader);

Link to comment
Share on other sites

try something like this

trader = mysql_query("SELECT DISTINCT (item1), item2 FROM `trades` WHERE `item1`='{$searchitem['id']}' OR `item2`='{$searchitem['id']}' OR `item3`='{$searchitem['id']}' OR `item4`='{$searchitem['id']}' OR `item5`='{$searchitem['id']}' OR `item6`='{$searchitem['id']}' ");

                $tradebarray = mysql_fetch_array($trader);

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.