Login   Register  
PHP Classes
elePHPant
Icontem

File: complex_example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Arturs Sosins  >  Phones Complete class  >  complex_example.php  >  Download  
File: complex_example.php
Role: Example script
Content type: text/plain
Description: Interaction with more complex search form
Class: Phones Complete class
Query information of devices from Phones Complete
Author: By
Last change: credits changed
Date: 3 years ago
Size: 4,050 bytes
 

Contents

Class file image Download
<?php
/************************************************************* 
 * This script is developed by Arturs Sosins aka ar2rsawseen, http://webcodingeasy.com 
 * Fee free to distribute and modify code, but keep reference to its creator 
 * 
 * This class can create user friendly interface to browse 
 * PhonesComplete user generated mobile phone database
 * and perform searches for different phone models 
 * based on parameter values using PhonesComplete API
 * 
 * For more information, examples and online documentation visit:  
 * http://webcodingeasy.com/PHP-classes/Phones-Complete-class
**************************************************************/

//declaring class instance
include("./mobile.class.php");
$mob = new mobile_phones();

if(isset(
$_POST['search']))
{
    
//excluding post search data from request url
    
$ex[0] = 'search';
    
    
//making url from post data including array from to values
    
$url $mob->make_url($_POST$ex);
    
//performing search using constructed url
    
$phones $mob->search($url);
    
//outputing result
    
foreach($phones as $phone)
    {
        echo 
"<p><a href='?model=".$phone['cached_slug']."'>".$phone['brand']." ".$phone['name']."</a></p>";
    }
}


if(isset(
$_GET['model']))
{
    
//getting information about specific model using cached_slug parameter
    
$arr $mob->get_phone($_GET['model']);
    echo 
"<pre>";
    
print_r($arr);
    echo 
"</pre>";
}
/******************************************************/
/*arrays for user interface form*/
//array with paremeters which to exclude from form
$exclude = array("age""cached_slug""created_at""id""phone_image_content_type""phone_image_file_name""phone_image_file_size""phone_image_updated_at""updated_at""phone_image_url""phone_image_thumb_url""phone_image_medium_url");

//array with paremeters for select user input
$select = array("bluetooth""brand""camera_flash""gps");

//array with paremeters for radio buttons user input
$radio = array("a2dp""edge""edr""frequency_1800""frequency_1900""frequency_2100""frequency_850""frequency_900""full_keyboard""hsdpa""gprs""lte""mini_jack""radio""touchscreen""umts""usb""wlanb""wlang");

//array with parameters for from to length
$from_to = array("width""depth""height""internal_memory""standby_time""talk_time""weight");
/******************************************************/

//creating form
$arr $mob->get_param_list();
echo 
"<form action='' method='post'>";
echo 
"<table border='1' cellpadding='5'>";
foreach(
$arr as $key => $val)
{
    
//excluding unwanted elements
    
if(!in_array($val$exclude))
    {
        echo 
"<tr>";
        
//creating select elements
        
if(in_array($val$select))
        {
            echo 
"<td>".$val."</td><td><select name='".$val."'>";
            echo 
"<option value=''></option>";
            
$parvals$mob->get_all_values($val);
            foreach(
$parvals as $pv)
            {
                echo 
"<option value='".$pv."'>".$pv."</option>";
            }
            echo 
"</select></td>";
        }
        
//creating radio buttons
        
else if(in_array($val$radio))
        {
            echo 
"<td>".$val."</td><td>";
            echo 
"<p><input type='radio' name='".$val."' value=''/> whatever</p>";
            
$parvals$mob->get_all_values($val);
            foreach(
$parvals as $pv)
            {
                echo 
"<p><input type='radio' name='".$val."' value='".$pv."'/> ".$pv."</p>";
            }
            echo 
"</td>";
        }
        
//creating from to values search input
        
else if(in_array($val$from_to))
        {
            echo 
"<td>".$val."</td>";
            echo 
"<td>from: <input type='text' name='".$val."[]' size='4'/> to: <input type='text' name='".$val."[]' size='4'/></td>";
        }
        
//else simple textboxes for string search
        
else
        {
            echo 
"<td>".$val."</td><td><input type='text' name='".$val."' ";
            if(isset(
$_POST[$val]))
            {
                echo 
"value='".$_POST[$val]."'";
            }
            echo 
"/></td>";
        }
        echo 
"</tr>";
    }
}
echo 
"<input type='hidden' name='search'/>";
echo 
"<tr><td colspan='2' align='center'><input type='submit' value='Search'/></td></tr>";
echo 
"</table>";
echo 
"</form>";
    
?>