Canadiengland Posted March 18, 2007 Share Posted March 18, 2007 for the following script, how would i make it display multiple unequipped items but not display the same ones more than once? //unequipped items ------------------------------------------------------------------- $uneq="SELECT * from km_items where owner='$player' and status='u'"; $uneq2=mysql_query($uneq) or die("Could not get user stats"); $uneq3=mysql_fetch_array($uneq2); if (!empty ($uneq3[id])) { echo "<a href=equip.php?itemid=$uneq3[id]><img src='$uneq3[itempic]'"; } else { } thanks! Quote Link to comment https://forums.phpfreaks.com/topic/43219-solved-constant-checking/ Share on other sites More sharing options...
JasonLewis Posted March 18, 2007 Share Posted March 18, 2007 change this: $uneq="SELECT * from km_items where owner='$player' and status='u'"; to this, i think: $uneq="SELECT DISTINCT(*) from km_items where owner='$player' and status='u'"; Quote Link to comment https://forums.phpfreaks.com/topic/43219-solved-constant-checking/#findComment-209827 Share on other sites More sharing options...
Canadiengland Posted March 18, 2007 Author Share Posted March 18, 2007 hmm.. didnt work Quote Link to comment https://forums.phpfreaks.com/topic/43219-solved-constant-checking/#findComment-209833 Share on other sites More sharing options...
JasonLewis Posted March 18, 2007 Share Posted March 18, 2007 oh wait, sorry you dont have a while-loop. try this then. //unequipped items ------------------------------------------------------------------- $uneq="SELECT DISTINCT(*) from `km_items` where `owner`='$player' and `status`='u'"; $uneq2=mysql_query($uneq) or die("Could not get user stats"); $shown_items = ""; //this is just another checker, incase my mysql is gay. while($uneq3=mysql_fetch_array($uneq2)){ if (!empty($uneq3['id']) && !in_array({$uneq3['itempic']}, $shown_items)){ echo "<a href='equip.php?itemid={$uneq3['id']}'><img src='{$uneq3['itempic']}'></a><br>"; $shown_items[] = $uneq3['itempic']; } } i hope i did it right that time. Quote Link to comment https://forums.phpfreaks.com/topic/43219-solved-constant-checking/#findComment-209835 Share on other sites More sharing options...
Canadiengland Posted March 18, 2007 Author Share Posted March 18, 2007 still doesnt work... i think its cause im using an older version of php or mysql or something.. using whatever comes with wampserver.. but its getting late thanks for trying, ill mess with it more tomorrow. Quote Link to comment https://forums.phpfreaks.com/topic/43219-solved-constant-checking/#findComment-209838 Share on other sites More sharing options...
JasonLewis Posted March 18, 2007 Share Posted March 18, 2007 what is the exact problem now? not showing all results or showing the same result more then once or are there errors being produced? Quote Link to comment https://forums.phpfreaks.com/topic/43219-solved-constant-checking/#findComment-209839 Share on other sites More sharing options...
Canadiengland Posted March 19, 2007 Author Share Posted March 19, 2007 //unequipped items ------------------------------------------------------------------- $uneq="SELECT DISTINCT * from km_items where owner='$player' and status='u'"; $uneq2=mysql_query($uneq) or die("Could not get user stats"); $uneq3=mysql_fetch_array($uneq2); $shown_items = ""; //this is just another checker, incase my mysql is gay. while($uneq3=mysql_fetch_array($uneq2)) { if (!empty($uneq3['id']) && !in_array($uneq3['itempic'])) { echo "<a href=equip.php?itemid=$uneq3[id]><img src='$uneq3[itempic]'<br>"; $shown_items[] = $uneq3['itempic']; } } print "</table><br><br>"; } } this code gives me the effect but it also says (on the page) Warning: Wrong parameter count for in_array() in C:\wamp\www\killmonster\index.php on line 242 any ideas? 242 is if (!empty($uneq3['id']) && !in_array($uneq3['itempic'])) Quote Link to comment https://forums.phpfreaks.com/topic/43219-solved-constant-checking/#findComment-210430 Share on other sites More sharing options...
Canadiengland Posted March 19, 2007 Author Share Posted March 19, 2007 buuuuuuuuuuuuuump Quote Link to comment https://forums.phpfreaks.com/topic/43219-solved-constant-checking/#findComment-210684 Share on other sites More sharing options...
per1os Posted March 19, 2007 Share Posted March 19, 2007 Just a note on the DISTINCT modifier, it generally does not work on * it needs to be a specific column, because doing a distinct on * makes it so every single column must match to not display it. IE: SELECT DISTINCT(lname), userid, pass ... would work like it should. On that note: http://us2.php.net/manual/en/function.in-array.php !in_array($uneq3['itempic']) ---- What are you checking for here? You need at least 2 parameters, an array and a needle. //unequipped items ------------------------------------------------------------------- $uneq="SELECT DISTINCT * from km_items where owner='$player' and status='u'"; $uneq2=mysql_query($uneq) or die("Could not get user stats"); $uneq3=mysql_fetch_array($uneq2); $shown_items = array(); while($uneq3=mysql_fetch_array($uneq2)) { if (!empty($uneq3['id']) && !in_array($uneq3['itempic'], $shown_items)) { echo "<a href=equip.php?itemid=$uneq3[id]><img src='$uneq3[itempic]' "; $shown_items[] = $uneq3['itempic']; } } print "</table> "; } } See if that works. Quote Link to comment https://forums.phpfreaks.com/topic/43219-solved-constant-checking/#findComment-210693 Share on other sites More sharing options...
Canadiengland Posted March 19, 2007 Author Share Posted March 19, 2007 wow that worked - thanks for helping AND explaining what you did, so i won't make future errors now! Quote Link to comment https://forums.phpfreaks.com/topic/43219-solved-constant-checking/#findComment-210701 Share on other sites More sharing options...
Canadiengland Posted March 19, 2007 Author Share Posted March 19, 2007 may have spoke too soon - that displays a max of 2 seperate pics and both pics are linked to the same url... hmm Quote Link to comment https://forums.phpfreaks.com/topic/43219-solved-constant-checking/#findComment-210703 Share on other sites More sharing options...
per1os Posted March 19, 2007 Share Posted March 19, 2007 <?php //unequipped items ------------------------------------------------------------------- $uneq="SELECT * from km_items where owner='$player' and status='u'"; $uneq2=mysql_query($uneq) or die("Could not get user stats"); //$uneq3=mysql_fetch_array($uneq2); -- I do not know why this was there? $shown_items = array(); while($uneq3=mysql_fetch_array($uneq2)) { if (!empty($uneq3['id']) && !in_array($uneq3['itempic'], $shown_items)) { echo "<a href=equip.php?itemid=$uneq3[id]><img src='$uneq3[itempic]' "; $shown_items[] = $uneq3['itempic']; } } print "</table> "; } } ?> If you can give me a database structure, that can help, because chances are the problem is in the query. Quote Link to comment https://forums.phpfreaks.com/topic/43219-solved-constant-checking/#findComment-210713 Share on other sites More sharing options...
Canadiengland Posted March 19, 2007 Author Share Posted March 19, 2007 database structure of km_items is name power type expperturn rageperturn itempic owner id status cost rarity raritymax itemfind Quote Link to comment https://forums.phpfreaks.com/topic/43219-solved-constant-checking/#findComment-210773 Share on other sites More sharing options...
Canadiengland Posted March 19, 2007 Author Share Posted March 19, 2007 well i kinda fixed it... the way you put it up there made it so that each item would be displayed according to pic... but i wanted it to be each item.. so i changed !in_array($uneq3['itempic'], $shown_items)) to !in_array($uneq3['id], $shown_items)) but ive still got the problem of each pic has the same url when they are 2 different ids Quote Link to comment https://forums.phpfreaks.com/topic/43219-solved-constant-checking/#findComment-210774 Share on other sites More sharing options...
Canadiengland Posted March 19, 2007 Author Share Posted March 19, 2007 SOLVED! added a <td> after each echo and that solved it. thanks for all the help project and frost! Quote Link to comment https://forums.phpfreaks.com/topic/43219-solved-constant-checking/#findComment-210780 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.