Script for multiple selection PHP/MySQL



    On one of my servers, $_SERVER['PHP_SELF'] == '/path/to/script.php', while $_SERVER['REQUEST_URI'] == '/path/to/'. On another server, they're equal - they're both of the form '/path/to/script.php'. My question is... why, on one of my servers, is REQUEST_URI not including the filename? Shouldn't it? The server encountering the problem is running Abyss Web Server - the server that's not is running Apache, if that makes a difference.
  • 2. Displaying Errors Question
    Hi all. I have a personal site I've been building, and essentially I have a 'flag' variable at the begining of each script that is set to true or false. True turns on error display via: So, this was all working perfectly until the last week or so. Now, if anything is even the slightest incorrect with the script, instead of displaying error messages on the screen a blank screen is returned and I have to go to the error.log to see what's happening. Two things that I can think of off the top of my head that have changed since then. I have changed all my scripts to use ' instead of " for my echo statements (where possible), and I have switched all my included files to be 'require' instead of 'include', as the really are required components... Has anyone else run into anything similar? Very strange behavior... not sure what is going on! Thanks!
  • 3. Video stream
    I'm not sure this is the right forum, but it seems the best to my question, sorry if it's not a strict PHP question. I have a webserver. The same server machine receive from the internet a multimedia stream, which composed from two separate RTP streams, one contains the video, the second contains the audio. I would like to build a webpage the will embed that multimedia service. Some kind of realplayer or another known (to web browsers) format. What is the (simplest) way to do it? Thanks, Uri
  • 4. php and :: usage
    Hello. I have a class controlling the content shown in my page. class ContentController { function GetContent() {get the last content published in db} public static function LastC {returb $this->GetContent();} } Now in my index page I don't want to initiliaze a new instance of ContentController, I just want to call ContentController::LastC() But it says: Fatal error: Using $this when not in object context in ContentController.php on line 232 Since LastC and GetContent is functions inside the same class why can't I call them? What's the use of :: when you reference a function and not a class' variable. thanks

Script for multiple selection PHP/MySQL

Postby EOZyo » Sat, 13 May 2006 03:10:46 GMT

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 */

  <form action="handler.php" method="post" name="myform">
      <td><select name="name1[]" multiple>
      <option value="value1">Value1</option>
      <option value="value2">Value2</option>
      <option value="value3">Value3</option></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 colspan="2">
     <input type="reset" name="Reset"> <input type="submit"

/* handler.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

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

$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 :)


Similar Threads:

1.Passing multiple selections to a MySql query

Hello All,

Can someone help me with a problem I am having?  I have a form which
has a multi-select list where the user can select more than one
company name from a list and I need to pass those selections to a
MySQL query for a report.

How do I get the list of items passed to my new page and include those
in my MySQL statement?

Any and all help is appreciated.


2.selection criteria spread on multiple rows.


I'm having the following problem. I have a table that contains
information about books people read, i.e. each row has two columns,
people id and book id.
I need to do the following query: retrieve the list of all people that
read ALL the books in a given list, e.g. all the people that read book
X and book Y and book Z.
Tu further complicate the situation, an extended query also include an
exclusion crieteria, i.e. a list of books that the user should not
have read.

I really have no clue on how to approach this.
Any help will be much appricated.


3.List Multiple Selection to MySQL

4.php/mysql results on multiple pages script

I'm using the following script to show 10 records per page, but where the 
pagecount, next & previous page links should be, I'm getting 'Pages :::'. There 
are 20 records in that database that I am trying to access. Whats wrong with 
the script?

 $host = 'xx';
 $username = 'xx';
 $password = 'xx';
 $database = 'xx';

 $conn = mysql_connect($host,$username,$password) or die("Cannot connect");
 mysql_select_db($database) or die("Cannot select db");

 /* Sending query to MYSQL */
 $query1 = "select * from blogs";

 // ==============
 // Configuration
 // ==============
 $perpage = "10"; // How many results to show per page
 $pageshow = "10"; // How many pages you want to show in the direction bar

 $records = mysql_fetch_array(mysql_query($query1));
 $page_num = ceil($records[results] / $perpage);
 $page = ($page) ? $page : 1;
 $vstart = $perpage * ($page-1);
 $page_start = floor(($page-1)/ $pageshow ) * $pageshow ;
 $page_end = $page_start + $pageshow;
 for ($p=$page_start+1 ; ($p <= $page_end) && ($p = $page_num)  ; $p++ )
 if ($page == $p) {
 $direct_bar .= "<b>$p</b> ";
 } else {
 $direct_bar .= "<a href='$PHP_SELF?page=$p'>$p</a> ";
 if ($records[results] > $vstart+$perpage ) {
 $next_list = "<a href='PHP_SELF?page=$next_p'>Next >></a> \n";
 if ($page>1) {
 $prev_list="<a href='PHP_SELF?page=$prev_p'><< Prev</a>\n";

 // Below will show the page numbers
 //print >>>EOF;
 print "Pages:";
 print $prev_list;
 print ":";
 print $direct_bar; 
 print ":";
 print $next_list;
 // EOF

 /* Sending query to MYSQL */
 $query = "select * from blogs limit $vstart,$perpage";
 $query_result = mysql_query($query) or die("<b>MySQL Error:</b> " . 

 print "<table>";

 if (mysql_numrows($query_result) <> 0){
 while ($i < $num) {
 echo "<tr><td width='45px' valign='top'>$day $month</td><td><a 
 print "</table>";

 // Below will show the page numbers
 //print >>>EOF
 print "Pages:";
 print $prev_list;
 print ":";
 print $direct_bar; 
 print ":";
 print $next_list;

5.Drop Down Lists Multiple Selections in PHP

Hi all...

How do I get the MULTIPLE results from a drop down list box form that
handles multiple?

<selection name="test" size="10">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>

echo $_REQUEST["test"];  seems to only display the LAST selection that
you chose if you selected all of them.

Any thoughts?


6. select lists (display multiple selections) - PHP

7. #RESOLVED# select lists (display multiple selections) - PHP

8. Mail values from a List with Multiple Selections with PHP

Return to php


Who is online

Users browsing this forum: No registered users and 33 guest