Navigate
Home
ArticleWiki
Forum
Journal
Search
Newsletter
Links
Tech News
expertsrt.com
Welcome Guest.
Username:

Password:

Remember me

need help with parse error
Welcome, Guest. Please login or register.
December 02, 2008, 01:54:44 PM
11304 Posts in 1248 Topics by 498 Members
Latest Member: katCheeme
Experts Round Table Network  |  Serverside Technology  |  PHP  |  need help with parse error « previous next »
Pages: [1] 2
Author Topic: need help with parse error  (Read 1064 times)
seandelaney
Mentor

Offline Offline

Posts: 119



WWW
« on: February 02, 2006, 03:19:51 AM »

In my index.php page I have:

Code:
<td width="700px" align="left" valign="top">
<?php include 'includes/options.php'; ?>
</td>


In my options.php page I have this:

Code:


...

function sectors(sid)
{
include 'includes/sectors.php?sid='.sid.'';
}

...


But im getting a parse error on line 37 which is the function above.

Problem is I cant seem to fix it...
Logged

seandelaney
Mentor

Offline Offline

Posts: 119



WWW
« Reply #1 on: February 02, 2006, 03:24:42 AM »

got it working guys,  :D

left out the $....  :scratch:

silly schoolboy error  :oops:
Logged

Anonymous
Guest
« Reply #2 on: February 02, 2006, 03:29:46 AM »

Either this is a REALLY new way of doing things, or you've got it wrong.

