f00sh Posted January 15, 2009 Share Posted January 15, 2009 Hey guys. this might be a little a stupid or abnormal... Basically I have a row in my Database that's called "Deck" Deck is different from user to user, in this case Deck is: Derp Deck 1 2 3 4 5 6 7 8 9 10 999 I've called for this and exploded it into Array $IDs Now, these numbers are all IDs to a different database with a Field "Name". I am trying to link the IDs in Deck to the Name field in the IDs database. I am having problems making this work: $tempNAME = $_SESSION['Username']; $Deck = explode("\n", $_SESSION['Pokemon1']); $Decktotal = count($Deck); $i = 1; while($i < $Decktotal) { $result = mysql_query("SELECT Name FROM CapturedCards WHERE id='$Deck[$i]' and Owner='$tempNAME'"); $row = mysql_fetch_array($result); $Cards[] = $row[0]; echo "<p>Testing: " . $row[0]; $i++; } This sort of works... except it is only returning the very last one (In this case 999). If I add another number like 3274 to the end of the list it will do that one instead, it will always do the last one. Any help is greatly appreciated, I hope I have made myself somewhat clear, I'm basically trying to use the IDs in the array $IDs[] to call for the name in the database that corresponds to the ID and the Username of the person logged in. Thanks a lot for any information Quote Link to comment Share on other sites More sharing options...
RussellReal Posted January 15, 2009 Share Posted January 15, 2009 this must be ABNORMALLY slow try the IN operator in mysql its specifically designed for arrays imploded by , ofcourse try this: <?php $tempNAME = $_SESSION['Username']; $Deck = str_replace("\n",",",trim($_SESSION['Pokemon1'])); $result = mysql_query("SELECT `Name`,`id` FROM `CapturedCards` WHERE `id` IN ('{$Deck}') AND `Owner` = '{$tempNAME}'"); while ($row = mysql_fetch_array($result)) { echo "<pre>TESTING\n".print_r($row,true)."</pre>"; } ?> 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.