General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old January 10th, 2003, 05:00 PM
steve55 steve55 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: UK
Posts: 44 steve55 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to steve55 Send a message via Yahoo to steve55
Question Doh!

I have just got a drop down menu working - populated by fields in my mysql dbase and have a resulting results page working as well! (I'm new to this)

But I need to add in a ALL option in my drop downs. Currently the choice is

<select>usa</select>
<select>uk</select>
<select>australia</select>

So my results have to contain one of the above options - I don't know how to add in an option for ALL and how to code it...

My current script for the drop down is as follows:-

<?php
include "config.php";

$db = mysql_connect ($Host, $User, $Password);
mysql_select_db ($DBName) or die ("Cannot connect to database");
/* We have now connected, unless you got an error message */

$SQL = "SELECT id, areas, towns, zip FROM houses";
$myResult = mysql_query($SQL, $db);
while(list($id, $areas, $towns, $zip) = mysql_fetch_array($myResult))
{
$menuOne .= "<option value=\"$areas\">$areas</option>\r";
$menuTwo .= "<option value=\"$towns\">$towns</option>\r";
$menuThree .= "<option value=\"$zip\">$zip</option>\r";
$menuFour .= "<option value=\"$id\">$id</option>\r";
}
mysql_close($db);

echo "<form action=\"srchtest1.php\" method=\"POST\">\r";
echo "<select name=\"fieldOne\">$menuOne</select>\r";
echo "<select name=\"fieldTwo\">$menuTwo</select>\r";
echo "<select name=\"fieldThree\">$menuThree</select>\r";
echo "<input type=\"Submit\" name=\"Submit\" value=\"Submit\">\r";
"<INPUT TYPE=\"HIDDEN\" NAME=\"id\" value=$menuFour>\r";
echo "</form>\r";


?>

Any help would be appreciated.
Thanks

Reply With Quote
  #2  
Old January 10th, 2003, 06:12 PM
kylie kylie is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 19 kylie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
steve,

Do you mean you want to be able to select all the countries in the list?

Firstly you will need to add the following code to the select box

multiple size="5"

then you will need to run some javascript that will go though the array of option elements and select each one.

Reply With Quote
  #3  
Old January 11th, 2003, 05:06 AM
steve55 steve55 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: UK
Posts: 44 steve55 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to steve55 Send a message via Yahoo to steve55
Basically if the user leaves drop down box it will 'select' all from that particular menu, as you correctly point out.

However I still don't have a clue how to do this...!

Reply With Quote
  #4  
Old January 11th, 2003, 05:16 AM
Jeb. Jeb. is offline
"l33t? What's l33t?"
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 51 Jeb. User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to Jeb.
Steve,

Perhaps I'm totally off-base here (wouldn't surprise me ), but why don't you check to see if a value is passed from the drop down box? If a value is not passed, you use a default value - which is every value in that box.

Or, you might have an "all" option in the box, and check for this value with the script the form is pointed to - if it exists, you simply grab all the values from MySQL again and use them. Otherwise, you use the value the user passed.

Just a thought

Peace,
Jeb.
__________________
Jeb.

AIM: JebediahMc - PM Me - E-Mail Me


Reply With Quote
  #5  
Old January 11th, 2003, 05:36 AM
steve55 steve55 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: UK
Posts: 44 steve55 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to steve55 Send a message via Yahoo to steve55
This is my results page - any ideas?




<?

include "config.php";

if ($Submit) // perform search only if a string was entered.
{
$db = mysql_connect ($Host, $User, $Password);
mysql_select_db ($DBName) or die ("Cannot connect to database");

$srch="%".$Submit."%";
$query = "select * from houses WHERE areas LIKE '$fieldOne' || towns LIKE '$fieldTwo' || zip LIKE '$fieldThree' ";

$result = mysql_db_query("stevesims", $query);

if ($result)
{
echo "Here are the results:<br><br>";
echo "<TABLE border = '1' cellspacing = '0' cellpadding ='0' width = '90%' align='center'><tr>
<td align=center bgcolor=#0099ff><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">URL</font></td>
<td align=center bgcolor=#0099ff><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">Area</font></td>
<td align=center bgcolor=#0099ff><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">Town</font></td>
<td align=center bgcolor=#0099ff><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">Post Code</font></td>
</tr>";

while ($r = mysql_fetch_array($result)) { // Begin while

$areas = $r["areas"];
$towns = $r["towns"];
$zip = $r["zip"];
$id = $r["id"];
echo "<tr>
<td><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\"><A HREF=\"http://www.stevesims.com/dummy/view2c.php?id=$id\"><b>View Property</b></A></font></td>
<td><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">$areas</font></td>
<td><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">$towns</font></td>
<td><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">$zip</font></td></tr>
";
} // end while
echo "</table>";
} else { echo "problems...."; }
} else {
echo "Search string is empty. <br> Go back and type a string to search";
}

