...

View Full Version : including file ??, please help



mjs
01-22-2010, 04:18 AM
I am new to php without any knowledge and degree or course class so
I do apologize for asking this stupid question but I am wondering if you can help me..

i want insert file $cat1 or $cat2 to in page.php... the code i was create e.g.


<? //config.php
$cat_all = ($cat2 or $cat1);
$cat1 = "cat.php" ;
$cat2 = "../back-up/cat.php"; //default anyway
if(file_exists($cat1)){
require_once $cat1;
}else{
require_once $cat2;
}
?>

<? //page.php
require "config.php";
function ShowIndexProd($number){
$ar = file($cat_all); // <------- input here //
$sizear = count($ar)-$number;
$data = explode("#",$ar[$sizear]);
echo "
<td class='BoxIndex' width='30%'><a href='prod_show.php?id=$sizear'><IMG SRC='img/$data[5]' width=150 border=0></a> <BR /><BR />
<B><FONT COLOR='red'> $data[2] </FONT></B> <BR />
<B>Price:</B>$rp $data[3] $usd<BR />
<a href='prod_show.php?id=$sizear'><b><FONT COLOR='#FF6600'> more details... </FONT></b></a>
</td>";
}

but the result: file $cat1 or $cat2 printed to html page, that i want them as file configuration.. any help would much appreciate and thank you

masterofollies
01-22-2010, 05:27 AM
is config.php and page.php two different files and you posted them together?

mjs
01-22-2010, 09:28 AM
the config.php and page.php are two different files and i posted them in different direcotry ?
i.e.

file & directory structures:


localhost/mysite/config/config.php

localhost/mysite/prod/page.php

localhost/mysite/db/cat.php //as $cat1

localhost/mysite/back-up/cat.php //as $cat2

mjs
01-23-2010, 04:31 AM
anyone else could help me, please?

PappaJohn
01-23-2010, 07:08 AM
Just took a quick glance, and you have several problems.

1. This line will return a boolean value (true or false):

$cat_all = ($cat2 or $cat1);
which is not what you are expecting.

2. You then use $cat_all inside of a function, but at that point the value is out of scope since you did not define it inside the function

mjs
01-23-2010, 11:39 AM
Hi, PappaJohn i welcome you.

but i bit don't understand your input... what the meaning
value is out of scope since you did not define it inside the function

would you give the samples code?

Blessing upon You..:thumbsup:

oesxyl
01-23-2010, 11:52 AM
Hi, PappaJohn i welcome you.

but i bit don't understand your input... what the meaning

would you give the samples code?

Blessing upon You..:thumbsup:


function myfunc(){
$myvar = 'a variable inside a function, local scope: myfunc';
}

echo $myvar; // this is undefined because is local in myfunc


best regards

mjs
01-23-2010, 03:44 PM
i think this question need to be hold for a moment... now i know what the problem

@$cat2 @$cat1, prior as .txt file then i change it become .php without put tags <? ?>.

the inside of file @$cat2 @$cat1 e.g.
-Properties
-Cars
-Animals
-Etc...

all as Categori

then when i add the tag <? ?>, it's goes to ought, but now i face that tag <? ?> also printed at the categori... :confused:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum