vmavrou Posted November 19, 2009 Share Posted November 19, 2009 hi! i have an array that contains name of fields. for example : $ff[0] = a $ff[1] = b $ff[2] = c and i know of course the length of the array. is possible to create a query to delete a row in a table where the contents of the array will be equals to zero for example . something like that. if($ff[0]==0&&$ff[1]==0&&$ff[2]==0) { delete row } but everytime we call that the array it could change. One time it might has 2 cells,other 3,4 etc. so we want to read the array and based on the results to automatic create a query. Is that possible to create a "dynamic" query to handle a case like this? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/182188-solved-dynamic-query-is-that-possible/ Share on other sites More sharing options...
vmavrou Posted November 19, 2009 Author Share Posted November 19, 2009 Manage to do it, by making up this solution. posted in case someone interested. $queryy = "DELETE FROM groupspu WHERE"; $result = mysql_query("SELECT * FROM groupspu"); $fields_num = mysql_num_fields($result); for($i=0; $i<$fields_num; $i++){ $field = mysql_fetch_field($result); $ff = $field->name; if($i==0) { $queryy = $queryy." ".$ff; } else{ $queryy = $queryy." ='0' AND ".$ff; } } $queryy = $queryy." ='0' "; $result = mysql_query($queryy); Quote Link to comment https://forums.phpfreaks.com/topic/182188-solved-dynamic-query-is-that-possible/#findComment-961338 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.