Jump to content

[SOLVED] "dynamic query". Is that possible?


vmavrou

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/182188-solved-dynamic-query-is-that-possible/
Share on other sites

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.