Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

98 users online



parse error

parse error

Currently viewing this thread: 1 (0 members and 1 guests)


Page 1 out of 2
sapphire

sapphire

Neverside Newbie
Status: Offline!

parse error

hi i dont know whats wrong with my code, im a n00b. pls help me out.

PHP:

<?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

Hoagster

Hoagster

Neverside Newbie
Status: Offline!

Maybe this helps:

PHP:

<?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)

BigToach

BigToach

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!

johnzer

johnzer

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.

sapphire

sapphire

Neverside Newbie
Status: Offline!

thanks guys Smile Grin

sapphire

sapphire

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?

sapphire

sapphire

Neverside Newbie
Status: Offline!

i defined the variables as follows

PHP:

<?php

                $path
=array(6);
                
$data_t=array(6);

?>

and changed the print line to:

PHP:

<?php

                    
Print($data_t=array($i));

?>

however it returns the word "ARRAY" and not the value of name function, as it should to.

Hoagster

Hoagster

Neverside Newbie
Status: Offline!

It's because $data_t is an array.

you could use

PHP:

<?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:

<?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)

sapphire

sapphire

Neverside Newbie
Status: Offline!

where does $value come from? or doe sit start there. what is it equal to?

Hoagster

Hoagster

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)

Page 1 out of 2
Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0112 seconds.