How to generate FORM that reflects MySQL table? - php

I want to generate HTML form based on MySQL table field. The generated input should reflect the type of the MySQL column, e.g. VARCHAR = text, TEXT = textarea, ENUM = checkbox, SET = radio, etc.

I think this kind of Lib is not available
But ya you can do it by making one table in your database that conatains details about form and retrive it and make HTML code dynamically

This is a two step problem.
First you need to analyse the database table. You can get column names, type, etc. using SHOW COLUMNS.
You need to generate the form based on the retrieved information.
Generating form can be as simple as iterating the array received from SHOW COLUMNS query and building HTML along the iteration, or using existing form generation libraries, e.g. Zend_Form or Dora.
Depending on your needs, there is existing software for reflecting and manipulating the whole database, e.g. phpMyAdmin. Furthermore, some frameworks provide means of reflecting the whole model (i.e. database table) in a form for CRUD operations, e.g. Symfony Forms.

Related

Filter Table format view - Drupal 7

I'm looking for some help about "Custom View". I looked throw the internet but can't find it (maybe cause of my bad key words).
I created a custom view with a Table format. The goal is to display content (based on a content type) in a table.
I already have my content showing, I can reorganize rows by client/sector.. by clicking on the column header but now I'd like to :
Filter result depending on the string in an input textfield
and
Filter result using a dropdown menu
I guess It's client side, but I'm a beginner in drupal so it's a bit hard to find out.
Here is what I'd like :
http://hpics.li/175e64e
For the select filter, you should try using exposed filters in your view. In the filter section, add filter on the fields and expose them. If these fields are taxonomy reference fields it should work right away. Otherwise it depends : with entity reference I think Better Exposed Filters can be usefull.
With plain text fields it will be more difficult to get what you want (personnaly I give up on exposed filters when it becomes to complicated), but still possible with this approach and a bit of client side work.
The general idea is to create JSON view wich gets all differents values for a text field across the nodes, using Views Data Source (or get all nodes with fields values then fetch unique values for each fields in javascript).
On client side, on the page load make an ajax call to this view to get an array of all possible values, then build your select list using this array, and then do a client side filtering (using for example the excellent Isotope).
But in my opinion you need to take side : all with views and exposed filters (server side, can be hard and frustrating...) or all in JS (client side), mixing the two should result in a big mess...
For the plain text search box I would choose to work client side, Views won't be of any help I'm afraid.
You can also find good javascript plugins for table sorting / filtering like Datatables.
Good luck.

Linking two html forms in backend and fetch data from mysql

I've to insert two html forms in a webpage, One is a dropdown which consists of the names of the attributes of a phone directory, and a text field where we can enter any value of the corresponding attribute(selected in dropdown) and generate the search results from the database. I am done with the front end and I've created a database as well. I really don't have any idea about that.
Can someone help me with linking both the forms and generating results in tabular format?
You will require PHP or another similar server-side scripting language to do that.
Please have a look at this tutorial on W3Schools.com
Languages required: HTML, PHP, SQL.

Looking for solution to avoid eval()

I need to create some sort of knowledge data base for updates (using PHP and MySQL).
Im using a database to store every update in HTML format.
People that are using the system work with different languages (information about users is stored in the DB).
Sometime the updates contain a text that should be translated and displayed taking into consideration the language that the user is working with.
What approach would you suggest, having in mind that i would like to avoid storing PHP and HTML in the DB.
I was thinking to create a col for every language and to store there the translation of every update, but what will happen it the update contains 2 different translations.
Prototype of the updates:
Some initial text
Translation of some part of the text
Some more text
Second translation
Final update text
I would create a table for languages and a table for updates. Then create a table that links languages to updates. One column for id, one column for language id, one column for update id. Then, you will be able to handle an update with multiple translations.
Another solution would be to use some sort of cdata tag, or something that you could parse easily enough. But this would be a very "wiki" based solution so there are patterns to follow to avoid mixing.
Example:
[English<-[This is the best update ever]->]
[Swedish<-[Detta är den bästa uppdateringen någonsin]->]

Xml template file, pinpoint data location on xml file

A simple three step task
Get data from MySQL
Create XML-file based on data
Send XML via Ajax and process responses
but...
In my project there would be a multiple different xml-content and that is not good if they are hardcoded in cms. It would also make lots of additional work if those files content is needed to change and it is very hard to pinpoint exact location for data in different XML-templates.
I considered to get first used column names from database as an array.
Then xml-template content is parsed to html form and select-list of columns (witch contains all needed db table column names) are positioned next current element or property (there is needs for lots of additional fields but i keep explanation simple).
Value of single element or property can be now easily select and when the form is saved, html-form content is combined back to XML but select-list values are coded inside xml-elements like {#name}, {#job}, {#description}.
On third step data is pulled from db as associative array. Then every coded position is replaced with corresponding array key content.
Does this make any sense or can it be done other way?

How to use PHP to generate HTML form to let user do complex searches on a database?

Let's imagine I have a database and I want to programatically allow the user to build queries. I am coding in PHP and will output an HTML form to let the user specify his query.
I know the names of all fields, their types (int/string/date, etc) and maybe also min/max. How can I best present this visually to the user and let him select his queries?
At the moment, my logic is only AND, because I create a table with an entry for each DB field.
If the original input was free-form text (edit or memo), then I can put <field name><operation><text input field> where operation is a drop down list of
contains/doesn't contain/begins./ends/etc. So he can specify name begins "Mc", etc
If the original input was from a drop down list, the operation is just equal/no equal and he gets to choose again from that drop down list.
For integrs operation is = != > >= =< <
And so on, BUT while I can generate a table row for each and put a checkbox by it, I can't let user specify complex seraches like (name beings"Mc" and salary>50000) || (name !=smith && title!="CEO))
I hope that I explained that understandably. What I guess I am preferably looking for is a FOSS PHP compoinent to help me. Failing that, some advice .... Thanks
I use this to present my tables
http://datatables.net/
You can build the queries however you would like with JS, and MAKE SURE YOU VALIDATE THE DATA SERVER-SIDE
Note: There's a bit of a learning curve here if you're new to jQuery and Json, but IMO it's worth it.

Categories