Guys, I am new to PHP development.I have created small PHP apps with your help. Now I am going to create a new PHP website.For that I need to create a dynamic list.Actually here as a list, I mean features of a product.Amount of feature vary from product to product so the length of the list also should be vary from product to product.I can create a 'dynamic text constant size' list but hard to create a complete dynamic list.I need your kind help to create that list guys. I have attached a image for your ease of understanding. If you have a idea please post it here.Because ideas makes solutions. Thank you
Sounds like you need a multidimensional array and a few lessons on dealing with arrays. $products = array ( 'product1'=>array('feature1','feature2','etc'), 'product2'=>array('feature1','feature2','etc'), 'product3'=>array('feature1','feature2','etc') ); PHP: Check out the array functions on php.net and get comfortable using foreach() and for() loops.
Yes friend I appreciate your kind help... But the problem is I have to deal with around 1000 products there fore I thought about a mySQL solution for this place. but hard to understand a way to create a list using PHP and mySQL because I am a newbie.I mean how to print a list on web page using PHP.I mean a dynamic list.I know I should use a loop since the length of the list vary but I have no idea about a way to print a list on a page after retrieving from the database. If you have a idea about that please help me.
Hi First read the data from mysql into an 2d array.(remember arrays are actually maps in php) $result=mysql_query("<your query>"); $rows=mysql_num_rows($result); $i=0; while($i<$rows){ $product=mysql_result($result,$i,'<your products column name>'); $feature=mysql_result($result,$i,'<your features column name>'); myarray[$product][]=$feature; $i++; } PHP: Now you should have something like this. Array([Product A] => Array([1] => AAAAAAA , [2] => BBBBBBBB) , [Product B] => Array([1] => 'CCCCCCC' , [2] => 'DDDDDDDD')); As you can see you know have a 2d map, because it's a map its already sorted for you and will respond very quickly with large amounts of data. To draw the list: <? $keys=array_keys($myarray); ?> <ul> <? for ($r=0;$r<count($keys);$r++){ ?><li><? echo $keys[$r]?><ul><? for ($k=0;$k<count($myarray[$keys[$r]]);$k++){ ?><li><? echo $myarray[$keys[$r]][$k]; ?></li><? } ?></ul></li><? } ?> </ul> PHP:
Thank you a lot kai555.I'll try this and will update you as soon as possible.If you can please tel me what is the best datatype in sql to store a list. Thank you again.
Hi it's better to use to table's and select using a join eg Table product: id | product 1 | Product A 2 | Product B ect... and then Table Feature: product_id | Feature 1 | 'AAAAAA' 1 | 'BBBBBBB' 2 | 'CCCCCC' 2 | 'DDDDDD' Now you can do a join select select * from Feature,Product where Product.id= Feature.product_id. So the list aren't stored as a datatype, but rather as a table on it's own.
WoooooW it's wonderful Kai555.Yeah you are 200% correct.I'll try this and will update you as possible as I can. I double thank you for your help kai555. Thanks a lot.