SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    645
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Reload a page after choice

    Oops, now I'm tired and just can't make this thing work.

    I have a page showing a specific listing for a chosen week.
    So I made a form where I can pick a week number from a list.
    Then I want my page to reload setting that week. Maybe would be good to make a Session of that as well, so I can remember it.

    This is what I got now, that isn't working of course. But I've been doing stuff for hours now and just gt tired when I got to this.

    PHP Code:
    <form name="form1" id="form1" method="post" action="index3.php?week=<?php echo $row_rs_week['week']?>">
      <select name="week" id="week">
        <?php
    do {  
    ?>
        <option value="<?php echo $row_rs_week['week']?>"<?php if (!(strcmp($row_rs_week['week'], date("W")))) {echo "SELECTED";} ?>><?php echo $row_rs_week['week']?></option>
        <?php
    } while ($row_rs_week mysql_fetch_assoc($rs_week));
      
    $rows mysql_num_rows($rs_week);
      if(
    $rows 0) {
          
    mysql_data_seek($rs_week0);
          
    $row_rs_week mysql_fetch_assoc($rs_week);
      }
    ?>
      </select>
      <input type="submit" name="Submit" value="SHOW" />
    </form>

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    153 Post(s)
    Tagged
    3 Thread(s)
    PHP Code:
    <form name="form1" id="form1" method="post" action="index3.php"> 
      <select name="week" id="week"> 
        <?php 
    do {   
    ?> 
        <option value="<?php echo $row_rs_week['week']?>"<?php if (!(strcmp($row_rs_week['week'], date("W")))) {echo "SELECTED";} ?>><?php echo $row_rs_week['week']?></option> 
        <?php 
    } while ($row_rs_week mysql_fetch_assoc($rs_week)); 
      
    $rows mysql_num_rows($rs_week); 
      if(
    $rows 0) { 
          
    mysql_data_seek($rs_week0); 
          
    $row_rs_week mysql_fetch_assoc($rs_week); 
      } 
    ?> 
      </select> 
      <input type="submit" name="Submit" value="SHOW" /> 
    </form>
    then grab the var from the post array
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    645
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I didn't get that? How do I do that?

    Since I first get a menu with the current week selected.
    But if the user picks another week I wnt to update the week in my list and also set a session to that selection when the page is reloaded.

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    153 Post(s)
    Tagged
    3 Thread(s)
    query the database with the $_POST['week'] variable from the form.

    What does your query look like now?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    645
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Now this is what I got from Dreamweaver

    PHP Code:
    mysql_select_db($db_site_connect$site_connect);
    $query_rs_week "SELECT * FROM tbl_week ORDER BY week ASC";
    $rs_week mysql_query($query_rs_week$site_connect) or die(mysql_error());
    $row_rs_week mysql_fetch_assoc($rs_week);
    $totalRows_rs_week mysql_num_rows($rs_week); 

  6. #6
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    645
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What I actually needs is a form where the user can pick a week number. The current week should be initially selected. Thenwhen the user select a week number it would be great if that selection could be added as a session as well. Then reload the page with the new week selected.

    Does anyone have an idea or solution?

  7. #7
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    HTML Code:
    <form name="form1" id="form1" method="post" action="samepage.php">
    	<select name="week" id="week">
    	<?php
    		if ($_POST['week']) $_SESSION['week_chosen'] = $_POST['week'];
    		elseif (!isset($_SESSION['week_chosen'])) $_SESSION['week_chosen'] = date('W');
    
    		$rs = mysql_query("SELECT * FROM tbl_week_list");
    		while ($row = mysql_fetch_assoc($rs)) {
    			$sel = ($_SESSION['week_chosen'] == $row['week_num']) ? "selected='selected'" : '';
    			echo "<option value='$row[week_num]' $sel>$row[week_num]</option>";
    		}
    	?>
      	</select>
      	<input type="submit" name="Submit" value="SHOW" />
    </form>
    Something like this? Some of the variables don't match but the theory, I think, is what you wanted.

  8. #8
    SitePoint Evangelist pompopom's Avatar
    Join Date
    Feb 2004
    Location
    Huldenberg (Belgium)
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by brad62 View Post
    What I actually needs is a form where the user can pick a week number. The current week should be initially selected. Thenwhen the user select a week number it would be great if that selection could be added as a session as well. Then reload the page with the new week selected.

    Does anyone have an idea or solution?
    if the page needs to reload automatically when the week was selected you need javascript.

    greetz,
    Koen
    The Path of excess leeds to the tower of wisdom (W. Blake)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •