christalix Posted November 12, 2009 Report Share Posted November 12, 2009 (edited) Hello, Sorry to bother you guys. If l have a variable called $value and this value fetches array from my database. ex. $xyz=mysql_query("SELECT contentext FROM blablabla WHERE parent is NUTLL); foreach($xyz as $value =>$key){ echo $value[1][0]['contenttext']; //where 0 is my error messages and 1 is my reuslt } then, l have $xyz2=mysql_query("SELECT contentext FROM blablabla WHERE is_campaign is NOT NULL AND parent IS NOT NULL); foreach($xyz2 as $value2 =>$key2){ echo $value2[1][0]['contenttext']; } So now if l am working on two different delete buttoms. I will like the delete.gif to be red if nothing is in the $value. l went this way: if(is_num($value > 0){ echo " you can not delete since the $value has a $value2 contents in it"; }else{ echo " You can delete this $value 2 since it contains no $value content"; } This is not working mich for me. Any tip on doing this ? Thanks Edited November 12, 2009 by christalix Quote Link to comment Share on other sites More sharing options...
falkencreative Posted November 12, 2009 Report Share Posted November 12, 2009 Isn't value an array? So shouldn't you have to do something like "$value[array cell]" rather than just "$value"? I'd start by doing a print_r of value and making sure the variable contains what you think it contains. Quote Link to comment Share on other sites More sharing options...
quyen Posted November 12, 2009 Report Share Posted November 12, 2009 <?php $arr = array("record1", "record2", "record3", "conditions"); $cond = "conditions"; foreach ($arr as $key => $value) { if($value == $cond){ print " $value "; } else{ print " $value "; } } ?> Quote Link to comment Share on other sites More sharing options...
christalix Posted November 12, 2009 Author Report Share Posted November 12, 2009 Well, l will try that at the job place tomorrow. it is like the $value is the parent and under the $value are the children $value2. So if there are no $value2 in $value, then deleting should be able with else not able to be deleted. It is mostly on this parent and children databse. The $value and $value2 calues are in the databse which ar ebeing called out with the foreach loop............> I will try !! Quote Link to comment Share on other sites More sharing options...
quyen Posted November 12, 2009 Report Share Posted November 12, 2009 (edited) are you selecting form the same table or from two different tables? You can build your select query better with sub-query. and make your code more simple and easy to handle. I think you are selecting from 1 table (or even 2 tables), the thing is you want to delete the records where the conditions are true, you can also use: if(condition1 && condition2){ } else{ } Quyen, Edited November 12, 2009 by quyen Quote Link to comment 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.
Note: Your post will require moderator approval before it will be visible.