Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/43219-solved-constant-checking/
Share on other sites

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.

//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']))

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.

<?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.

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

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.