a2bardeals Posted June 14, 2006 Share Posted June 14, 2006 So I have hit a wall. I have two problems.First,I have two lists that are dependent on variables. a daily events list (daily.php) and a monthly events list (monthly.php) they both have variables to set which day or month to view.If i am looking at monthly.php i can use html to pass variables just by<a href="monthly.php?mo=jan">Jan</a>ormanually typing in the URLhowever when i try to set a default value for $mo in monthly.phpe.g. $mo = date('M') // to auto detect todays datei cant change the variable via the URL or a link to view other months or daysSecond,I have a page called display.php which includes the two files together one on top of the other<? include 'daily/daily.php'; ?><br><? include 'monthly/monthly.php';?>If i use links on both pages to pass variablesthe URL comes out like[a href=\"http://www.domain.com/mysql/monthly.php?mo=jan\" target=\"_blank\"]http://www.domain.com/mysql/monthly.php?mo=jan[/a]and i get a File Not Found becuase monthly is in a higher directory anyways.get ok results when i use the GET method of a form. aka selection box with submit buttonhowever any information that was kept in the $today variable in the URL goes away.So is there a way to keep one variable up and just replace the value of the other one?any help will be very helpful Quote Link to comment https://forums.phpfreaks.com/topic/12011-variable-in-url-help/ Share on other sites More sharing options...
kenrbnsn Posted June 14, 2006 Share Posted June 14, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]however when i try to set a default value for $mo in monthly.phpe.g. $mo = date('M') // to auto detect todays datei cant change the variable via the URL or a link to view other months or days[/quote]Please post the code that's not working for this.Actually, we need to see most of your scripts, since your explanations really don't make much sense.Ken Quote Link to comment https://forums.phpfreaks.com/topic/12011-variable-in-url-help/#findComment-45696 Share on other sites More sharing options...
aebstract Posted June 14, 2006 Share Posted June 14, 2006 I don't know what you want on your second question, but for your first one try this out:[code]if (!isset($mo)){$mo = "date('M')";}[/code]this way if you set it by the url it will not set it to current day, but if it isn't set by url it will set it to the auto. Quote Link to comment https://forums.phpfreaks.com/topic/12011-variable-in-url-help/#findComment-45702 Share on other sites More sharing options...
a2bardeals Posted June 14, 2006 Author Share Posted June 14, 2006 ok heres the code so far...The Daily List (daily/list.php)[code]<font face="arial, helvetica" size="2"><? @mysql_connect($server,$username,$password); @mysql_select_db($database);echo '<b>Specials For:</b> ';echo $today;echo '<br><br>';$result = mysql_query("SELECT link, day, deal FROM daily WHERE day = '".$today."'");if (!$result) {echo 'Could not run query: ' . mysql_error();exit;}while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf('%s<br>%s<br><br>', $row[0], $row[2]);}mysql_free_result($result);?>[/code]Here is the Monthly List (monthly/monthylist.php)[code]<font face="arial, helvetica" size="2"><? @mysql_connect($server,$username,$password); @mysql_select_db($database);$file = basename($_SERVER['PHP_SELF']); echo 'Deals For:';echo $mo;echo '<br><br>';$result = mysql_query("SELECT link, month, deal FROM monthly WHERE month = '".$mo."'");if (!$result) {echo 'Could not run query: ' . mysql_error();exit;}while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf('%s<br>%s<br><br>', $row[0], $row[2]);}mysql_free_result($result);?>[/code]and here is the dislplay (display.php) ***in lower directory[code]<html><head></head><body><? $file = basename($_SERVER['PHP_SELF']);echo 'Daily Specials <br>';?><form action=<? echo $file; ?> method="get"> <select name=today><option selected>Select Day...</option> <option value=Mon>Monday</option> <option value=Tue>Tuesday</option> <option value=Wed>Wednesday</option> <option value=Thu>Thursday</option> <option value=Fri>Friday</option> <option value=Sat>Saturday</option> <option value=Sun>Sunday</option> </select><input type=Submit value=View!></form><?include "daily/list.php"; ?><br><hr><br>Monthly Specials<br><form action=<? echo $file; ?> method="get"> <select name="mo"><option selected>Select Month...</option> <option value="Jan">January</option> <option value="Feb">February</option> <option value="Mar">March</option> <option value="Apr">April</option> <option value="May">May</option> <option value="Jun">June</option> <option value="Jul">July</option> </select><input type="Submit" value="View!"></form><br><?php include "monthly/monthlylist.php";?></body></html>[/code]i also have an index.php file that detects the day and week redirects to display by doing this:[code]<html><head><title>Hold On..</title><?$dday = Date('D');$monthy = Date('M');?></head><body><script>location = "display.php?today=<? echo $dday; ?>&mo=<? echo $monthy; ?>";</script>Getting Deals For <?echo $Monthly;echo $monthy; ?><center>Hold On!</a></body></html>[/code]but there has to be an easier way to load the variables in the URL on the load of display.php without having to redirect right?basically when the user is looking at display.php and chages the day to view i want the mo=Jun to stay the same in the URLakapage is loaded as[a href=\"http://www.domain.com/display.php?today=Tue&mo=Jun\" target=\"_blank\"]http://www.domain.com/display.php?today=Tue&mo=Jun[/a]user selects wednesday from the list and URL changes to[a href=\"http://www.domain.com/display.php?today=Wed&mo=Jun\" target=\"_blank\"]http://www.domain.com/display.php?today=Wed&mo=Jun[/a]rather right now it goes to[a href=\"http://www.domain.com/display.php?today=Wed\" target=\"_blank\"]http://www.domain.com/display.php?today=Wed[/a]and the monthy list of events goes away...PLEASE HELP! my brain hurts Quote Link to comment https://forums.phpfreaks.com/topic/12011-variable-in-url-help/#findComment-45710 Share on other sites More sharing options...
kenrbnsn Posted June 15, 2006 Share Posted June 15, 2006 Please describe exactly what you are trying to do with these scripts. Do not refer to the scripts, but just a written explanation. I think I can figure it out and if my guess is correct, there is a much easier way of doing this, but by see what you are trying to do I should be able to help you.Ken Quote Link to comment https://forums.phpfreaks.com/topic/12011-variable-in-url-help/#findComment-45759 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.