473,405 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Script for multiple selection PHP/MySQL

Hi, I would like to share this small script with you, i was looking for
2 days all over the net and i could find anything like this, thus i
decided to create one, i hope it could help somebody :)

We will create 2 documents:

1) form.html and,
2) handler.php

===================
/* form.html */

<table>
<form action="handler.php" method="post" name="myform">
<tr>
<td><select name="name1[]" multiple>
<option value="value1">Value1</option>
<option value="value2">Value2</option>
<option value="value3">Value3</option></td>
</tr>
<tr>
<td>
<input type="checkbox" name="name2[]" value="value1">Value1<br />
<input type="checkbox" name="name2[]" value="value2">Value2<br />
<input type="checkbox" name="name2[]" value="value3">Value3<br />
</td>
</tr>
<tr>
<td colspan="2">
<input type="reset" name="Reset">&nbsp;<input type="submit"
value="Submit">
</td>
</tr>
</form>
</table>

===================
/* handler.php */

<?php
// Connect to your database

mysql_connect("host", "username", "password") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());

$name1 = $_POST['name1'];
$name2 = $_POST['name2'];

for($name1array=0; $name1array < sizeof($name1); $name1array++)
{
if($name1array < (sizeof($name1)-1)) { $name1_cond = " OR "; }
else { $name1_cond = ""; }
$name1q = $name1q."`name1` LIKE
'".$name1[$name1array]."'$name1_cond";
}

for($name2array=0; $name2array < sizeof($name2); $name2array++)
{
if($name2array < (sizeof($name2)-1)) { $name2_cond = " OR "; }
else { $name2_cond = ""; }
$name2q = $name2q."`name2` LIKE
'".$name2[$name2array]."'$name2_cond";
}

$name1q = "($name1q)";
$name2q = "($name2q)";

$query = "SELECT * FROM `table` WHERE $name1q AND $name2q LIMIT 0,30";

$sql = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($sql)) // Get your results.
{
echo "$row['myrow1']."<br>\n";
echo "$row['myrow2']."<br>\n";
}
?>

Obviously, this has to be adapted to fit your needs, for me, everything
works, i'm actually using sessions with it and no problems so far.

I hope you find this useful :)

SALUX!!!
EOZyo

May 11 '06 #1
0 9662

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: jing_li | last post by:
Hi, you all, I am a newbee for php and I need your help. One of my coworker and I are both developing a webpage for our project using php. We have a copy of the same files in different location...
0
by: Ringwraith | last post by:
Hi! Have anyone ever tried to modify the Gene Cash's Tkinter tree widget (available from http://home.cfl.rr.com/genecash/) so it supports multiple items selection ( selection of multiple files...
2
by: Joe | last post by:
Iıve got a bunch of email addresses in a mysql table. I need a php script that will loop the results of a selection and format them so I can put them in a php mail() function. Iım not too swift...
60
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the...
2
by: dasanchez | last post by:
Hello, everyone. Please bear in mind that I have a very basic knowledge of VBA, but I think I can understand logic. I'm looking for a way to build a module that can help me parse the data in one...
2
by: webfreak | last post by:
hello am a relative newbie to php. am using dreamweaver,php/mysql. i want to populate a mysql field using a multiple selection list menu. i have been to countless forums and so far nothing. can...
3
by: uremog | last post by:
I have a set of of check boxes. onClick, the checkboxes call check_radio and recup_checkbox. the referenced radios function as group selectors. check_radio just unchecks the radios if someone...
6
by: rhaazy | last post by:
I have to create a script to install a database, and one of the tables has about 200 rows of static data... I dont want to have to manually type in 200 insert statements, so is there a better way...
18
by: =?Utf-8?B?TGkgV2VuZw==?= | last post by:
Hi, Is there a way for TreeView to have multiple selections? But I am not talking about its checked boxes. I want a way similar to ListView with MultiSelect = True. So I can use or key and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.