Jump to content


Photo

Variable Issues Using A Form


  • Please log in to reply
1 reply to this topic

#1 fleabel

fleabel
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 15 June 2006 - 11:10 PM

I have a little form with two drop down menus. These two selections are used to pull required information from a flat file database. I have then integrated a piece of script that sorts the columns. This all works beautifully if I bipass the form and just hard code the two variables, however, if I use the form to set the varibles it works great to get the initial information but as soon as i try to sort it the info disappears. I have enough sense to know that this is because it is 'loosing' the varibles from the form but I have absolutely no idea how to fix it.

I think the problem has something to do with the page being reloaded when you click on the header of the comlumn you want to sort by. But I could be completely off track.

If someone can save me that would be much appriated [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

<tr class="contboxtxt" bgcolor="#CCCCCC">
    <th><a class="contboxtxt" href="?"><strong>Date</strong></th>
    <th><a class="contboxtxt" href="?month"><strong>Month</strong></th>
    <th><a class="contboxtxt" href="?year"><strong>Year</strong></th>
    <th><a class="contboxtxt" href="?sport"><strong>Sport</strong></th>
    <th><a class="contboxtxt" href="?event"><strong>Event</strong></th>
    <th><a class="contboxtxt" href="?venue"><strong>Venue</strong></th>
    <th><a class="contboxtxt" href="?city"><strong>City</strong></th>
    <th><a class="contboxtxt" href="?state"><strong>State</strong></th>
</tr>';

    $searchOption = $_POST['searchMenu'];
    $selectOption = $_POST['selectedMenu'];

    $fp = 'events_database.txt'; 
    $tmp_array = file($fp);
    $row = 0;

    switch($searchOption){
        case 'state':
            foreach ($tmp_array as $value) {
                $curr = explode("|", $value);
                // check for whatever you want here
                if (trim($curr[7]) == $selectOption){
                    if ($sortby == 'date') $sortkey = strtolower($curr[0]);
                    if ($sortby == 'month') $sortkey = strtolower($curr[1]);
                    if ($sortby == 'year') $sortkey = $curr[2];
                    if ($sortby == 'sport') $sortkey = strtolower($curr[3]);
                    if ($sortby == 'event') $sortkey = strtolower($curr[4]);
                    if ($sortby == 'venue') $sortkey = strtolower($curr[5]);
                    if ($sortby == 'city') $sortkey = strtolower($curr[6]);
                    if ($sortby == 'state') $sortkey = strtolower($curr[7]);
                    $col[$row] = array($sortkey, $curr[0], $curr[1], $curr[2], $curr[3], $curr[4], $curr[5], $curr[6], $curr[7]);
                    $row++;
                };
            };
            break;
        case 'city':
            bassically same code as above
        case 'sport':
            bassically same code as above
        case 'month':
            bassically same code as above
        default:
            break;
    };
    
            sort($col); 
            reset($col); 
  
            $arrays = count($col) - 1; 
  
            $loop = -1; 
            while ($loop < $arrays) { 
                $loop++; 
                echo ' 
                    <tr> 
                        <td class="contboxtxt">'.$col[$loop][1].'</td> 
                        <td class="contboxtxt">'.$col[$loop][2].'</td> 
                        <td class="contboxtxt">'.$col[$loop][3].'</td> 
                        <td class="contboxtxt">'.$col[$loop][4].'</td> 
                        <td class="contboxtxt">'.$col[$loop][5].'</td> 
                        <td class="contboxtxt">'.$col[$loop][6].'</td> 
                        <td class="contboxtxt">'.$col[$loop][7].'</td>
                        <td class="contboxtxt">'.$col[$loop][8].'</td>  
                    </tr>'; 
            };


#2 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 16 June 2006 - 08:00 AM

you should use the $_GET method to pass on the information you are looking at, the _POST variables are lost otherwise
z..z..z..z..z..z..z..z..




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users