/    Sign up×
Community /Pin to ProfileBookmark

$GET[‘] from links

i am building a website but not from forms or selects or anything i need to pass avariable or info to another page which i can do that but what i am trying to do consists of a include page that has way too many elseif’s i am trying to find a way to consolidate it so the code isnt messy like that
here is the piece of code that i have

<?if($_GET[‘year’]==”1960″){

include(“make.php”);
}elseif($_
GET[‘search’]==”1961″){

include(“make.php”);
}elseif($_GET[‘search’]==”1962″){

include(“make.php”);
}elseif($_
GET[‘search’]==”1963″){

include(“make.php”);
}elseif($_GET[‘search’]==”1964″){

include(“make.php”);
}elseif($_
GET[‘search’]==”1965″){

include(“make.php”);
} …etc

here is what i am trying to do or going about it wrong

<?if($_GET[‘year’]==null){?>
<table>
<td><center><h2>Please Select your Year</h2></center></td>
</table>
<table>
<tr><td><a href=”search.php?search=year&amp;year=1960″><h4>1960</h4></a>
<a href=”search.php?search=1961″><h4>1961</h4></a>
<a href=”search.php?search=1962″><h4>1962</h4></a>
<a href=”search.php?search=1963″><h4>1963</h4></a>
<a href=”search.php?search=1964″><h4>1964</h4></a></td>
..etc

which actually works but when i click the year you see multiple years and thats where the too many elseif’s are and i don want

this is the piece of code that isnt working for the selection

<?}elseif($_GET[‘year’]!=null){?>

<table>

<td><center><h2>Please Select Your Make</h2></center></td>
</table>
<table>
<tr><td><a href=”search.php?search=<?echo$_GET[‘search’]?>&amp;year=<?echo$_GET[‘year’];?>&amp;make=Buick”><h4>Buick</h4></a>
<a href=”search.php?search=Cadilac”><h4>Cadilac</h4></a>
<a href=”search.php?search=Chevrolet”><h4>Chevrolet</h4></a>

<a href=”search.php?search=Chevytruck”><h4>Chevy Truck</h4></a></td>
<td><a href=”search.php?search=Chrysler”><h4>Chrysler</h4></a>
..etc

i just dont know what to put into the value of $_GET[”] to show what the users have selected instead of that huge code of too many elseif’s

thank you very much in advanced

to post a comment
PHP

22 Comments(s)

Copy linkTweet thisAlerts:
@criterion9Jun 15.2009 — There is no need to have all those elseifs since you are just including the same file regardless. Check to see if the _GET variable is set and include the make.php file then. For example:<i>
</i>if(isset($_GET['your_var_name_here']){
include("your_file_name_here");
}
Copy linkTweet thisAlerts:
@cabalauthorJun 15.2009 — if(isset($_GET['search']==null)){

include("nogroup.php");

}

gives this error

Parse error: syntax error, unexpected T_IS_EQUAL, expecting ',' or ')' in /home/cabal/public_html/repopparts/search.php on line 89
Copy linkTweet thisAlerts:
@criterion9Jun 15.2009 — Is this what you meant?
<i>
</i>if(isset($_GET['your_var']) &amp;&amp; $_GET['your_var'] != null){
//do stuff
}
Copy linkTweet thisAlerts:
@cabalauthorJun 15.2009 — yes that did that error but if you take a look on my web page when you click on a year i need that value to pass to the next $_GET

http://repopparts.easywebbies.com/search.php?search=Year

if(isset($_GET['year']) && $_GET['year']==$GET['year']){

include("make.php");

}

i cant get the variable to pass
Copy linkTweet thisAlerts:
@criterion9Jun 15.2009 — It is doing that. $_GET['search'] will equal "Year" when it first starts from your link and then "1975" or whatever year you clicked on. What seems to be the trouble?
Copy linkTweet thisAlerts:
@cabalauthorJun 15.2009 — i cant get the variable to pass without giving it a thopusand elseif's

and was hoping there was an easier way when i get down thto the models of the make's
Copy linkTweet thisAlerts:
@criterion9Jun 15.2009 — Your code above is check is "$_GET['year']" is set which it never will be since you are setting "$_GET['search']" using the links. Neither of those things has anything to do with passing code to an included file. What is the code you are using inside make.php?
Copy linkTweet thisAlerts:
@criterion9Jun 15.2009 — Also

if(isset($_GET['year']) && $_GET['year']==$GET['year']){
[/quote]

is unnecessary. The stuff after the "&&" is just checking if the variable is equal to itself which it always will be.

http://www.webmonkey.com/tutorial/PHP_Tutorial_for_Beginners

http://www.ibm.com/developerworks/views/opensource/libraryview.jsp?search_by=learning+php
Copy linkTweet thisAlerts:
@cabalauthorJun 15.2009 — if(isset($_GET['search']) && $_GET['search']==Year){

include("year.php");

}

all the year.php has in it is

<table>

<td><center><h2>Please Select Your Make</h2></center></td>

</table>

<table>

<tr><td><a href="search.php?search=<?echo$_GET['search']?>&amp;year=<?echo$_GET['year'];?>&amp;make=Buick"><h4>Buick</h4></a>

<a href="search.php?search=Cadilac"><h4>Cadilac</h4></a>

<a href="search.php?search=Chevrolet"><h4>Chevrolet</h4></a>


<a href="search.php?search=Chevytruck"><h4>Chevy Truck</h4></a></td>

<td><a href="search.php?search=Chrysler"><h4>Chrysler</h4></a>

<a href="search.php?search=Dodge"><h4>Dodge</h4></a>

<a href="search.php?search=Dodgetruck"><h4>Dodge Truck</h4></a>

<a href="search.php?search=Eagle"><h4>Eagle</h4></a>

<a href="search.php?search=Ford"><h4>Ford</h4></a></td>

<td><a href="search.php?search=Fordtruck"><h4>Ford Truck</h4></a>

<a href="search.php?search=Gmctruck"><h4>GMC Truck</h4></a>

<a href="search.php?search=Jeeptruck"><h4>Jeep Truck</h4></a>

<a href="search.php?search=Lincoln"><h4>Lincoln</h4></a>

<a href="search.php?search=Mercury"><h4>Mercury </h4></a></td>

<td><a href="search.php?search=Oldsmobile"><h4>Oldsmobile</h4></a>

<a href="search.php?search=Plymouth"><h4>Plymouth</h4></a>

<a href="search.php?search=Pontiac"><h4>Pontiac</h4></a>

<a href="search.php?search=Volkswagon"><h4>Volkswagon</h4></a>

<a href="search.php?search=Volkswagontruck"><h4>Volkswagon Truck</h4></a></td>

</tr>

</table>

and that brings up the page you were on

p.s. i will be finishing it

now i need when they click 1975 or any other search link that it

goes to the files make.php

then model.php

i can do it with a thousand elseif's but that is very sloppy coding
Copy linkTweet thisAlerts:
@criterion9Jun 15.2009 — So then you need to change pages based on the $_GET['search']. I.e.:

<i>
</i>if(isset($_GET['search']){
switch($_GET['search']){
case "make":
include("make.php");
break;
default: //fall-through intential
case "year":
include("year.php");
break;
}
} else {
// the search variable isn't set
}
Copy linkTweet thisAlerts:
@cabalauthorJun 15.2009 — So then you need to change pages based on the $_GET['search']. I.e.:

<i>
</i>if(isset($_GET['search']){
switch($_GET['search']){
case "make":
include("make.php");
break;
default: //fall-through intential
case "year":
include("year.php");
break;
}
} else {
// the search variable isn't set
}
[/QUOTE]


so then the case make would be $_GET['make'] and so on

if i am understanding you correctly
Copy linkTweet thisAlerts:
@criterion9Jun 15.2009 — Exactly. Then when you display your links on each page you'll need to have ?search=year&amp;make=whatever&amp;model=something for each of them as appropriate. So the first page with just have ?search=year&amp;year=xxxx. The next page (if it were model) would have ?search=year&amp;year=your_get_value&amp;model=this_model.

Does that make sense?
Copy linkTweet thisAlerts:
@cabalauthorJun 15.2009 — yes that does make sence

right now on default i have it starting on search.php

and the select your part link is set to be on

http://repopparts.easywebbies.com/search.php?search=Year

the one bad thing it does is it displays both year.php and make.php on the search your part link probably because the search your part link has a search in the variable piece of the <a href how should i go about stating that link to do only the years
Copy linkTweet thisAlerts:
@criterion9Jun 15.2009 — What is your code in search.php? It seems like you are including both for some reason. Are you using the switch...case?
Copy linkTweet thisAlerts:
@cabalauthorJun 15.2009 — ok i got the fron page working ok now i need to figure out that code you have given me to only display one page then switch to the next
Copy linkTweet thisAlerts:
@criterion9Jun 15.2009 — Exactly. Then when you display your links on each page you'll need to have ?search=year&amp;make=whatever&amp;model=something for each of them as appropriate. So the first page with just have ?search=year&amp;year=xxxx. The next page (if it were model) would have ?search=year&amp;year=your_get_value&amp;model=this_model.

Does that make sense?[/QUOTE]


I'm sorry, I've mislead you on the above. Each page should have search=the_next_page&amp;all_the_other_stuff. So the first page will have search=year, the year page would have search=make, the make page would have search=model, etc.
Copy linkTweet thisAlerts:
@cabalauthorJun 15.2009 — if(isset($_GET['search'])){

switch($_
GET['search']){

case "make":

include("make.php");

break;

default: //fall-through intential

case "year":

include("year.php");

break;

}

} else {

// the search variable isn't set

}

i put that into the search.php just how you gave it and it brings up both pages at once

nevermind on that it still wont bring up the next page as make.php
Copy linkTweet thisAlerts:
@criterion9Jun 15.2009 — Post your whole search.php contents. I think I know what's going on but I need to see to make sure.
Copy linkTweet thisAlerts:
@cabalauthorJun 15.2009 — <HTML>

<?include("header.php");?>

<BODY vLink=#124a82 aLink=#0000ff link=#124a82 bgColor=#ffffff leftMargin=0 topMargin=0 rightMargin=0 MARGINHEIGHT="0" MARGINWIDTH="0">

<?include("logo.php");?>

<TABLE cellSpacing=0 cellPadding=0 width="100&#37;" border=0>

<TR>

<TD vAlign=top width=140><IMG height=2 width=140><br>

<!--Start left side-->

<TABLE cellSpacing=3 cellPadding=0 width=151 height=100% border=0>

<tr>

<TD width="100%"><font face="Arial" color="#0000FF" size="2"><i><b>Search</b></i></font></TD>

</tr>

<tr>

<TD width="100%">

<TABLE cellSpacing=2 cellPadding=0 width="100%" border=0>

<TR>

<TD width="100%" height="34"><FONT face=Arial color=#cccccc size=2>

<a href="search.php">Home</a><br>

<a href="search.php?search=Year">Search Your Part</a><br>

</TD><br>

</TR>
</TABLE>

</tr>
<tr>
</TD>
<TD width="100%"><font face="Arial" color="#0000FF" size="2"><i><b>Coming Soon</b></i></font>

<td><img border="0" src="images/spacer.gif" width=10 height=3></td>
</tr>
<tr>
<TD width="100%" height="34"><font face="Arial" color="#oooooo" size="2"><i>Submit Your Info</i></font></TD><br>
</tr>
<tr>
<TD width="100%" height="34"><font face="Arial" color="#oooooo" size="2"><i>Compare Vendors</i></font></TD><br>
</tr>
<tr>
<TD align=middle width="100%"><font face="Arial" color="#ffffff" size="2"><b>Chat</b></font></TD>
</tr>

<tr>

<TD width="100%">
<TABLE cellSpacing=2 cellPadding=0 width="100%" border=0>
<TR>
<TD width="100%" height="34"><IFRAME src="chat-book/chat-book.php?pagina=0" frameborder="0" width="160" height="300" scrolling="yes" marginwidth="0" marginheight="0"></IFRAME>
</TD>
</TR>
</TABLE>
</TD>
</tr>
<tr>
<td><img border="0" src="images/spacer.gif" width=10 height=3></td>
</tr>
<tr>
<TD align=middle width="100%"><font face="Arial" color="#ffffff" size="2"><b>Your Pics You Sent</b></font></TD>
</tr>
<tr>
<TD width="100%">
<TABLE cellSpacing=2 cellPadding=0 width="100%" border=0>
<TR>

<td height="135"><iframe src="slideshow/" height="100%" width="100%" scrolling="no"></iframe>
</TR>
</TABLE>
</TD>
</tr>

</TABLE>
</TD>
<!--End left side-->


<!--Start of Middle-->

<TD vAlign=top width="70%" height=100%>

<TABLE cellSpacing=0 cellPadding=0 width="100%" height=100% border=0>

<tr>
<td>
<?


if(isset($_GET['search'])){

switch($_
GET['search']){

case "make":

include("make.php");

break;

default: //fall-through intential

case "year":

include("year.php");

break;

}

} else {

// the search variable isn't set

}

?>


</TD>
</TR>

<TR>

</TR>
</TABLE>
</TD>
<!--End middle-->

<TD vAlign=top width=9></TD>

<!--Right side-->
<TD vAlign=top width="30%">

<TABLE cellSpacing=5 cellPadding=0 width="100%" border=0>

<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TR>
<TD align=middle width="100%"><font face="Arial" color="#ffffff" size="2">Date and Info</font></TD>
</TR>
<TR>
<TD width="100%">
<TABLE cellSpacing=5 cellPadding=0 width="100%" border=0>
<TR>
<TD width="100%">
<TABLE cellPadding=0 width="100%" border=0>
<TR>
<TD width="100%"><font color="#000000" face="Arial" size=2><?php
$d=date("l");
echo "Todays Date Is";
echo "<br />";
echo "$d";
echo "<br>";
echo date("Y/m/d");
?>
<br>
<?php

$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];

echo 'Your IP '.$ip; echo "<br />"; echo 'you are logged';

?>

</font></TD>

</TR>

</TABLE>

</td>

</TR>

</TABLE>

</TD>

</TR>

</TABLE>

</TD>

</tr>

<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TR>
<TD align=middle width="100%"><font face="Arial" color="#cccccc" size="2">Login</font></TD>
</TR>
<TR>
<TD width="100%">
<TABLE cellSpacing=5 cellPadding=0 width="100%" border=0>
<TR>
<TD width="100%">
<TABLE cellPadding=0 width="100%" border=0>
<TR>
<TD width="100%"><form action="members_area/checkuser.php" method="post">
Username: <input type="text" name="username" size="20"><br>
Password: <input type="password" name="password" size="20"><br>
<input type="submit" value="Log In">
</form>
<br />
<br />
<a href="logout1.php">Logout</a>
<FONT>or&nbsp;</FONT>
<a href="members_area/join_form.html"> Register</a></font></TD>
</TR>
</TABLE>
</td>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</TD>
</tr>

<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TR>
<TD align=middle width="100%"><font face="Arial" color="#ffffff" size="2">Google Adds</font></TD>
</TR>
<TR>
<TD width="100%" bgColor=#f5f5f5>
<TABLE cellSpacing=5 cellPadding=0 width="100%" border=0>
<TR>
<TD width="100%">
<TABLE cellSpacing=5 cellPadding=0 width="100%" border=0>
<TR>
<TD width="100%" bgcolor="#FFFFFF"><script src="http://www.gmodules.com/ig/ifr?url=http://www.google.com/coop/api/007091944170777598728/cse/ggfk13wqlxw/gadget&amp;synd=open&amp;w=110&amp;h=75&amp;title=car+parts&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js"></script></TD>
</TR>
</TABLE>
</td>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</TD>
</tr>

<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>

<TR>
<TD width="100%">
<TABLE cellSpacing=5 cellPadding=0 width="100%" border=0>
<TR>
<TD width="100%">
<TABLE cellSpacing=5 cellPadding=0 width="100%" border=0>
<TR>

<TD width="100%" valign=top>
<TABLE cellPadding=0 width="100%" border=0>

</TABLE>
</td>
</TR>
</TABLE>
</td>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</TD>
</tr>
</table>
<!--End rigth side-->

</td>
</tr>

</table>

<?include("footer.php");?>
Copy linkTweet thisAlerts:
@criterion9Jun 15.2009 — Your links in your year.php look a little off.

http://repopparts.easywebbies.com/search.php?year=1960
[/quote]

This should have ?search=make&amp;year=1960 otherwise the search page won't know to include the make.php file instead of the year.php file.

Does that make sense?
Copy linkTweet thisAlerts:
@cabalauthorJun 15.2009 — ok that did work i cant beleive i missed that little piece even thow i have worked with it before

you are awsome i apreciate you now i can go on and do model to display what i need at that part

thank you very much for your patience
Copy linkTweet thisAlerts:
@criterion9Jun 15.2009 — No problem. For efficiency you might consider using arrays to list out the links using a loop. Glad I could help.
×

Success!

Help @cabal spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...