PHP Classes

AJAX List Box: Retrieve MySQL query results into arrays

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 630 All time: 5,033 This week: 57Up
Version License PHP version Categories
ajax-list-box 1.0Freeware3.0Databases
Description 

Author

This is a simple class that can be used to retrieve MySQL query results into arrays.

It can execute a given MySQL SELECT query and retrieves the results into an array.

Picture of Pravin Sonawane
  Performance   Level  

 

Example

<?php
   
include("functions.php");
   
$db = new PHP_fun();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript" type="text/javascript" src="validation.js"></script>
<script language="javascript" type="text/javascript">
    function getCities(id)
    {
        var obj = document.form1;
        if (id != "")
        {
            url = "getCities.php?stateid="+id;
            http.open("GET", url, true);
            http.onreadystatechange = getCitiesResponse;
            http.send(null);
        }
    }
   
    function getCitiesResponse()
    {
        //alert(http.readyState);
        var obj = document.form1;
        if (http.readyState == 4)
        {
            var result = trimString(http.responseText);
            if (result != '' && result != 'undefined')
            {
                clearBox(obj.city);
                obj.city.options[0] = new Option("-City-", "");
                var result_line_arr = result.split("###");
                for (i=0;i<result_line_arr.length;i++)
                {
                    var result_arr = result_line_arr[i].split(":");
                    var code = result_arr[0];
                    var name = result_arr[1];
                    obj.city.options[i+1] = new Option(name, code);
                }
            }
        }
    }
</script>
</head>
<body>
<table width="60%" border="0" cellspacing="0" cellpadding="5">
<form action="" method="post" name="form1">
  <tr>
      <td align="right" class="verdana11">State :</td>
      <td align="left" class="verdana11">
          <select name="state" id="state" onchange="javascript: getCities(this.value);">
            <option value="">-State-</option>
            <?php
                $sql
= "select * from state";
               
$rs = $db->select_row($sql);
                for(
$i=0;$i<count($rs);$i++)
                {
?>
<option value="<?=$rs[$i]['state_id']?>"><?=$rs[$i]['state_name']?></option>
                <?php }
           
?>
</select>
    </td>
  </tr>
    <tr>
      <td align="right" class="verdana11">City : </td>
      <td align="left" class="verdana11">
          <select name="city" id="city" style="width:150px;">
                <option value="">-City-</option>
          </select>
      </td>
    </tr>
</form>
</table>
</body>
</html>


  Files folder image Files (5)  
File Role Description
Accessible without login Plain text file db.sql Data MySql Database File
Plain text file functions.php Class Class
Accessible without login Plain text file getCities.php Example Database Request File
Accessible without login Plain text file index.php Example Main File
Accessible without login Plain text file validation.js Data Javascript File

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:630
This week:0
All time:5,033
This week:57Up
User Comments (1)
very amazing script
13 years ago (arunachalam)
70%StarStarStarStar