How to combine multiple if conditions

Source: Internet
Author: User
How to combine multiple if conditions
Title: Code efficiency is not high, redundancy is too much, online and so on.
PHP Code
  if ($start _id = = $first _id && $arrive _id = = ") {echo" I am the first city City ";                    To inquire whether the first city has added transport $start _id = ';                    $arrive _id = $first _id;                    $res = $this->model->get_traffic ($tripid, $type, $start _id, $arrive _id);  if ($res) {$affected _rows = $this->model->update_traffic ($traffic, $tripid, $type, $start _id,                        $arrive _id); if ($affected _rows > 0) {echo "updated successfully!                        "; }}else{$trafficid = $this->model->add_traffic ($traffic, $tripid, $start _                        ID, $arrive _id, $type, $dateline);                        if ($trafficid > 0) {echo ' Add success ';                }} exit;                   if ($start _id = = $last _id && $arrive _id = = ") { echo "I am the last city";                    $start _id = $last _id;                    $arrive _id = ";                                        $res = $this->model->get_traffic ($tripid, $type, $start _id, $arrive _id);  if ($res) {$affected _rows = $this->model->update_traffic ($traffic, $tripid, $type, $start _id,                        $arrive _id); if ($affected _rows > 0) {echo "updated successfully!                        "; }}else{$trafficid = $this->model->add_traffic ($traffic, $tripid, $start _                        ID, $arrive _id, $type, $dateline);                        if ($trafficid > 0) {echo ' Add success ';                }} exit;                if ($start _id = = ' && $arrive _id = = ') {echo "Requires 2 cities to add transportation";                    }else{echo "Select right can be put into storage";$res = $this->model->get_traffic ($tripid, $type, $start _id, $arrive _id);  if ($res) {$affected _rows = $this->model->update_traffic ($traffic, $tripid, $type, $start _id,                        $arrive _id); if ($affected _rows > 0) {echo "updated successfully!                        "; }}else{$trafficid = $this->model->add_traffic ($traffic, $tripid, $start _                        ID, $arrive _id, $type, $dateline);                        if ($trafficid > 0) {echo ' Add success ';            }}}} $this->display = true;            $this->view->assign (' cities ', $cities);            $this->view->assign (' Traffic ', $_config[' traffic ');            $this->view->assign (' Tripid ', $tripid);            $this->view->assign (' Cityid ', $cityid); $this->view->assIGN (' type ', $type);        }else if ($type = = 2) {echo "I'm here to add the sights of gourmet green"; }


------Solution--------------------
Does your if else {} bracket match? Why do I feel wrong?
------Solution--------------------
You can try it with switch!
------Solution--------------------
$res = $this->model->get_traffic ($tripid, $type, $start _id, $arrive _id);
if ($res) {
$affected _rows = $this->model->update_traffic ($traffic, $tripid, $type, $start _id, $arrive _id);
if ($affected _rows > 0) {
echo "Updated successfully! ";
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.