dssqq82402 2017-09-13 15:11
浏览 47

如果条件没有在PHP中正确检查?

I am working on submission system. I have a drop down list when user want to edit the section drop-down need to be matched select option to visible in drop down list based on before saved in database value. I write some code for this option but it's not working properly. This same code I have used for the antoher project it's working well. An error also not coming I have checked syntax no problem.

enter image description here

                 <?php  

                    $journalid = $_GET['jiid'];
                    $sqlold = "SELECT `jtype`, `jtitle` FROM `journal` WHERE jid=? LIMIT 1";
                    $db->query($sqlold);
                    $db->bind(1, $journalid);
                    $db->execute();
                    $resjid = $db->resultset();
                    foreach($resjid  as $resjtype){
                          $resjournaltype = $resjtype['jtype'];
                    }                         
                    echo 'Res Ournal Type: '.$resjournaltype;
                    $db->query("SELECT article_name, article_value FROM article_type");
                    $db->execute();
                    $resultrow = $db->resultset();  
                    foreach($resultrow as $vals){
                    if($resjournaltype == $vals['article_value'] ){
                     echo "yes";
                    }

                            ?>
                                    <option <?php //if ( $jtype == $res['article_value'] )  echo 'selected = "selected"'; ?> value="<?php echo $res["article_value"];?>"><?php echo $res['article_name']; ?> </option>
                            <?php
                            else {?>
                            <option <?php //if ( $jtype == $res['article_value'] )  echo 'selected = "selected"'; ?> value="<?php echo $res["article_value"];?>"><?php echo $res['article_name']; ?> </option>                                  
                            <?php
                                    } 

                                }*/
                                else{   

                            ?>
                            <option <?php //if ( $resjid[0]['jtype'] == $vals['article_value'] )  echo 'selected = "selected"'; ?> value="<?php echo $vals["article_value"];?>"><?php echo $vals['article_name']; ?> </option>
                          <?php
                                    }
                                }
                        ?>                  
  • 写回答

1条回答 默认 最新

  • dsjgk330337 2017-09-13 19:43
    关注

    I am searching for a solution every where on the Internet but I forgot some syntax problems. These problems not giving an error. If here I am checking if condition inside for-each loop here is I made a mistake. My actual code is this. The problem was I am checking two string, not numbers. In PHP string values compare with strcmp() function.

     if($resjournaltype == $vals['article_value'] )
     {  echo "yes"; }
    

    I changed condition like this finally my problem has been solved.

    if(strcmp($resjournaltype, $vals['article_value']) == true){
        echo $resjournaltype .'-'. $vals['article_value'] ; }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助