Jump to content

[SOLVED] Array problem


DeanWhitehouse

Recommended Posts

I have data stored in my database as such (this is only one table, one field in the whole db)

array("left" => array("article_1" => array("id" => 1,"pos" => 2),"article_2" => array("id" => 2,"pos" => 1),"article_3" => array("id" => 3,"pos" => 3)))

 

when i try and extract it doing

<?php
$newspaper = mysql_fetch_assoc($newspaper);
?>
<h1>American Gangsters Newspaper - <?=Secure($newspaper['title'])?></h1>
<table align="center" width="100%">
	<tr>
		<td colspan="2" align="center" style="border-bottom:thin solid grey;">
			<h2>Issue Number: <?=number_format($newspaper['id'])?>, Published <?=ConvertTimeToWords($newspaper['time'])?></h2>
		</td>
	</tr>
	<tr>
		<td colspan="2" align="left" style="border-bottom:thin solid grey;">
			Editor <?=CreateUserLink($newspaper['editor_id']);?><br>
			Description:<br> <?=Secure($newspaper['desc'])?>
		</td>
	</tr>
	<?php
	$left = $newspaper['articles']['left'];
	$right = $newspaper['articles']['right'];
	?>
	<tr>
		<td align="left" width="50%" style="border-right:thin solid grey;">
			<?php print_r($newspaper['articles']); echo $left;?>
			<h3></h3>
			Article OneArticle OneArticle OneArticle OneArticle OneArticle OneArticle OneArticle OneArticle OneArticle One
			<hr>
			<h3>Article Title</h3>
			Article OneArticle OneArticle OneArticle OneArticle OneArticle OneArticle OneArticle OneArticle OneArticle One
		</td>
		<td align="left" width="50%">
			Article Two
		</td>
	</tr>
	<tr>
		<td colspan="2" align="left" style="border-top:thin solid grey;">
			<h2>Adverts</h2>
			<?=Secure($newspaper['advert'])?>
		</td>
	</tr>
</table>

I get an unexpected result, the print_r($newspaper['articles']); prints the array as expected but echo $left; prints the letter a

:s

 

Same if i try print_r($left);

 

Any ideas?

 

Thanks,

Blade

Link to comment
Share on other sites

array("left" => array("article_1" => array("id" => 1,"pos" => 2),"article_2" => array("id" => 2,"pos" => 1),"article_3" => array("id" => 3,"pos" => 3)))

 

Thats what print_r($newspaper['articles']);

prints

 

The data stored in the db is

array("articles" => array("left" => array("article_1" => array("id" => 1,"pos" => 2),"article_2" => array("id" => 2,"pos" => 1),"article_3" => array("id" => 3,"pos" => 3))),array("right" => array("")))

Link to comment
Share on other sites

array("left" => array("article_1" => array("id" => 1,"pos" => 2),"article_2" => array("id" => 2,"pos" => 1),"article_3" => array("id" => 3,"pos" => 3)))

 

Thats what print_r($newspaper['articles']);

prints

 

No, I don't think it is. That's not the format that print_r() uses when displaying it's output.

Link to comment
Share on other sites

I have tried using eval already it created a wierd error

 

Using your way it creates these errors

08:14 am:

Notice: Array to string conversion in /home/vheissu/public_html/paper.php on line 42

08:14 am:

Parse error: syntax error, unexpected $end, expecting '(' in /home/vheissu/public_html/paper.php(42) : eval()'d code on line 1

 

trying

	$left = eval($newspaper['articles']);
	$left = $left['left'];

I get

08:14 am:

Parse error: syntax error, unexpected $end, expecting '(' in /home/vheissu/public_html/paper.php(42) : eval()'d code on line 1

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.