Jump to content

Variable Issues Using A Form


fleabel

Recommended Posts

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\" /]

[code]
<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>';
            };[/code]
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.