Inferno_str1ke Posted September 26, 2006 Share Posted September 26, 2006 Ok, simple thing, I have the following lines:[CODE]$query="SELECT * FROM ".$L_sqlprefix."config";$result=mysql_query($query) OR die($query.'<br/>'.mysql_error());while ($line=mysql_fetch_array($result,MYSQL_ASSOC)){ $_[ $line['title'] ] = $line['value'];}[/CODE]What this does is take a title and value out of the database and stick it into an array. When printed ( print_r($_); ) the array should look like this:[CODE]Array ( [blogtitle] => 1.k.e.Net [thisurl] => http://127.0.0.1:85/ [feedurl] => rss.php [feedtype] => RSS 2.0 [install] => complete )[/CODE]When executing on my test server the code performs fine, but when I run it on my web server the array comes out as follows:[CODE]Array ( [blogtitle] => 1 [thisurl] => h[feedurl] => r[feedtype] => R[install] => c )[/CODE]Which is obviously useless to me. Now I'm stumped as to why it's behaving differently in different locations, and also stumped as to another way to get the info into an array.I've tried a a few different ways on the web server, all produce random and useless results:[CODE]array ($_);$query="SELECT * FROM config";$result=mysql_query($query) OR die($query.'<br/>'.mysql_error());while ($line=mysql_fetch_array($result,MYSQL_ASSOC)){ $_[$line['title']]=$line['value']; echo $line['title'].'<br/>'; echo $line['value'].'<br/>'; print_r($_); echo '<br/><br/>';}[/CODE]Result:[CODE]blogtitle1keNet1usr/local/apache/bin/httpdthisurlhttp://127.0.0.1:85/husr/local/apache/bin/httpdfeedtypeRSS 2.0Rusr/local/apache/bin/httpdperpage101usr/local/apache/bin/httpd[/CODE]There are more but I've cut it short and you get the point. Incidentally using:[CODE]$array=mysql_fetch_array($result,MYSQL_ASSOC);foreach ($array as $subarray){ echo $subarray.'<br/><br/>';}[/CODE]instead of the While loop gives me the result (not cut short):[CODE]1blogtitle1keNet0[/CODE] Quote Link to comment Share on other sites More sharing options...
craygo Posted September 26, 2006 Share Posted September 26, 2006 Try $_ = array(); rather than array($_)also you could try using mysql_fetch_assoc rather than mysql_fetch_array. I know they sort of mean the same thing but I have had different results using different functions.Ray Quote Link to comment Share on other sites More sharing options...
thepip3r Posted September 26, 2006 Share Posted September 26, 2006 change:$_[ $line['title'] ] = $line['value'];to$_[ $line ]['title'] = $line['value'];...if you're trying to make "title" in the 1st dimension of the $_[$line] array. Quote Link to comment Share on other sites More sharing options...
Inferno_str1ke Posted September 26, 2006 Author Share Posted September 26, 2006 No, title does not need to be an attribute of the array - each array item needs to be $_[' *option name here* '].I shall try defining the array differently. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 26, 2006 Share Posted September 26, 2006 try[code]<?php$query="SELECT * FROM ".$L_sqlprefix."config";$result=mysql_query($query) OR die($query.'<br/>'.mysql_error());$data = array();while ($line=mysql_fetch_array($result,MYSQL_ASSOC)){ $data[] = $line;}// view resultsecho '<pre>', print_r($data, true), '</pre>';?>[/code] Quote Link to comment Share on other sites More sharing options...
Inferno_str1ke Posted September 26, 2006 Author Share Posted September 26, 2006 I have found, thanks to that, that the error was that it just didn't like $_ as a name of an array. I changed it to $l and my old code worked too. Thanks for helping me see that. 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.