Create a model name list
Posted:
Wed Apr 28, 2010 9:30 am
by frblanc
Hello,
I would like to create a model name list. Could you help me to make that ?
Regards,
François
Re: Create a model name list
Posted:
Sat May 01, 2010 8:18 am
by kamermans
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);
?>
Re: Create a model name list
Posted:
Sat May 01, 2010 8:26 am
by kamermans
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);
?>
Re: Create a model name list
Posted:
Wed Nov 10, 2010 1:33 pm
by whatisthis
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.
Re: Create a model name list
Posted:
Wed Nov 10, 2010 2:32 pm
by kamermans
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);
?>