Languages :: PHP :: another stupid question |
|||
| By: roe1and |
Date: 18/01/2008 12:44:19 |
Points: 20 | Status: Answered Quality : Excellent |
|
i have a page that contains a form and it looks something like this : []name []surname []tel_no []birth_date []address submit the [] represents checkboxes on the next page i want this information to go into a sql query. so if i select name and surname and address and submit it on the next page the query has to read "SELECT name, surname, address FROM ...". or if i select name and birth_date then it needs to read "SELECT name, birth_date FROM ..." i suppose id would be easiest to pass these into an variable and than place the variable in the query: $fields = 'name, birth_date'; $query = "SELECT $fields FROM ...;"; i just cant seem to figure it out.... help please |
|||
| By: VGR | Date: 18/01/2008 15:02:02 | Type : Answer |
|
| not tested but should work : $query='select '; //note the space foreach($_POST as $var=>$val) { $query.="$var='{$val}' AND "; //note the spaces } if ($query=='select ') then die ("please check some boxes ;-)"); else { // go on // delete the last "and " //note the space $query=substr($query,0,-4); // complete query $query.="from ...;"; //note no space // exec etc } |
|||
| By: roe1and | Date: 18/01/2008 17:02:07 | Type : Comment |
|
| i got it sorted in the end. my solution was not as elegant as yours but thanks anyway | |||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