?>

Reply With Quote
  #6  
Old January 11th, 2003, 11:24 AM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
PHP Code:
/*******************************
Check the incoming and bind
scalars appropriatly.
*******************************/
if ( !empty( $_POST['a'] ) ) $a $_POST['a']; else $a '%';
if ( !empty( 
$_POST['b'] ) ) $b $_POST['b']; else $b '%';
if ( !empty( 
$_POST['c'] ) ) $c $_POST['c']; else $c '%';
/*******************************
Your DB Query
*******************************/
$query "select * from houses WHERE areas LIKE '$a' || towns LIKE '$b' || zip LIKE '$c' "


Using wildcards we could build the query as so. On your select menus, have the default value (Select One) set to '0'. So, if $_POST['a'] comes into the script as '0', it is considered empty - so we can bind $a to '%' or wildcard matching everything.
__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
  #7  
Old January 15th, 2003, 08:58 AM
steve55 steve55 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: UK
Posts: 44 steve55 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to steve55 Send a message via Yahoo to steve55
Thanks, but I'm still having problems, probably because I'm new to this rather than anything else.

I have got the drop down menus & results page working, but currently it pulls everything out the database and puts it into the drop downs, like so

<select>london</select>
<select>New York</select>
<select>Toronto</select>
etc.....

So the user HAS TO select a city.

- I would like to change it to this,

<select>CHOOSE A CITY</select>
<select>london</select>
<select>New York</select>
<select>Toronto</select>
etc...


..SO if the user leaves the drop down as CHOOSE CITY, the results page displays ALL CITIES as opposed to say just london, or just New York, or just Toronto.

I just don't know how to do it..

Reply With Quote
  #8  
Old January 15th, 2003, 09:49 AM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
PHP Code:
/********************************************
Select Menu
********************************************/
function select_menu_city$_nam )
    {
    
$_sel '<select name="' $_nam '">';
    
$_sel .= '<option selected>Choose A City</option>';
    
$_qry mysql_query"SELECT id, city FROM cities" ); 
    while ( 
$_dat mysql_fetch_array$_qry ) ) {
        
$_sel .= '<option value="' $_dat['id'] . '">' $_dat['city'] . '</option>' "\n";
    }
    
$_sel .= '</select>';
    return( 
$_sel );


Ok - lets break the above function down:

Line 1: The opening tags of the select menu where $_nam is the name you are identifying the menu as (fed to the function on the function call).
Line 2: The first option in the menu (and the defualt). No value is givin to this.
Line 3: Your query to grab the list of cities from your DB. Each city in your DB needs an identifying id.
Line 4: The start of the data loop from your DB.
Line 5: The actual option values and corresponding names that will be in the menu.
Line 6: Close of the loop.
Line 7: The closing HTML tag of the select menu.
Line 8: Returns the HTML block into your current script namespace.

----------------------------------------

Now, to call the function and build the menu, place the code below in your page where you want the menu to appear ->
PHP Code:
echo select_menu_city'cities' ); 

Now, make sure that you also include the function at the top of your page.

The initial select option is left blank so if the user does'nt choose a city, the blank entry would mean your wildcard search.

Reply With Quote
  #9  
Old January 15th, 2003, 10:45 AM
steve55 steve55 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: UK
Posts: 44 steve55 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to steve55 Send a message via Yahoo to steve55
Thanks for your patience and help.

Reply With Quote
  #10  
Old January 15th, 2003, 11:13 AM
steve55 steve55 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: UK
Posts: 44 steve55 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to steve55 Send a message via Yahoo to steve55
That works thank you - but I still need to add it a form action and button to proceed to the results page...

Also is there any way of telling the script to only list duplicate entries in the menu once..

The menu is for a dummy property database I have set up to teach myself php etc.... the menu currently looks like this,

<select>Choose a City</select>
<select>New York</select>
<select>New York</select>
<select>London</select>
<select>Toronto</select>
<select>New York</select>

This is because I have entered in three properties in the city of New York, obviously the more I entries I add for New York the more times it will appear in the menu...

Reply With Quote
  #11  
Old January 15th, 2003, 11:58 AM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Ok, the form action and button is in your HTML, so no need to go over that. To get rid if the duplicate entries in your menu, adjust your query to this ->
PHP Code:
 $_qry mysql_query"SELECT DISTINCT id, city FROM cities" ); 

The DISTINCT tells mysql to return non-duplicate entries or only one entry for each multiple entry....

Reply With Quote
  #12  
Old January 15th, 2003, 04:47 PM
steve55 steve55 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: UK
Posts: 44 steve55 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to steve55 Send a message via Yahoo to steve55
Thank you, for your help - much appreciated and definitely a weight off my mind.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Doh!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |