PDA

View Full Version : super newbie project, trying to use array attributes in a function but get error


silverglade
09-07-2009, 11:43 PM
hi, my teacher told me to use an array to control the look of a table. and im trying, but have no idea if this is valid code. i also get the error

Parse error: parse error, expecting `')'' in C:\wamp\www\lessons\table\table.php on line 46

please, any advice or help greatly appreciated. thank you. derek

here is the code

<?php

//table options multidimensional array

$table_options = array(
'color'=>array(
'color1'=> 'blue',
'color2'=> 'green',
'color3'=> 'red',
'color4'=> 'orange',
'color5'=> 'purple',
'color6'=> 'yellow'
),
'width'=>array(
'width1' => '20%',
'width2' => '50%',
'width3' => '70%',
'width4' => '90%',
'width5' => '100%'
),
'border'=>array(
'border1' => '0',
'border2' => '1'
),

'row_num'=>array(
'rows1'=> '1',
'rows2'=> '2',
'rows3'=> '3',
'rows4'=> '4',
'rows5'=> '5'
)
);




///setting and outputting the table functions

//declaring the array attributes as the function arguments.

function table_setter($table_options['color'][],$table_options['width'][],$table_options['border'][], $table_options['row_num'][]){

///youre altering the table dimensions with php!!!
$table .= "<table background-color=\"$table_options['color'][]\" width=\"$table_options['width'][]\" border=\"$table_options['border'][]\" >
<tr>
<td>header 1</td>
<td>header 2</td>
<td>header 3</td>
</tr>";



for($i=0;$i<$table_options['row_num'][];$i++){


$table .= "<tr>
<td>data</td>
<td>data</td>
<td>data</td>
</tr>";

}

$table .= "</table>";


return $table;

}


echo table_setter($table_options['color']['color1'],$table_options['width']['width3'],$table_options['border']['border2'], $table_options['row_num']['rows5']);



?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>

silverglade
09-08-2009, 12:29 AM
nevermind i think im ditching the assignment i dont think i have a good idea of what the assignment was supposed to do.

domedia
09-09-2009, 08:10 PM
Too bad, the error message was verbal and told you exactly what was wrong :-/

bee80
09-13-2009, 10:45 AM
looks good code, you do know what your doing so dont give up!! just post line lines 40 to 50 please