How to merge multiple if conditions such as: low code efficiency, too much redundancy, online, etc. PHPcodeif ($ start_id $ first_id & amp; $ arrive_id) {echo & quot; I am the first city & quot ;; query whether multiple if conditions are merged in the first city.
Example: the code is inefficient, redundant, and online.
PHP code
If ($ start_id = $ first_id & $ arrive_id = '') {echo" I am the first City city "; // check whether the first city has added the vehicle $ 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 'added successfully';} 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 'added successfully ';}} exit;} if ($ start_id = ''& $ arrive_id = '') {echo "you need to select two cities to add transportation vehicles";} else {echo "you can select the correct city to import traffic to the database"; $ res = $ this-> model-> get_traffic ($ tripid, $ type, $ start_id, $ arrive_id); if ($ res) {$ affected_rows = $ this-> model-> update_traffic ($ traffic, $ tripid, $ typ E, $ start_id, $ arrive_id); if ($ affected_rows> 0) {echo "update successful! ";}} Else {$ trafficid = $ this-> model-> add_traffic ($ traffic, $ tripid, $ start_id, $ arrive_id, $ type, $ dateline ); if ($ trafficid> 0) {echo 'added successfully ';}}}$ 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 am here to add scenic green food ";}
------ Solution --------------------
Does your if else {} parentheses match? What do I think is 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! ";