Jump to content

variable in URL HELP!!!


a2bardeals

Recommended Posts

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
Link to comment
Share on other sites

[!--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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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 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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.