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! ";