Lamez Posted March 7, 2008 Share Posted March 7, 2008 1.Variables, could I do this: <?php $var = "cat"; echo "I love $var"; $var ="dog"; echo "I love $var"; ?> and the output will be I love cat I love dog 2.How do I do this page.php?action=members&user or page.php?action=login&pass&user or somting like that Quote Link to comment https://forums.phpfreaks.com/topic/94887-few-questions/ Share on other sites More sharing options...
fert Posted March 7, 2008 Share Posted March 7, 2008 $_GET['name_of_var'] Quote Link to comment https://forums.phpfreaks.com/topic/94887-few-questions/#findComment-486021 Share on other sites More sharing options...
Lamez Posted March 7, 2008 Author Share Posted March 7, 2008 I know that, but how do I do this ?action=page&somthing Quote Link to comment https://forums.phpfreaks.com/topic/94887-few-questions/#findComment-486023 Share on other sites More sharing options...
obsidian Posted March 7, 2008 Share Posted March 7, 2008 1. Yes. Try it out. Every time you run the assignment operator on a variable, you effectively overwrite the previous value. 2. First off, to retrieve information from the URL, you need to use the $_GET global. This is an array that is set up in PHP to automatically return any parameters passed via the URL. However, based on your sample, I would definitely encourage you to never pass user information such as password, SSN, etc through the URL. Always use POST (and preferably a secure server for the SSN and any other personal info). Check out this page of the PHP manual for details on the predefined variables including $_GET. Quote Link to comment https://forums.phpfreaks.com/topic/94887-few-questions/#findComment-486027 Share on other sites More sharing options...
obsidian Posted March 7, 2008 Share Posted March 7, 2008 I know that, but how do I do this ?action=page&somthing In and of itself, that sets the variable something but doesn't assign a value to it, so it's pretty much worthless. If you are attempting to assign multiple values to a single variable, you may want to do something like this: URL: index.php?cat=1,2,3,4 <?php $cats = explode(',', $_GET['cat']); ?> Quote Link to comment https://forums.phpfreaks.com/topic/94887-few-questions/#findComment-486030 Share on other sites More sharing options...
Lamez Posted March 7, 2008 Author Share Posted March 7, 2008 hmm, well I would never pass information via URL, I do though use post data. Well thanks for the information guys. I will have to look at that link on variables. But what I set would it work? Quote Link to comment https://forums.phpfreaks.com/topic/94887-few-questions/#findComment-486534 Share on other sites More sharing options...
Lamez Posted March 7, 2008 Author Share Posted March 7, 2008 <?php $test = $_GET['page']; if ($test == ("page" && "this")){ echo "ya you found the page"; }else{ echo "nothing here"; } ?> would that work out as: ?page&this Quote Link to comment https://forums.phpfreaks.com/topic/94887-few-questions/#findComment-486538 Share on other sites More sharing options...
deadonarrival Posted March 7, 2008 Share Posted March 7, 2008 ?action=page&somthing=value You can then use $action = $_GET['action']; $something = $_GET['something']; Quote Link to comment https://forums.phpfreaks.com/topic/94887-few-questions/#findComment-486543 Share on other sites More sharing options...
Lamez Posted March 7, 2008 Author Share Posted March 7, 2008 another thing, what exactly are arrays good for? I love using mysql_fetch_array(), but that is the only array I have ever used Quote Link to comment https://forums.phpfreaks.com/topic/94887-few-questions/#findComment-486554 Share on other sites More sharing options...
deadonarrival Posted March 7, 2008 Share Posted March 7, 2008 Arrays are great for storing lists of similar things. eg colours are similar, with just different names: <?php $colours = array("Red","Orange","Yellow","Green","Blue","Indigo","Violet"); print "In the rainbow the colours are:"; foreach ($colours as $key => $value) { print "<li>$value</li>"; } ?> Obviously not too useful, but what if you make an array with all the countries in the world, or states in america, or maybe months in a year. How about car manufacturers? If someone wants to sign up to your site, you can have a drop-down box with a list of all the countries in the world, using a similar loop to the one above. Or you could have the same for car manufacturers. Say you made a website for a garage, and wanted a set of checkboxes <?php $extras = array("pas"=>"Power Assisted Steering","alloys"=>"Alloy Wheels","CD"=>"CD player","SUN"=>"Sun Roof"); print "Which extras do you require?"; foreach($extras as $key => $value) { print "<input type=\"checkbox\" name=\"extras\" value=\"$key\" />$value<br />"; } ?> Would produce Which extras do you require? [ ] Power Assisted Steering [ ] Alloys [ ] CD Player [ ] Sun Roof And if there were 50 extras, it would save you a fair bit of typing making all those input fields. Quote Link to comment https://forums.phpfreaks.com/topic/94887-few-questions/#findComment-486570 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.