[thelist] PHP - RegExp & Array problems

Beau Hartshorne beau at members.evolt.org
Tue Jun 25 11:51:01 CDT 2002


I'm sorry Lach -- I thought I might be able to help, but I'm no use
debugging unless I can run the code.

Try to echo the variables at different stages of the script. It will
help you find exactly where the problem is.

There's a little tidbit on this page that might help:

http://www.php.net/manual/en/language.types.array.php

phresno at concept-factory.com says:

to echo multidimensional arrays put the variable in {}'s

example:
<?php
for($i=0;$i<=2;$i++)
{
    for($j=0;$j<=2;$j++)
    {
        $array[$i][$j] = $i + $j;
        echo "Array[$i][$j]: $array[$i][$j]\n";
    }
}
?>

displays:
Array[0][0]: Array[0]
Array[0][1]: Array[1]
Array[0][2]: Array[2]
Array[1][0]: Array[0]
Array[1][1]: Array[1]
Array[1][2]: Array[2]
Array[2][0]: Array[0]
Array[2][1]: Array[1]
Array[2][2]: Array[2]

while the code:
<?php
for($i=0;$i<=2;$i++)
{
    for($j=0;$j<=2;$j++)
    {
        $array[$i][$j] = $i + $j;
        echo "Array[$i][$j]: {$array[$i][$j]}\n";
    }
}
?>

will properly display the values as such:
Array[0][0]: 0
Array[0][1]: 1
Array[0][2]: 2
Array[1][0]: 1
Array[1][1]: 2
Array[1][2]: 3
Array[2][0]: 2
Array[2][1]: 3
Array[2][2]: 4

Please let us know once you figure it out, and don't forget to change
your "n" to "\n", and the "t" to "\t"!

Cheers,

Beau

> stylearray.php:
>
> $i = 0;
> $styles = '';
> $db = mysql_connect($dbHost, $dbUsername, $dbPassword);
> mysql_select_db('luminosity',$db);
> $sql = 'SELECT styleTitle, styleName, styleMedia FROM
luminosityStyles';
> $result = mysql_query($sql, $db);
> while ($entry = mysql_fetch_array($result)) {
> 	$styles[$i]['title'] = $entry['styleTitle'];
> 	$styles[$i]['name'] = $entry['styleName'];
> 	$styles[$i]['media'] = $entry['styleMedia'];
> 	$i++;
> }
> return $styles;
>
> relevant part of .template
>
> $styles = '';
> $stylelist = include('stylearray.php');
> $prefstyle = $_COOKIE['style'];
> if (!$prefstyle) {
> 	$prefstyle = 'default';
> }
> for ($i=0; $i<count($stylelist); $i++) {
> 	if (($stylelist[$i]['title'] != $prefstyle) &&
> 	($stylelist[$i]['media']== 'screen')) {
> 		$styles .= "t".'<link rel="alternate stylesheet"
> href="/luminosity/style/'.$stylelist[$i]['name'].'.css"
> media="'.$stylelist[$i]['media'].'"
title="'.$stylelist[$i]['title'].'"
> type="text/css" />'."n";
> 	}
> 	else {
> 		$styles .= "t".'<link rel="stylesheet"
> href="/luminosity/style/'.$stylelist[$i]['name'].'.css"
> media="'.$stylelist[$i]['media'].'"
title="'.$stylelist[$i]['title'].'"
> type="text/css" />'."n";
> 	}
> }





More information about the thelist mailing list