[thelist] PHP / javascript arrays problem

Douglas Livingstone Evolt at neuance.net
Fri Apr 16 05:57:02 CDT 2004


I only see two differences:

	-	the one which doesn't work has a double space after the = sign, while 
the one which works only as one space
	-	the one which works has a lowercase 'xsara', the one which doesn't has 
an uppercase 'Xsara'

I'd be surprised if that made a diffrenece though. Check you MIME types.

Douglas

On Fri, 16 Apr 2004 11:40:46 -0400, David Horn 
<davidhorn at ticktockdesign.com> wrote:

> Hi all,
>
> First time post to this list, so apologies if I'm a little longwinded!
>
> I'm having problems creating javascript arrays from PHP.  I'm pretty  
> new to both concepts, so please bear with me.
>
> The PHP I'm using to generate the js looks like this:
>
> <?php
> $db = mysql_pconnect("localhost", "*****", "*****");
> mysql_select_db('carsite');
> $query1 = "SELECT modelName, makeID FROM makes GROUP BY makeID";
> $result=mysql_query($query1);
> echo "varStockModels = new Array(); \n";
> echo "varStockModels[0] = new Array('');\n";
>
> while ( $models=mysql_fetch_assoc($result) )
> 	{
> 	 echo "varStockModels[";
> 	 echo $models['makeID'];
> 	 echo "] =  new Array('','$models[modelName]'); \n";
> 	 }
> 	
> ?>
>
> this generates the following array quite satisfactorily:
>
> <script language="JavaScript">
> varStockModels = new Array();
> varStockModels[0] = new Array('');
> varStockModels[1] =  new Array('','Xsara');
> varStockModels[2] =  new Array('','Focus');
> varStockModels[3] =  new Array('','MX5');
> varStockModels[4] =  new Array('','midget');
> varStockModels[5] =  new Array('','Clio');
> varStockModels[6] =  new Array('','Octavia');
> varStockModels[7] =  new Array('','SD40');
> varStockModels[8] =  new Array('','XR20');
> </script>
>
> However, this array only seems to work on Windows browsers, and not on  
> Mac IE / Safari / Opera.  When I hard code the array onto a page, it  
> works satisfactorily in all browsers - which has really got me puzzled.
>
> If anyone there can help me out with why, I'd really appreciate it.   
> I've posted working (or not working) examples of this occurrence at the  
> following pages:
>
> http://www.ticktockdesign.com/cars/doesnotwork.php
> http://www.ticktockdesign.com/cars/doeswork.php
>
> I suspect the problem relies with my ham-fisted javascript at the top  
> of each page, but I'm really not sure.
>
> IF i get this cracked ... my next question is going to be how do I  
> expand the PHP above to accommodate situations where there is more than  
> one model per 'makeID', but one thing at a time I guess!
>
> Anyway, I hope this is the right group to ask!  Many thanks in advance  
> for your help,
>
> David
>
> ------------------------------------------------------------------------ 
> ----
> David Horn
> Creative Director
> www.TickTockDesign.com
> Design.  On Time.
> t. +44 (0) 795 876 9196
> f. +44 (0) 870 429 2747--
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !



-- 
Douglas Livingstone


More information about the thelist mailing list