Note that there are some explanatory texts on larger screens.

plurals
  1. POif else condition not working in a function
    text
    copied!<p>i am making a function in which i get results from mysql table in form of words separated by comma . I separated them by using explode and then try to put a condition check inside for loop's if and else statements . but the condition check is not working i tried to echo the results coming from the database and it comes out to be <code>V</code> and there is condition check for <code>V</code> in my function but its not working here is my code</p> <pre><code> function partner_diet($page,$user_id) { $getrow=mysql_query("SELECT * from partner_prefrences where uid='$user_id'"); $results=mysql_fetch_array($getrow); $string=$results['diet']; $string = preg_replace('/\.$/', '', $string); //Remove dot at end if exists $array = explode(',', $string); //split string into array seperated by ', ' //loop over values ?&gt; &lt;select name="mipdiet" class="mipdiet" multiple="multiple"&gt; &lt;option &lt;?php foreach($array as $value) { if($value=='V') {?&gt; checked &lt;?php } } ?&gt; name="pdiet" value="V"&gt; Vegetarian &lt;/option&gt; &lt;option &lt;?php foreach($array as $value) { if($value=='N') {?&gt; checked &lt;?php } } ?&gt; name="pdiet" value="N"&gt; Non Vegetarian &lt;/option&gt; &lt;option &lt;?php foreach($array as $value) { if($value=='J') {?&gt; checked &lt;?php } } ?&gt; name="pdiet" value="J"&gt; Jain &lt;/option&gt; &lt;option &lt;?php foreach($array as $value) { if($value=='E') {?&gt; checked &lt;?php } } ?&gt; name="pdiet" value="E"&gt; Eggetarian &lt;/option&gt; &lt;/select&gt; &lt;?php } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload