Jump to content


Photo

Strange problem..


  • Please log in to reply
2 replies to this topic

#1 Jarin

Jarin
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 10 May 2006 - 11:56 AM

I'm having a very strange problem that I've never encountered before. It's rather simple actually, but I can't find any reason why it would do this.

So, I have a serialized array like this: a:1:{s:5:"night";s:1:"1";} which is stored in the variable $world['flags']. If I were to echo that variable, it prints out exactly as it should, a:1:{s:5:"night";s:1:"1";}

However, if I assign a variable like this:
$wflag = $world['flags'];
Then $wflag will return a NULL value. It doesn't store the information at all. Below is the entire portion of the script in question. And yes, 'flags' is a valid field in the result. Everything else in the query works as it should.

$worlds = $DB_site->query("SELECT * FROM vb3_heroadmin WHERE world='$worldid'");
$world = mysql_fetch_array($worlds);

$worldn = $world['name'];
$optionx = $world['xpmult'];
$optiong = $world['goldmult'];
$optioni = $world['itemrarity'];
$optiona = $world['aprarity'];
$wflag = $world['flags'];

Thanks for any help you might offer.

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 10 May 2006 - 01:52 PM

I'm going to guess that you need to unserialize it before transferring it to a PHP variable.

Info: PHP Manual


#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 10 May 2006 - 02:27 PM

Put some debuging code in:
<?php
$worlds = $DB_site->query("SELECT * FROM vb3_heroadmin WHERE world='$worldid'");
$world = mysql_fetch_assoc($worlds);  // changed from mysql_fetch_array to mysql_fetch_assoc
echo '<pre>' . print_r($world,true) . '</pre>'; // debug line -- check that you're getting what you think you're getting
$worldn = $world['name'];
$optionx = $world['xpmult'];
$optiong = $world['goldmult'];
$optioni = $world['itemrarity'];
$optiona = $world['aprarity'];
$wflag = $world['flags'];
echo '$wflag = ' . $wflag . '<br>'; // another debug line.
?>
You should be able to move the value to any variable without unserializing it.

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users