Chevy Posted October 21, 2007 Share Posted October 21, 2007 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? ??? Quote Link to comment Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 Change your SQL query to this $uitem_select = mysql_query("SELECT * FROM `useritems` WHERE `itemid`='$itemiid' AND `location`='Gone' GROUP BY {$itemid} ORDER BY {$itemid} ASC"); try that Quote Link to comment Share on other sites More sharing options...
Chevy Posted October 21, 2007 Author Share Posted October 21, 2007 This is what I get: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/chevy/public_html/trades/search.php on line 18 Quote Link to comment Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 $uitem_select = mysql_query("SELECT * FROM `useritems` WHERE `itemid`= '".$itemiid."' AND `location`= 'Gone' GROUP BY {$itemid}"); Well try that and if not then I dont know Quote Link to comment Share on other sites More sharing options...
Chevy Posted October 21, 2007 Author Share Posted October 21, 2007 Still didn't work Quote Link to comment Share on other sites More sharing options...
MadTechie Posted October 21, 2007 Share Posted October 21, 2007 $uitem_select = mysql_query("SELECT * FROM `useritems` WHERE `itemid`='$itemiid' AND `location`='Gone' GROUP BY `itemid`"); Quote Link to comment Share on other sites More sharing options...
Chevy Posted October 21, 2007 Author Share Posted October 21, 2007 Thanks a lot! I new it was that, I did the mysql_error and it told me...never new of the group function, thanks again! Quote Link to comment Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 $uitem_select = mysql_query("SELECT * FROM `useritems` WHERE `itemid`='$itemiid' AND `location`='Gone' GROUP BY `itemid`"); dadgum.. i was trying yo group it by a variable.. my bad Quote Link to comment Share on other sites More sharing options...
MadTechie Posted October 21, 2007 Share Posted October 21, 2007 lol, when i looked that that i thought.. That should of worked' date=' then created my one and only then spotted the differents[/quote'].. ahh well, thats what we get for working on a Sunday.. lol Quote Link to comment Share on other sites More sharing options...
Chevy Posted October 21, 2007 Author Share Posted October 21, 2007 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; } } Quote Link to comment Share on other sites More sharing options...
Barand Posted October 21, 2007 Share Posted October 21, 2007 SELECT DISTINCT itemid, owner FROM `useritems` WHERE `itemid`='$itemiid' AND `location`='Gone'" Quote Link to comment Share on other sites More sharing options...
Chevy Posted October 21, 2007 Author Share Posted October 21, 2007 Nope, still get nothing. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 21, 2007 Share Posted October 21, 2007 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 Quote Link to comment Share on other sites More sharing options...
Chevy Posted October 21, 2007 Author Share Posted October 21, 2007 Yea, it still did not work, what do you mean normalizing? Quote Link to comment Share on other sites More sharing options...
Barand Posted October 21, 2007 Share Posted October 21, 2007 http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html Quote Link to comment Share on other sites More sharing options...
Chevy Posted October 21, 2007 Author Share Posted October 21, 2007 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 Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 22, 2007 Share Posted October 22, 2007 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); Quote Link to comment Share on other sites More sharing options...
Chevy Posted October 22, 2007 Author Share Posted October 22, 2007 I have tried this as I said Still does not work. Quote Link to comment Share on other sites More sharing options...
teng84 Posted October 22, 2007 Share Posted October 22, 2007 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); Quote Link to comment Share on other sites More sharing options...
Chevy Posted October 22, 2007 Author Share Posted October 22, 2007 That also does not work I wonder why this is so hard haha Quote Link to comment Share on other sites More sharing options...
teng84 Posted October 22, 2007 Share Posted October 22, 2007 thats not hard and thats not php ok post your table structure and maybe few more explanation Quote Link to comment Share on other sites More sharing options...
Chevy Posted October 22, 2007 Author Share Posted October 22, 2007 pretty much all that is in the script is the table structure (all INT for items) Quote Link to comment Share on other sites More sharing options...
teng84 Posted October 22, 2007 Share Posted October 22, 2007 what is the field name of your lot number? Quote Link to comment Share on other sites More sharing options...
Chevy Posted October 22, 2007 Author Share Posted October 22, 2007 id in the trades table Quote Link to comment Share on other sites More sharing options...
Chevy Posted October 22, 2007 Author Share Posted October 22, 2007 any more suggestions? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.