Jump to content


Photo

variable in URL HELP!!!


  • Please log in to reply
4 replies to this topic

#1 a2bardeals

a2bardeals
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts
  • LocationAnn Arbor, MI

Posted 14 June 2006 - 07:33 PM

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>
or
manually typing in the URL

however when i try to set a default value for $mo in monthly.php
e.g. $mo = date('M') // to auto detect todays date
i cant change the variable via the URL or a link to view other months or days

Second,

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 variables
the 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 button

however 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

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 14 June 2006 - 07:45 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]however when i try to set a default value for $mo in monthly.php
e.g. $mo = date('M') // to auto detect todays date
i 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

#3 aebstract

aebstract
  • Members
  • PipPipPip
  • Advanced Member
  • 1,105 posts

Posted 14 June 2006 - 08:04 PM

I don't know what you want on your second question, but for your first one try this out:

if (!isset($mo)){
$mo = "date('M')";
}

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.

There is an area of the mind that could be called unsane, beyond sanity, and yet
not insane. Think of a circle with a fine split in it. At one end there's
insanity. You go around the circle to sanity, and on the other end of the
circle, close to insanity, but not insanity, is unsanity.


#4 a2bardeals

a2bardeals
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts
  • LocationAnn Arbor, MI

Posted 14 June 2006 - 08:35 PM

ok heres the code so far...

The Daily List (daily/list.php)
<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);


?>

Here is the Monthly List (monthly/monthylist.php)
<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);


?>

and here is the dislplay (display.php) ***in lower directory
<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>

i also have an index.php file that detects the day and week redirects to display by doing this:
<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>

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 URL
aka
page 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

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 15 June 2006 - 12:02 AM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users