Jump to content

Looping Explode Array to Gather Data and Applying Data to new Array


f00sh

Recommended Posts

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

Link to comment
Share on other sites

this must be ABNORMALLY slow :P

 

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>";
}
?>

Link to comment
Share on other sites

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.