Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Begginer Help SVP

Status
Not open for further replies.

sumilsay

Technical User
Feb 12, 2003
69
0
0
CA
i am trying to learn... i really am :(


<?php

if ($HTTP_GET_VARS["who"] == "admin")
{
echo("
<h1>here's a default page for admin</h1>
<a href='?who=admin&amp;step=list'>list all</a><hr />
<table border='1'>
<tr>
<td>html search widget<br /><a href='?who=admin&amp;step=list'>search</a></td>
</tr>
</table>
<hr />
<a href='?who=admin&amp;step=add'>add</a><hr />
");
if ($HTTP_GET_VARS["step"] == "list")
{
echo("
<h1>here's a list for admin</h1>
<a href='?who=admin'>home</a><hr />
list row <a href='?who=admin&amp;step=detail'>view</a><br />
list row <a href='?who=admin&amp;step=detail'>view</a><br />
list row <a href='?who=admin&amp;step=detail'>view</a><br />
list row <a href='?who=admin&amp;step=detail'>view</a><br />
");
}
}
else
{
echo("
<h1>here's a default page for user</h1>
<a href='?who=user&amp;step=list'>list all</a><hr />
html categories widget<br />
<a href='?who=user&amp;step=list&filt=1'>category 1</a><br />
<a href='?who=user&amp;step=list&filt=2'>category 2</a><br />
<a href='?who=user&amp;step=list&filt=3'>category 3</a><hr />
<table border='1'>
<tr>
<td>html search widget<br /><a href='?who=user&amp;step=list'>search</a></td>
</tr>
</table>
<hr />");
if ($HTTP_GET_VARS["step"] == "list")
{
echo("
<h1>here's a list for user</h1>
<a href='?who=user'>home</a><hr />
list row <a href='?who=user&amp;step=detail'>view</a><br />
list row <a href='?who=user&amp;step=detail'>view</a><br />
list row <a href='?who=user&amp;step=detail'>view</a><br />
list row <a href='?who=user&amp;step=detail'>view</a><br />
");
if ($HTTP_GET_VARS["step"] == "detail")
{
echo("
<h1>here's a detail for user</h1>
<a href='?who=user'>home</a><hr />
new item detail<hr />
");
}

}
}


?>


why is it opening up the next information on the same page? and when i click on the user view detail, it goes back a step.
does anyone understand the code, or me?!

thanks for your time everyone.
me.
 
Okay, here's the logical blocks of your code:

Code:
if ($_GET["who"] == "admin")
{
	//output default admin page

	if ($_GET["step"]  == "list")
	{
		//output admin list stuff
	}
}
else 
{
	//output default user page
	if ($_GET["step"]  == "list")
	{
		//output user list stuff
	
		if ($_GET["step"]  == "detail")
		{
			//output user detail stuff
		}
	}
}

If who is "admin", the script will always output the default admin page. If the step is "list", the script additionally outputs the list.

If the who is "user", the script will always output the default page. If step is "list", it will also output the list. However, the detail section will never be run, as that section of code is nested inside the if-block that outputs the list. Step cannot be both "list" and "detail".

What is it you want this thing to do?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Also there is no else to catch other events.

eg.
Code:
if ($_GET["who"] == "admin")
{[b]
    //output default admin page
    if (!isset($_GET["step"]))
    {
        $_GET["step"] = "list";
    }
[/b]
    if ($_GET["step"]  == "list")
    {
        //output admin list stuff
    }
    else
    {
         echo "you bad boy!";
    }
}
...

Olav Alexander Mjelde
Admin & Webmaster
 
wait, this one is better:
Code:
    if ($_GET["step"]  == "list" || !isset($_GET["step"]))
    {
        //output admin list stuff
    }

Olav Alexander Mjelde
Admin & Webmaster
 
hmm, maybe so..
My eyes burn, my eyes burn.. (after reading the red fontcolor on blue bgcolor)

I think that some colors should be banned from this forum, or maybe just all colors.

Some exceptions though, as if they are inside the code-tags, they might be usefull, if not abusefull.

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top