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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.