Jump to content

function help "$this = $this2, $this3;" etc


Mutley

Recommended Posts

I'm trying to make it simple to make several admin menus but can't seem to get this part right, I just get this error:
[quote]Parse error: parse error, unexpected T_VARIABLE on line 21[/quote]

Here is the part I get confused with in bold, is this ok to do?

[code]<?
$team
[b]$menu = $addprofile, $manageprofile, $newsform, $logout; [/b]

draw__admin_menu($menu, $team);
?>[/[/code]


Here is the full code, I hope you understand what I'm trying to do:

[code]<?
$addprofile = "- <a href=\"admin_profileform.php\">Add a new Profile</a>";
$manageprofile = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$newsform = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$logout = " - <a href=\"logout.php\">Logout</a>";

function draw_admin_menu($menu, $team) {

if($logged[username] && $logged[level] ==$team)
{
?>
<center>Welcome <b><?=$logged[username]?></b><br /></center><br /><br />
<?=$menu?><br /><br />
<?
}
}
?>
<br /><br /><br />
<?
$team
$menu = $addprofile, $manageprofile, $newsform, $logout;

draw__admin_menu($menu, $team);
?>[/code]

Thanks.
Link to comment
Share on other sites

I've changed the common errors and commented it up but it still doesn't work, it won't display the content, I just get a blank white page:

[code]<?
// Here are the list of menu options I want to call
$addprofile = "- <a href=\"admin_profileform.php\">Add a new Profile</a>";
$manageprofile = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$newsform = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$logout = " - <a href=\"logout.php\">Logout</a>";

// The draw function, so I can create a list of links and user levels instead of doing the same code repeatadly
function draw_admin_menu($menu, $team) {

if($logged[username] && $logged[level] ==$team)
{
?>
<center>Welcome <b><?=$logged[username]?></b></center><br /><br />
<?=$menu?><br /><br />
<?
}
}
?>
<br /><br /><br />
<?

// Here is my admin menu calling the functions above

draw_admin_menu($menu, $team);
$team = "under_7s";
$menu = "$addprofile, $manageprofile, $newsform, $logout";

?>[/code]
Link to comment
Share on other sites

Try:

[code]
<?
// Here are the list of menu options I want to call
$addprofile = "- <a href=\"admin_profileform.php\">Add a new Profile</a>";
$manageprofile = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$newsform = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$logout = " - <a href=\"logout.php\">Logout</a>";
$teamname = "under_7s";

// The draw function, so I can create a list of links and user levels instead of doing the same code repeatadly
function draw_admin_menu($menu, $team) {
global $addprofile, $manageprofile, $newsform, $logout, $teamname;
$menu = "$addprofile, $manageprofile, $newsform, $logout";
$team = "$teamname";
return $menu, $team;

if($logged[username] && $logged[level] ==$team)
{
?>
<center>Welcome <b><?=$logged[username]?></b></center><br /><br />
<?=$menu?><br /><br />
<?
}
}
?>
<br /><br /><br />
<?

// Here is my admin menu calling the functions above
echo draw_admin_menu($menu, $team);

?>
[/code]
Link to comment
Share on other sites

the br's in my previous message about viewing the source code of your page were interpreted as line breaks.

your function prints out some line breaks, br's, at the end.  Check the source code of your blank page to see if those are there, which woul dindicate that the function is executing properly and the problem is probably that the conditions set in your if statement are not being satisfied.
Link to comment
Share on other sites

It is definatly the functions, having $ in a $=... like my topic title says. I did this code:

[code]<?
// Here are the list of menu options I want to call
$addprofile = "- <a href=\"admin_profileform.php\">Add a new Profile</a>";
$manageprofile = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$newsform = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$logout = " - <a href=\"logout.php\">Logout</a>";

// The draw function, so I can create a list of links and user levels instead of doing the same code repeatadly
function draw_admin_menu($team, $menu) {

//if($logged[username] && $logged[level] ==$team)
//{
?>
<center>Welcome <b><?=$logged[username]?></b></center><br /><br />
<?=$menu?><br /><br />
<?
}
//}
?>
End of page
<?

// Here is my admin menu calling the functions above

$team = "under_7s";
$menu = "$addprofile, $manageprofile, $newsform, $logout";
draw_admin_menu($menu, $team);

?>[/code]

...commenting out the "$" parts and it loaded "under_7s" and the word "Welcome" but didn't load any of the $menu or name attributes?

I thought it might be a PHP problem, so did this in the $menu part:
[code]$menu = <<<INCLUDES
$addprofile, $manageprofile, $newsform, $logout;
draw_admin_menu($menu, $team)
INCLUDES;[/code]

Still nothing worked.
Link to comment
Share on other sites

Nope.

Here is the code as it stands:
[code]<?
// Here are the list of menu options I want to call
$addprofile = "- <a href=\"admin_profileform.php\">Add a new Profile</a>";
$manageprofile = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$newsform = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$logout = " - <a href=\"logout.php\">Logout</a>";

// The draw function, so I can create a list of links and user levels instead of doing the same code repeatadly
function draw_admin_menu($team, $menu) {

//if($logged[username] && $logged[level] ==$team)
//{
?>
<center>Welcome <b><?=$logged[username];?></b></center><br /><br />
<?=$menu;?><br /><br />
<?
}
//}
?>
End of page
<?

// Here is my admin menu calling the functions above

$team = "under_7s";
$menu = <<<INCLUDES
$addprofile, $manageprofile, $newsform, $logout;
draw_admin_menu($menu, $team)
INCLUDES;

?>[/code]


Someone must know why. :(
Link to comment
Share on other sites

perhaps your server is not set up to use ASP style tags.  Try
[code]
//if($logged[username] && $logged[level] ==$team)
//{
?>
<center>Welcome <b><?PHP echo $logged[username];?></b></center><br /><br />
<?PHP echo $menu;?><br /><br />
[/code]

Also, I don't understand the following lines of your code:
[code]
menu = <<<INCLUDES
$addprofile, $manageprofile, $newsform, $logout;
[/code]

Perhaps <<<INCLUDES is something with which I am not familiar, or it's just your notation.
Link to comment
Share on other sites

Okay. looking at your code you are using an $logged variable in side the draw_admin_menu function. Now the function wont be able to access the $logged function as it is out side of the variable scope of the function. WHat you'll want to do is define as global inside the function like so [code=php:0]global $logged;[/code] Also your parameters where in the wrong order too in your function, and you was calling your function in the wrong place. Try this:
[code]<?php

// Here are the list of menu options I want to call
$addprofile = "- <a href=\"admin_profileform.php\">Add a new Profile</a>";
$manageprofile = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$newsform = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$logout = " - <a href=\"logout.php\">Logout</a>";

// Here is my admin menu calling the functions above
$team = "under_7s";
$menu = $addprofile . $manageprofile . $newsform . $logout;

// The draw function, so I can create a list of links and user levels instead of doing the same code repeatadly
function draw_admin_menu($menu, $team)
{
    global $logged; // define the $logged variable as global so we can access them from within the function.

    if($logged['username'] && $logged['level'] == $team)
    {
        $html = '<center>Welcome <b>' . $logged['username'] . '</b></center><br /><br />' . $menu . '<br /><br />';
    }

    echo $html;
}

draw_admin_menu($menu, $team);

?>
End of page[/code]
Link to comment
Share on other sites

What happens if you use this as the function:

[code=php:0]function draw_admin_menu($menu, $team)
{
    global $logged; // define the $logged variable as global so we can access them from within the function.

    //if($logged['username'] && $logged['level'] == $team)
    //{
        $html = '<center>Welcome <b>' . $logged['username'] . '</b></center><br /><br />' . $menu . '<br /><br />';
    //}

    echo $html;
}[/code]


Do you get any output. Also where is the $logged variable being created to?
Link to comment
Share on other sites

[quote author=wildteen88 link=topic=103422.msg412637#msg412637 date=1155150632]
What happens if you use this as the function:

[code=php:0]function draw_admin_menu($menu, $team)
{
    global $logged; // define the $logged variable as global so we can access them from within the function.

    //if($logged['username'] && $logged['level'] == $team)
    //{
        $html = '<center>Welcome <b>' . $logged['username'] . '</b></center><br /><br />' . $menu . '<br /><br />';
    //}

    echo $html;
}[/code]


Do you get any output. Also where is the $logged variable being created to?
[/quote]

YES! Of course! I forgot to do include('config.php') at the top for my logged variable.

Ah thanks, it all works now. Jeez, thanks so much wildteen!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.