Create a model name list

Integrating Tera-WURFL in your applications.

Create a model name list

Postby frblanc » Wed Apr 28, 2010 9:30 am

Hello,

I would like to create a model name list. Could you help me to make that ?

Regards,

François
frblanc
 
Posts: 1
Joined: Wed Apr 28, 2010 9:25 am

Re: Create a model name list

Postby kamermans » Sat May 01, 2010 8:18 am

You will have to iterate through all the devices and pull out their model name. Here's how to get them all in an array:
Code: Select all
<?php
$brand_names = array();
$db = new mysqli($host,$user,$pass,$db);
$res = $db->query("SELECT * FROM TeraWurflMerge");
while($row = $res->fetch_assoc()){
   $capabilities = unserialize($row['capabilities']);
   $brand_names[] = $capabilities['product_info']['brand_name'];
}
sort($brand_names,SORT_STRING);
?>
Thanks,

Steve Kamerman
Tera-WURFL Author
COO of ScientiaMobile

IMPORTANT ANNOUNCEMENT! Tera-WURFL and WURFL have joined forces! We have launched ScientiaMobile to provide commercial support for our device detection solutions.

Tera-WURFL.com | Device Explorer
kamermans
Site Admin
 
Posts: 323
Joined: Wed Mar 10, 2010 12:06 pm
Location: Fort Worth, TX

Re: Create a model name list

Postby kamermans » Sat May 01, 2010 8:26 am

Sorry, just realized you wanted [b]Brand + Model Names[b/], this should work:
Code: Select all
<?php
$model_names = array();
$db = new mysqli($host,$user,$pass,$db);
$res = $db->query("SELECT * FROM TeraWurflMerge");
while($row = $res->fetch_assoc()){
   $capabilities = unserialize($row['capabilities']);
   $model_names[] = $capabilities['product_info']['brand_name'].' '.$capabilities['product_info']['model_name'];
}
$model_names = array_unique($model_names,SORT_STRING);
?>
Thanks,

Steve Kamerman
Tera-WURFL Author
COO of ScientiaMobile

IMPORTANT ANNOUNCEMENT! Tera-WURFL and WURFL have joined forces! We have launched ScientiaMobile to provide commercial support for our device detection solutions.

Tera-WURFL.com | Device Explorer
kamermans
Site Admin
 
Posts: 323
Joined: Wed Mar 10, 2010 12:06 pm
Location: Fort Worth, TX

Re: Create a model name list

Postby whatisthis » Wed Nov 10, 2010 1:33 pm

I've tried both of those examples and I keep getting this error.

Notice: Undefined index: brand_name in dbPlayGround.php on line 21

I see how the tables are set up, but I'm missing why the index is undefined.
whatisthis
 
Posts: 1
Joined: Wed Nov 10, 2010 12:56 pm

Re: Create a model name list

Postby kamermans » Wed Nov 10, 2010 2:32 pm

Most of the entries will not have brand_name defined due to inheritance - try this code instead.

Code: Select all
<?php
$model_names = array();
$db = new mysqli($host,$user,$pass,$db);
$res = $db->query("SELECT * FROM TeraWurflMerge");
while($row = $res->fetch_assoc()){
   $capabilities = unserialize($row['capabilities']);
   if(array_key_exists('product_info',$capabilities) && array_key_exists('brand_name', $capabilities['product_info'])){
      $model_names[] = $capabilities['product_info']['brand_name'].' '.$capabilities['product_info']['model_name'];
   }
}
$model_names = array_unique($model_names,SORT_STRING);
?>
Thanks,

Steve Kamerman
Tera-WURFL Author
COO of ScientiaMobile

IMPORTANT ANNOUNCEMENT! Tera-WURFL and WURFL have joined forces! We have launched ScientiaMobile to provide commercial support for our device detection solutions.

Tera-WURFL.com | Device Explorer
kamermans
Site Admin
 
Posts: 323
Joined: Wed Mar 10, 2010 12:06 pm
Location: Fort Worth, TX


Return to Using Tera-WURFL

Who is online

Users browsing this forum: No registered users and 1 guest

cron