
October 9th, 2005
12:49 AM
Neverside Newbie
Status: Offline!
parse error
hi i dont know whats wrong with my code, im a n00b. pls help me out.
<?php
$numberoftimings=6;
for($i=1; $i<=$numberoftimings; $i++) {
function name(i) {//LINE 121
switch(i) {
case 1: return 'fajr'; break;
case 2: return 'sunrise'; break;
case 3: return 'dhuhr'; break;
case 4: return 'asr'; break;
case 5: return 'maghrib'; break;
case 6: return 'isha'; break;
}
}
$path(i)=('namaz/time_data/' . $country1 . '/' . $city1 . '/' . $monthf . '/' . $dayf . '/' . name(i) . '.txt');
if(file_exists($path(i)) {
$data_t(i)=file_get_contents($path(i));
}
else {
$data_t(i)=('<span class="style111">ERROR</span><br><img src="error_small.jpg">');
}
}
Print($data_t(1));
?>
i get this error on IIS:
Parse error: parse error, expecting `')'' in C:\Maktab-e-Rasool\V2\ttable.php on line 121

October 9th, 2005
01:44 AM
Neverside Newbie
Status: Offline!
Maybe this helps:
<?php
$numberoftimings=6;
for($i=1; $i<=$numberoftimings; $i++){
$path[$i]=('namaz/time_data/' . $country1 . '/' . $city1 . '/' . $monthf . '/' . $dayf . '/' . name($i) . '.txt');
if(file_exists($path[$i])){
$data_t[$i]=file_get_contents($path[$i]);
}else{
$data_t[$i]=('<span class="style111">ERROR</span><br><img src="error_small.jpg">');
}
}
function name($i) {
switch($i){
case 1: return 'fajr'; break;
case 2: return 'sunrise'; break;
case 3: return 'dhuhr'; break;
case 4: return 'asr'; break;
case 5: return 'maghrib'; break;
case 6: return 'isha'; break;
}
}
Print($data_t);
?>
Last edited by Hoagster, October 9th, 2005 01:45 AM (Edited 1 times)

October 9th, 2005
06:52 AM
Neversidian
Status: Offline!
just an explaation of what went wrong.
In PHP calling on array elements uses brakets [] not parenthesis ()
___________________
Neverside Development Director
PHP Snippets
BigToach.com - IT WORKS, TOACHY!

October 9th, 2005
11:23 AM
Neverside Newbie
Status: Offline!
To add to BigToach's reply, you also left out $ infront of your variable i in this case, and it also isn't a good idea to define a function inside a loop.

October 9th, 2005
01:59 PM
Neverside Newbie
Status: Offline!
i used that code, and the Print command doesnt print $data_t, it prints the word "ARRAY"
is this because i have not defined the $data_t variable as an array? if so, how do i do that?

October 9th, 2005
02:11 PM
Neverside Newbie
Status: Offline!
i defined the variables as follows
<?php
$path=array(6);
$data_t=array(6);
?>
and changed the print line to:
<?php
Print($data_t=array($i));
?>
however it returns the word "ARRAY" and not the value of name function, as it should to.

October 9th, 2005
02:32 PM
Neverside Newbie
Status: Offline!
It's because $data_t is an array.
you could use
<?php
print_r($data_t);
?>
to see what is in the array.
But you could also define $data_t as an array in the beginning and print it with an foreach-loop at the end.
<?php
$numberoftimings=6;
$path_t = array();
for($i=1; $i<=$numberoftimings; $i++){
//....
}
function name($i) {
//...
}
foreach ($path_t as $value){
echo $value;
}
?>
Last edited by Hoagster, October 9th, 2005 02:34 PM (Edited 2 times)

October 9th, 2005
02:39 PM
Neverside Newbie
Status: Offline!
where does $value come from? or doe sit start there. what is it equal to?

October 9th, 2005
02:54 PM
Neverside Newbie
Status: Offline!
$value is equal to the content of the array while the foreach function loops through it.
for reference: http://www.php.net/manual/en/control-structures.foreach.php
Last edited by Hoagster, October 9th, 2005 02:57 PM (Edited 2 times)