Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-24-2013, 02:35 PM   PM User | #1
howard-moore
Regular Coder

 
Join Date: May 2008
Posts: 114
Thanks: 13
Thanked 0 Times in 0 Posts
howard-moore is an unknown quantity at this point
PHP script not working - what is going wrong?

Hi,

I have the following bit of PHP that is not working. I am basically trying to put together a menu structure:

Code:
<?php
	$sql = "SELECT * FROM PCNET_$filename WHERE page_type='TOP_PAGE' AND live='checked' AND page_order!='x' ORDER BY parent_code, ABS(page_order), title";
	$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
	while ($row = mysql_fetch_assoc($sql_result)) {
		echo '<dt><a href="'.($row["link"]).'?id='.($row["id"]).'">'.($row["menu_title"]).'</a></dt>';
			if ($row["parent_live"]=='checked') {
				include ('subgridmenu.php?parent_code=';
				echo	($row["id"])'');
			};
		};
?>
It shows all the pages in the menu list OK, but will not display anything in the subgridmenu.php file, which is as follows:

Code:
<?php
	$sql = "SELECT * FROM PCNET_$filename WHERE page_type='SUB_PAGE' AND live='checked' AND page_order!='x' ORDER BY ABS(page_order), title";
	$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
	while ($row = mysql_fetch_assoc($sql_result)) {
		echo '<dd><a href="'.($row["link"]).'?id='.($row["id"]).'">'.($row["menu_title"]).'</a></dd>';
		}
?>
Can anyone give me any pointers as to why?

Thanks,
Neil
howard-moore is offline   Reply With Quote
Old 02-24-2013, 03:53 PM   PM User | #2
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Have you tried running the second subgrid query through phpmyadmin to check that it runs? I've never trusted the or die() method, it's a bit flawed and doesn't always work.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 02-24-2013, 03:53 PM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
You can't do this:
PHP Code:
                include ('subgridmenu.php?parent_code=';
                echo    (
$row["id"])''); 
querystrings are HTTP, not FILE protocol based. You can assign $parent_code prior to the include of the subgridmenu.php, or even $_GET['parent_code'].
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
howard-moore (02-24-2013)
Old 02-24-2013, 03:58 PM   PM User | #4
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,364
Thanks: 18
Thanked 348 Times in 347 Posts
sunfighter is on a distinguished road
In top php this line
PHP Code:
include ('subgridmenu.php?parent_code='
is missing a closing parenthese.
PHP Code:
include ('subgridmenu.php?parent_code='); 
and shouldn't it have the parent_code variable?

This line
PHP Code:
echo    ($row["id"])''); 
At first I'd say it has an extra parenthese, but then I've never seen parentheses like that in an echo.

So I'm guessing:
PHP Code:
if ($row["parent_live"]=='checked') {
    include (
'subgridmenu.php?parent_code='.$row["id"]);
    
//echo ($row["id"]).'';
}; 
sunfighter is offline   Reply With Quote
Old 02-24-2013, 04:18 PM   PM User | #5
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by sunfighter View Post
So I'm guessing:
PHP Code:
if ($row["parent_live"]=='checked') {
    include (
'subgridmenu.php?parent_code='.$row["id"]);
    
//echo ($row["id"]).'';
}; 
As fou says, you can't use parameters on file system calls, only urls. Why? With the file system there is no webserver to deal with the parameters.

@Fou: Good catch.. I missed another glaringly obvious issue

I think I'm going to take a week or two off... I'm clearly loosing the plot
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 02-24-2013, 04:23 PM   PM User | #6
howard-moore
Regular Coder

 
Join Date: May 2008
Posts: 114
Thanks: 13
Thanked 0 Times in 0 Posts
howard-moore is an unknown quantity at this point
Quote:
Originally Posted by tangoforce View Post
As fou says, you can't use parameters on file system calls, only urls. Why? With the file system there is no webserver to deal with the parameters.

@Fou: Good catch.. I missed another glaringly obvious issue

I think I'm going to take a week or two off... I'm clearly loosing the plot
Thanks - that was exactly the issue!

Really appreciate your help.

Neil
howard-moore is offline   Reply With Quote
Old 02-24-2013, 04:28 PM   PM User | #7
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
It's Fou you need to thank - go up and click his big green "Thank User for this post" button
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:50 AM.


Advertisement
Log in to turn off these ads.