You are using include without a protocol in front (e.g. http:// ftp://, etc), therefore the file protocol will be used and the include file will be presented as PHP code to be processed within this script.

The parameter should not make any difference.

What happens if you ...

Code:
<?php
function section($sid)
{
    include 'includes/sectors.php';
}
?>


From my understanding the included file does not receive the parameter (unless MAYBE it somehow gets it as in an $argv[] array).

Confused and maybe about to learn something new!
Logged
seandelaney
Mentor

Offline Offline

Posts: 119



WWW
« Reply #3 on: February 02, 2006, 03:31:54 AM »

what i did was this:

Code:
function sectors($sid)
{
include 'includes/sectors.php?sid=$sid';
}


It worked, but is it not correct?

Your the expert!
Logged

Anonymous
Guest
« Reply #4 on: February 02, 2006, 03:40:10 AM »

I am? I am!

What I'm asking is how does supplying the parameter to the include make any difference to the included code?

Is it possible that you actually have a file called ...

includes/sectors.php?sid=$sid

Or are you expecting the $sid to be translated into the actual sid value?

e.g.

Code:
<?php
$sid='PHP12345';
function sectors($sid)
{
   include "includes/sectors.php?sid=$sid";
}

sectors($sid);
?>


And you have a file called

includes/sectors.php?sid=PHP12345

On Windows, you cannot have a file with a ? in the name.

If I try this code I get ...

Warning: include(includes/sectors.php?sid=PHP12345): failed to open stream: No such file or directory in C:\t1.php on line 5

Warning: include(): Failed opening 'includes/sectors.php?sid=PHP12345' for inclusion (include_path='C:\PEAR\pear;.\;c:\php5\includes\;c:\php5\pear\;D:\Data\PHP\Includes\') in C:\t1.php on line 5

Now.

If you are suppressing warnings, then you will not see this message.

And as include is optional, the code will continue running.

But I suspect this is not what you require.
Logged
Anonymous
Guest
« Reply #5 on: February 02, 2006, 03:41:39 AM »

More comments from a recently answered Q in TOS.

http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_21714569.html
Logged
seandelaney
Mentor

Offline Offline

Posts: 119



WWW
« Reply #6 on: February 02, 2006, 03:58:52 AM »

OK your right!

I think I have gone down the wrong path in what im trying to do.

In my index.php page I have

Code:

<?php include 'includes/options.php';?>


I also have a menu with my links - example:

Code:

<a href="index.php?pid=87&amp;sid=<?=$row['sid'];?>" title="<?=$row['title'];?>"><?=$row['title'];?></a></p>


Inside my options.php page I have a Switch and Case statements to redirect user to the different pages in the site.

Code:

<?php
function sectors($sid)
{
include 'includes/sectors.php?sid=$sid';
}

switch (preg_replace('/[^0-9]/','', (isset($_GET["pid"])) ? $_GET["pid"] : ""))
{
Case "87": sectors($_GET['sid']); break;
default: home();
}
?>


What im trying to do, is if user selects a sector from my menu, have that sectors details appear in the "display" area of my index.php page.

confused?  :D

Each sectors details are stored in a MySQL and I want to query DB using the "sid" (Sector ID) to pull out the correct details.

All my pages are inside a includes folder.

The sectors.php page is just a template so to have each of the sectors details have the same format...

So what I want to do is pass the "sid" through the functions... or is there more better way?
Logged

Anonymous
Guest
« Reply #7 on: February 02, 2006, 04:09:02 AM »

Without seeing more code it is not easy to advise you on the specifics.

Does the file sectors.php contain plain code with no wrapper to make it a function? Or are you expecting to get this from the webserver (differentiate between webserver and filestore)?

Normally, functions reside in a library file (a .inc if you will).

These libraries are included/required at the beginning of a script.

You can then call the functions from the script.

You can pass them parameters.

What is the content of sectors.php?

You say it is a template. So why a PHP extension? I would have expected .tpl (or something).
Logged
seandelaney
Mentor

Offline Offline

Posts: 119



WWW
« Reply #8 on: February 02, 2006, 04:14:35 AM »

this is my sectors.php page:

Code:
<?php
#$sector_id = $_GET['sector_id'];
#$query_list_sectors_details = "SELECT sid, title FROM tblSectors WHERE sid = $sector_id";
#$result_list_sectors_details = mysql_query($query_list_sectors_details, $link_id) or die("ERROR RETRIVING sectors FROM DATABASE");
#while ($row = mysql_fetch_array($result_list_sectors_details))
#{
?>
<!-- START OF SCREEN TABLES //-->
<table border="0px" cellpadding="0px" cellspacing="0px" width="700px">
<tr>
<td width="700px" height="30px" align="left" valign="middle" class="location"><p>You are here: <a href="." title="Sectors">Sectors</a> > <?=$row['title'];?></p></td>
</tr>
<tr>
<td width="700px" align="left" valign="middle" class="display">
<p><strong><?=$row['title'];?></strong></p>
<p>Selected Sector information here</p>
<p><a href="." title="^ Back to Top">^ Back to Top</a></p>
</td>
</tr>
</table>
<!-- END OF SCREEN TABLES //-->
<?php
}
?>

I also made a change to this line:

Code:
include 'includes/sectors.php?sid=$sid';


It now looks like this:

Code:
include 'includes/sectors.php?sector_id=$sid';
Logged

Anonymous
Guest
« Reply #9 on: February 02, 2006, 04:32:10 AM »

Aha!

So, change the sectors.php script to ...

Code:
<?php
function sector($sid)
{
$sid = (int)$sid; // We only want an integer - nothing else.
$query_list_sectors_details = "SELECT sid, title FROM tblSectors WHERE sid = $sid";
$result_list_sectors_details = mysql_query($query_list_sectors_details, $GLOBAL['link_id']) or die("ERROR RETRIVING sectors FROM DATABASE"); // Messy GLOBAL.

$s_Output = '';
while (False !== ($row = mysql_fetch_array($result_list_sectors_details)))
{
$s_Output .= <<< END_HTML
<!-- START OF SCREEN TABLES //-->
<table border="0px" cellpadding="0px" cellspacing="0px" width="700px">
<tr>
<td width="700px" height="30px" align="left" valign="middle" class="location">
<p>You are here: <a href="." title="Sectors">Sectors</a> > {$row['title']}</p>
</td>
</tr>
<tr>
<td width="700px" align="left" valign="middle" class="display">
<p><strong>{$row['title']}</strong></p>
<p>Selected Sector information here</p>
<p><a href="." title="^ Back to Top">^ Back to Top</a></p>
</td>
</tr>
</table>
<!-- END OF SCREEN TABLES //-->
END_HTML;
}

return $s_Output;
}
?>


Place the line ...
Code:
require_once('includes/sector.php');
at the top of the main script.

Then use
Code:
Case "87":
echo sectors($_GET['sid']);
break;


to get the result of the sector call.

When I am coding, I will only have 1 useful echo statement. This will normally be at the end of the script when all the HTML/JS/CSS/etc has been constructed and I want to send it to the browser.

Any other echo statements will be for debugging and would appear before the main data. But this is not necessary.

Try this and see what happens.

Wherever you want to get the sector information, you call sector(id_here) and you will get back the HTML containing the "SCREEN TABLES" data. Or nothing if the ID was not a valid sector ID.
Logged
seandelaney
Mentor

Offline Offline

Posts: 119



WWW
« Reply #10 on: February 02, 2006, 04:55:08 AM »

thats made it better!

cheers  =D>
Logged

Anonymous
Guest
« Reply #11 on: February 02, 2006, 05:04:22 AM »

The main emphasis here is that you are calling a funciton and that the therefore you would expect it to return something.

Unfortunately, PHP does not have a "procedure" construct, though writing one is very easy - a function with no return.

But another developer to something called a "function" would expect a return.

Glad to have helped.
Logged
Srirangan
Moderator
*
Offline Offline

Posts: 52



WWW
« Reply #12 on: February 02, 2006, 10:57:39 AM »

Code:


...

function sectors($sid)
{
include 'includes/sectors.php?sid='.$sid.'';
}

...
Logged

I rant therefore I am!
Srirangan
Moderator
*
Offline Offline

Posts: 52



WWW
« Reply #13 on: February 02, 2006, 10:59:39 AM »

Code:

function sectors($sid)
{  
   include "includes/sectors.php?sid=$sid";
}


am too tired to comment, please post your questions if you have any, i'll reply tommorrow. coffee!  :coffee2:
Logged

I rant therefore I am!
Anonymous
Guest
« Reply #14 on: February 03, 2006, 01:23:09 AM »

Quote from: "Srirangan"
Code:

function sectors($sid)
{  
   include "includes/sectors.php?sid=$sid";
}


am too tired to comment, please post your questions if you have any, i'll reply tommorrow. coffee!  :coffee2:


Not wanting to point and stuff, but query had already been covered and hopefully sean's code has improved a little on the way.
Logged
Pages: [1] 2
« previous next »
    Jump to: