Jump to content

Archived

This topic is now archived and is closed to further replies.

Jarin

Strange problem..

Recommended Posts

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.

Share this post


Link to post
Share on other sites
I'm going to guess that you need to unserialize it before transferring it to a PHP variable.

Share this post


Link to post
Share on other sites
Put some debuging code in:
[code]<?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.
?>[/code]
You should be able to move the value to any variable without unserializing it.

Ken

Share this post


Link to post
Share on other sites

×

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.