Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Remote File for a Drop-Down Menu, in a search form
Old 02-06-2006, 01:05 PM Remote File for a Drop-Down Menu, in a search form
Junior Talker

Posts: 2
Trades: 0
Im pretty new to PHP coding. I've been working with a script that is used to search through member profiles. I need to add a drop-down field to the search form - but I'm not exactly sure what to do.

An example of the current code ,that is used for a field similar to what I want to add, is this

PHP Code:
             $TXT[12] = file("".$VAR[5]."/inc/txt/country.txt");
                    
$TXT[14] = "";
                    foreach (
$TXT[12] as $TXT[13])
                    {
                        
$TXT[13] = trim($TXT[13]);
                        
$SLT[4] = "";
                        if (isset(
$_GET['location'])) { if ($_GET['location'] == $TXT[13]) { $SLT[4] = " selected"; } } 
Basically, all I understand, thus far, with this section of coding is where the file it is retrieving the drop-down information is located. I don't fully understand the use of the numbers in the $TXT commands.
phirehawk is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-07-2006, 04:38 AM Re: Remote File for a Drop-Down Menu, in a search form
digitalfields's Avatar
Skilled Talker

Posts: 50
Trades: 0
As for creating a drop menu to search it would help to know what you want in the drop down menu, like is it dynamic data or fixed? And how is it stored, file or database?

As for your example im a little confused by it.

PHP Code:
$TXT[12] = file("".$VAR[5]."/inc/txt/country.txt");
                    
$TXT[14] = "";
                    foreach (
$TXT[12] as $TXT[13])
                    {
                        
$TXT[13] = trim($TXT[13]);
                        
$SLT[4] = "";
                        if (isset(
$_GET['location'])) { if ($_GET['location'] == $TXT[13]) { $SLT 
Usually I would load the file to $TXT like this:

PHP Code:
$TXT file("".$VAR[5]."/inc/txt/country.txt"); 
Which would put the contents of country.txt into an array.

So if in country.txt you have:
Code:
USA
United Kingdom
Canada
$TXT would equal the following:
$TXT[0] = "USA";
$TXT[1] = "United Kingdom";
$TXT[2] = "Canada";

Basically the numbers are the index in the array. By using [] you are accessing an item in an array. If you dont know what an array is, its a collection of whatever type you assign, eg int, string, object. PHP isnt fussy about object types. Think of it like a bookcase, at the left is book[0] on the right is book[10], book[0] might equal "harry potter", book[10] = "something else".

To clean up your existing code I would use the following:
PHP Code:
$TXT file("".$VAR[5]."/inc/txt/country.txt");
         
$TXT[14] = ""// maybe an entry you dont want?
          
foreach ($TXT as $location)
                    {
                        
$location trim($location);
                        
$SLT[4] = ""// dont know what that is?
                        
if (isset($_GET['location'])) { if ($_GET['location'] == $location) { $SLT[4] = " selected"; } } 
Hope that helps.
__________________
Digital Fields - Web Design

Please login or register to view this content. Registration is FREE
digitalfields is offline
Reply With Quote
View Public Profile Visit digitalfields's homepage!
 
Old 02-07-2006, 01:38 PM Re: Remote File for a Drop-Down Menu, in a search form
Junior Talker

Posts: 2
Trades: 0
The information for the drop menu is coming from a static text file.
I was looking back through the code (where I pulled the above portion from) and found out what that the $STL is supposed to be an array
PHP Code:
    $TXT = array();
    
$SLT = array(); 
For the first piece of coding this secions come before it in the PHP file

PHP Code:
                        if (isset($_GET['location']))
                        {
                            if (
$_GET['location'] != ''
                            {
                                
$LINKS .= "&location=".$_GET["location"]."";
                                
$_GET['location'] = str_replace("_"," ",$_GET['location']);
                                
$DATABASE .= " AND `location` = '$_GET[location]'";
                            }
                        } 
and

this is how the author printed it out within the form

PHP Code:
<table style="width:100%;">
<
tr>
<
td style="width:25%;font-size:8pt;" class="color">

<
label for="location"><u>L</u>ocation:</label>
    <
div style="padding-top:5px;padding-left:5px;">
        <
select name="location" id="location" style="width:120px;">
        <
option value="">Any</option>
$TXT[14] </select>
    </
div
Maybe that'll make a little more sense; as to what is happening withe file.
phirehawk is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Remote File for a Drop-Down Menu, in a search form
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.20330 seconds with 12 queries