kusal Posted July 6, 2006 Share Posted July 6, 2006 is it possible to use php to create dynamic web pagesex ;if i create a table (let assume that i don't know the attributes) is it possible to print its contentkusal - sri lanka Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/ Share on other sites More sharing options...
CheesierAngel Posted July 6, 2006 Share Posted July 6, 2006 Check out the PEAR package for easely creating dynamic tables.I'm sure you'll find what you'r looking for. <a href="http://pear.php.net/package/HTML_Table">http://pear.php.net/package/HTML_Table</a> Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/#findComment-53797 Share on other sites More sharing options...
kusal Posted July 6, 2006 Author Share Posted July 6, 2006 can any one help me with a code(thank you for your help "CheesierAngel") Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/#findComment-53820 Share on other sites More sharing options...
hackerkts Posted July 6, 2006 Share Posted July 6, 2006 kusal, what do you mean dynamic page ?page=contact, page=news ? Try checking the FAQ, it's a sticky thread. Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/#findComment-53822 Share on other sites More sharing options...
kusal Posted July 6, 2006 Author Share Posted July 6, 2006 thing is this, i'm developing a inventory control system for a company(as my 2nd year project) and they request that the system sould be able create tables when they needed, using php. then for more complication the tables will be later used to do functions like add, delete, update....(i think you got the point) but i don't have any idea what would be the attributes of those table bcos they enter those details.so i need a codeing that will take out those attributes from what ever the table and do above mentioned functions Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/#findComment-53829 Share on other sites More sharing options...
CheesierAngel Posted July 6, 2006 Share Posted July 6, 2006 There are some CMS's that have this kind of functions integrated as default.For example cakePHP uses scaffolding... . For wathever table you created in your databasecakePHP will make the forms for adding, editing, deleting your table content automaticly. The only work left is making the .thtml files for the look en feel of the forms.Your can read more about this at <a href="http://manual.cakephp.org/chapter/5">http://manual.cakephp.org/chapter/5</a> Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/#findComment-53832 Share on other sites More sharing options...
kusal Posted July 6, 2006 Author Share Posted July 6, 2006 i can't use 3rd party libaries (it's a project)pure php Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/#findComment-53834 Share on other sites More sharing options...
.josh Posted July 6, 2006 Share Posted July 6, 2006 so...what is your question - can you do it with php? well since that's your project assignment, then obviously you should know that you can do that in php. do you have a specific question? do you know [i]anything[/i] about php? if not, you are going to have to start with your first hello world example just like with any other language. Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/#findComment-53836 Share on other sites More sharing options...
kusal Posted July 6, 2006 Author Share Posted July 6, 2006 yes i know bit of php, i have almost finished my project, but only for the predefiened tables, i don't know a way to get information from tables that i don't know (tables that would be created by the company)(MAN IT'S VERY HARD EXPRESS MY MESSAGE).kusal Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/#findComment-53842 Share on other sites More sharing options...
.josh Posted July 6, 2006 Share Posted July 6, 2006 maybe it would help if you gave an example. are you talking about dynamically creating database tables through php? if so, then this is not really a php question, but a database (example: mysql) question. You would use the same commands (for example) for creating a table as you would in your database. As far as php, you'd just use the variable name instead of an actual name. example using mysql:[code]<?php $tablename = $_POST['tablename']; //name of table user entered from some form $columnname = $_POST['columnname']; //name of some column user entered from some form//example: create the table with one column that's varchar(30) type, default not null$sql = "CREATE TABLE $tablename ($columnname varchar(30) NOT NULL)";$result = mysql_query($sql);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/#findComment-53844 Share on other sites More sharing options...
CheesierAngel Posted July 6, 2006 Share Posted July 6, 2006 Search for sql functions to discover how your tables and which tables are build in your database.MySQL has his own functions for determining which tables there were defined in your database, which columnheaders they have, the kind of data stored in the different columns and so on.You better first check out the MySQL functions you can execute from your php script to receive the needed data.With this data you can recreate your tables dynamicly with php.For example: query "show tables" and store it into a var. foreach(var -> table) query desc table recreate the table query for all content in the table output your dataIt is for your project so i'll let you write the code yourself, but i want to give you the 'thinking' solution. (Which is for most cases the most difficult part) Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/#findComment-53845 Share on other sites More sharing options...
kusal Posted July 6, 2006 Author Share Posted July 6, 2006 Yes you got the point(but not fully).yes i know that in that way i can create tables, let assume that the above created table needed to insert data (assume that i have given the system to them)then i need to have created a page to add those details in the newly created table.but the problem is, i don't know any details about that table attribute, how can i dynamicaly get those table details to create a adding page Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/#findComment-53850 Share on other sites More sharing options...
.josh Posted July 6, 2006 Share Posted July 6, 2006 I still don't understand what you are asking. If you have input fields for the user to input a table name, column name and column type, you would create the table based off of the inputed information. Are you now asking something like this: User wants to go to a page and there will be a list of the tables he just created, and it lists what type of column it is, so he knows what kind of info he can put in it? Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/#findComment-53855 Share on other sites More sharing options...
CheesierAngel Posted July 6, 2006 Share Posted July 6, 2006 Can you give a specific example for what it should be used for ?Do you already have some code we can see ? Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/#findComment-53863 Share on other sites More sharing options...
.josh Posted July 6, 2006 Share Posted July 6, 2006 assuming that you are asking what i mentioned in my previous post - again, this is not really a php question. but here is an example of the sql query and how you would utilize it with php:[code]<?php//obviously you need to connect to the db first. this also //assumes you are using mysql, seeing as you have yet//to mention what db you are using...$tablename = 'nameoftable'; //put name of table here//this query string will return a list of all the columns in the//table and the information about the columns$sql = "show columns from $tablename";$result = mysql_query($sql) or die(mysql_error());//fetch and make an array of the results of the querywhile ($rs = mysql_fetch_array($result, MYSQL_ASSOC)) { $list[] = $rs;}//example of listing out the results:foreach ($list as $row) { echo "<b>-- {$row['Field']} -- </b><br>"; foreach ($row as $key => $val) { echo "$key : $val <br>"; }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/#findComment-53866 Share on other sites More sharing options...
Ninjakreborn Posted July 6, 2006 Share Posted July 6, 2006 He means have something to where tables can auto-generate themselves using php with proper attributes based on the situation. Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/#findComment-53868 Share on other sites More sharing options...
.josh Posted July 6, 2006 Share Posted July 6, 2006 well i gave him an example of that and he said that's not quite what he meant. Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/#findComment-53870 Share on other sites More sharing options...
kusal Posted July 7, 2006 Author Share Posted July 7, 2006 the problem is not how to create a table or retrieving data from it.ex:the project is that i create an invetory control system for computer hardware devices for a mobile telephone company in sri lanka. the company has pc,routers,servers,laptops,printer,telephones.....etc, to be stock controlled. so i have created tables for every device with there uniqe attributes. and created funtions like add,delete,update,view...etc, for every table using php and mysqlNOW THE PROBLEM IS THAT COMPANY IS ASKING ME TO CREATE A FUNCTION THAT, IF THEY COME ACROSS NEW HARDWARE DEVICE (EX: ISP LOAD BALANCER, WHICH IS NOT CREATED ABOVE) THEY NEED TO CREATE A TABLE FOR IT AND NEED TO HAVE ALL ABOVE MENTIONED FUNCTIONS.HOW CAN I DO THIS, I NEED TO CREATE HTML PAGES AND PHP PAGES DYNAMICLY FOR A CHANGING DATABASE. Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/#findComment-54251 Share on other sites More sharing options...
hackerkts Posted July 7, 2006 Share Posted July 7, 2006 Please don't use capital letters, it doesn't sound nice to me :(Bold those words would be better if you want people to take note of that parts.Hmm.. You could store the informations in database, then loop them out.Take a look at this page, you can store all those items then loop them out,hope I got what you mean. Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/#findComment-54252 Share on other sites More sharing options...
Mr.x Posted July 7, 2006 Share Posted July 7, 2006 I had to do something similar for a cell phone store, except it was with manufacturers of the phones.One of the best tips I got was to create a seperate table just for differn't categories or product types.Ie in the table would just beServersDesksMonitorsPhones etc.I then would while loop all of these out and it created a list of items for them to choose...So say they choose servers, it would go to details.php?type=servers for example.Before hand you have to figure out some of the things they have in common, so are you getting into specific detail with each object or not? If not then you can do statics of such things like quantity, location, year purchased, etc.Then the script loops through your database and outputs out any "items" that are categorized as a server to a new row in your table, then you have standard functions such as add or subtract them.Then later on you make an admin panel so if they add in SUPER SERVERS then all it does is create the new category and they have the option to add products as Super Servers.Not sure if this helps, if it doesn't help hopefully it will help you solve some questions.-Sean Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/#findComment-54255 Share on other sites More sharing options...
kusal Posted July 7, 2006 Author Share Posted July 7, 2006 can i use [b]show table[/b] and [b]describe[/b] table_name to get the info,let say that i get those info but how can i create relevant html page and php pages. Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/#findComment-54256 Share on other sites More sharing options...
hackerkts Posted July 7, 2006 Share Posted July 7, 2006 Eh.. Can you explain to me what does you mean by [b]show table[/b] and [b]describe[/b] ?Try this sample, hope it's what you looking for.MySQL table structure:[code]CREATE TABLE `handphone` (`id` MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY ,`type` TEXT NOT NULL ,`servers` TEXT NOT NULL ,`desks` TEXT NOT NULL ,`monitors` TEXT NOT NULL ,`phones` TEXT NOT NULL)[/code]MySQL datas:[code]INSERT INTO `handphone` VALUES (1, 'type1', 'servers1', 'desks1', 'monitors1', 'phones1');INSERT INTO `handphone` VALUES (2, 'type1', 'servers2', 'desks2', 'monitors2', 'phones2');INSERT INTO `handphone` VALUES (3, 'type1', 'servers3', 'desks3', 'monitors3', 'phones3');INSERT INTO `handphone` VALUES (4, 'type2', 'servers1', 'desks1', 'monitors1', 'phones1');INSERT INTO `handphone` VALUES (5, 'type2', 'servers2', 'desks2', 'monitors2', 'phones2');INSERT INTO `handphone` VALUES (6, 'type2', 'servers3', 'desks3', 'monitors3', 'phones3');INSERT INTO `handphone` VALUES (7, 'type3', 'servers1', 'desks1', 'monitors1', 'phones1');INSERT INTO `handphone` VALUES (8, 'type3', 'servers2', 'desks2', 'monitors2', 'phones2');INSERT INTO `handphone` VALUES (9, 'type3', 'servers3', 'desks3', 'monitors3', 'phones3');[/code]Scripts[code]<?phpmysql_connect("localhost", "root","") or die(mysql_error());mysql_select_db("hp") or die(mysql_error());if (isset($_GET['type'])) { $result = mysql_query("SELECT * FROM handphone WHERE type='".$_GET['type']."'") or die("Query failed: " . mysql_error()); while($row = mysql_fetch_assoc($result)) { ?> <table width="560" border="1" align="center" cellpadding="2"> <tr> <td><strong>Servers: </strong><?php echo $row['servers']; ?></td> </tr> <tr> <td><strong>Desks: </strong><?php echo $row['desks']; ?></td> </tr> <tr> <td><strong>Monitors: </strong><?php echo $row['monitors']; ?></td> </tr> <tr> <td><strong>Phones: </strong><?php echo $row['phones']; ?></td> </tr> </table><br> <?php }} else { echo "You didn't select any type."; }?>[/code]If you save the code in index.php, then you can access it from http://domain/index.php?type=1 or type=2 or type3It will display according to your type. Quote Link to comment https://forums.phpfreaks.com/topic/13834-dynamic/#findComment-54272 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.