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? ??? Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/ 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 Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-374801 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 Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-374809 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 Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-374822 Share on other sites More sharing options...
Chevy Posted October 21, 2007 Author Share Posted October 21, 2007 Still didn't work Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-374832 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`"); Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-374839 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! Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-374842 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 Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-374860 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 Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-374863 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; } } Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-375054 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'" Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-375064 Share on other sites More sharing options...
Chevy Posted October 21, 2007 Author Share Posted October 21, 2007 Nope, still get nothing. Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-375077 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 Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-375081 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? Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-375086 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 Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-375088 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 Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-375093 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); Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-375108 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. Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-375110 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); Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-375123 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 Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-375130 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 Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-375137 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) Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-375146 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? Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-375155 Share on other sites More sharing options...
Chevy Posted October 22, 2007 Author Share Posted October 22, 2007 id in the trades table Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-375161 Share on other sites More sharing options...
Chevy Posted October 22, 2007 Author Share Posted October 22, 2007 any more suggestions? Link to comment https://forums.phpfreaks.com/topic/74207-display-1-row-for-each/#findComment-375345 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.