Jump to content

Using Cookies And Links ?


Lustat
 Share

Recommended Posts

ok I've hit one (hopefully LAST) hurdle in creating my site. index.php has a form in it, you select state and it takes you to page2.php page2 grabs the state you chose and sets it as a cookie on your computer. select a link and it takes you to page3.php problem is... if my links are all page3.php how does it know what data to display from the mysql database ? I cant do links such as: page3.php/whatever I'm aware this may be somewhat of a beginner stupid question, but I'm completely baffled by this..edit: forgot to mention that the cookie will be used to determine the state (row) info. each state is it's own row, and each item is a column :)

Edited by Lustat
Link to comment
Share on other sites

maybe I'm misinterpreting your question, but can't you display the correct links on page 3 by using your cookie as a variable in your query? if each of those links are dependent on your cookie, you would have to process the cookie on each of those pages. Seems like it'd be better to use query string variables.

Link to comment
Share on other sites

maybe I'm misinterpreting your question, but can't you display the correct links on page 3 by using your cookie as a variable in your query? if each of those links are dependent on your cookie, you would have to process the cookie on each of those pages. Seems like it'd be better to use query string variables.
wouldnt I than have to use 2 cookies for each state ? so far the only variable that is used for the cookie is the state abbreviation so if you select texas the cookie is just "tx" page 2 seems to be working fine, but I'm not sure how to set up the links to take you to page 3 and display proper info. as it is, all I'm doing now is just echoing the menu. but I cant just echo the main body because they're all different options...also just ran into another problem... if there's no cookie set, page 2 first gives an error until you refresh the page :/
Link to comment
Share on other sites

i dont get what you're trying to accomplish. What are page 1, 2, and 3 supposed to do?
ah sorry. sounds like I mis understood you as well.instead of page 1,2,3.index.php has a form where you select your state. that takes you to state homepage (state.php) state homepage has 8 links AND the state page is also the one that sets the cookie for what state they selected. if they click on one of the links, that takes you to a 3rd page (selection.php) question is, how do I set my links so that when you select one of the 8 links on state.php, it takes you to selection.php and displays the info for that link...if I make my link href=selection.php it takes me there, but it doesnt display the link infoif that makes any sense
Link to comment
Share on other sites

oh ok. much more clear. well since you set the selected state to a cookie, you can use that cookie to query the database for more information on that state on selection.php. Another way of doing it would be to throw a query string into each of the links. For example, your links on state.php could be like this:

echo "yourfirstlink.php?state=".$_COOKIE['state'];echo "yoursecondlink.php?state=".$_COOKIE['state'];echo "yourthirdlink.php?state=".$_COOKIE['state'];

Then on selection.php, you can use that GET variable 'state' through $_GET['state']

Link to comment
Share on other sites

oh ok. much more clear. well since you set the selected state to a cookie, you can use that cookie to query the database for more information on that state on selection.php. Another way of doing it would be to throw a query string into each of the links. For example, your links on state.php could be like this:
echo "yourfirstlink.php?state=".$_COOKIE['state'];echo "yoursecondlink.php?state=".$_COOKIE['state'];echo "yourthirdlink.php?state=".$_COOKIE['state'];

Then on selection.php, you can use that GET variable 'state' through $_GET['state']

I really dont want to admit that I'm still confused :/I think the reason I'm still confused is because technically my links need to just be info from a querymy states pages has the following code
if(isset($_GET['state'])) {	$state = $_GET['state'];	$query = "SELECT state, menuA, menuB, Universities, Colleges, Otherstuff FROM states WHERE state = '${state}'";	$result = mysql_query($query) OR die(mysql_error());	// What happens if state that was specified is not in the db, or there was more then 1 state that matched in the db(state is hopefully UNIQUE isn't it)?	if (mysql_num_rows($result) != 1) {		// Probably do the same as what you do if they didn't specify a state here(so same as below code)	}} else {	// What happens if they don't give a state?  Do we return a default state?	// Assuming we do return a default state, we will need to set $result here to the default 'state'.}$row = mysql_fetch_assoc($result);?>

so technically I'm pulling stuff from the $queryso in theory my links should be

selection.php?$query=Universities

and my selection.php page would have

<PHP echo "$_GET('$query')"; ?>

?? sorry I'm probably asking stupid questions, I'm just completely baffled

Link to comment
Share on other sites

cancel that.. I answered my oqn question on this. thank you, I would not have been able to see how blind I am if it wasnt for your help :)I now have the links as selection.php?query=whateverand in selection.php I have <?php echo $_GET["query"]; ?>

Edited by Lustat
Link to comment
Share on other sites

cancel that.. I answered my oqn question on this. thank you, I would not have been able to see how blind I am if it wasnt for your help :)I now have the links as selection.php?query=whateverand in selection.php I have <?php echo $_GET["query"]; ?>
hmm perhaps I spoke too soon... get query only gets the name of the column, not the actual contents :/ just my luck haha
Link to comment
Share on other sites

ok first of all, your 'query' variable is not accessed through the GET superglobal since you defined it as: $query = "SELECT state, menuA, menuB, Universities, Colleges, Otherstuff FROM states WHERE state = '$_COOKIE['state']'";On your 3rd page, you can just use this same query since the state selected is stored in a cookie.

Link to comment
Share on other sites

ok first of all, your 'query' variable is not accessed through the GET superglobal since you defined it as: $query = "SELECT state, menuA, menuB, Universities, Colleges, Otherstuff FROM states WHERE state = '$_COOKIE['state']'";On your 3rd page, you can just use this same query since the state selected is stored in a cookie.
ok I think I'm in the clear with everything. just had to realize that the idea I had was too complicated lol. my mentality was to just have 1 page and depending on the link you click on, to just display that info in the main window. sort of like frames. solved the problem by just making 4 pages. one for each category and based on the state it'll echo just the info for that link / state
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...