codeigniter - Why is this page remembering PHP variables from the last page? -
i've made button on site (which uses expressionengine), , works. when put identical code on page, button's text should have been on last page (the opposite should be, though refreshing page puts right, can't flip values. here's code works:
<?php $db1 = $this->ee->load->database('ext_db', true); $mapid = "{entry_id}"; $ipaddress = $_server['remote_addr']; $thisquery = "select * maplikes ipaddress = '$ipaddress' , mapid = '$mapid'"; $q = $db1->query($thisquery); $results = $q->result_array(); foreach ($q->result() $row) { $liked = $row->liked; } $buttontext = 'like'; $buttonimage = "1"; if ($liked == "1") { $buttontext = 'unlike'; $buttonimage = "2"; } if($_post['like']) { if ($liked == "1") { $thisquery = "delete maplikes mapid = '$mapid' , ipaddress = '$ipaddress'"; $db1->query($thisquery); } else { $thisquery = "insert maplikes (maplikeid, mapid, liked, ipaddress) values ('null', '$mapid', '1', '$ipaddress')"; $db1->query($thisquery); } } ?> and code doesn't:
<?php $db1 = $this->ee->load->database('ext_db', true); $mapid = "{segment_3_category_id}"; $ipaddress = $_server['remote_addr']; $thisquery = "select * categorylikes ipaddress = '$ipaddress' , mapid = '$mapid'"; $q = $db1->query($thisquery); $results = $q->result_array(); foreach ($q->result() $row) { $liked = $row->liked; } $buttontext = 'like'; $buttonimage = "1"; if ($liked == "1") { $buttontext = 'unlike'; $buttonimage = "2"; } if($_post['like']) { if ($liked == "1") { $thisquery = "delete categorylikes mapid = '$mapid' , ipaddress = '$ipaddress'"; $db1->query($thisquery); } else { $thisquery = "insert categorylikes (categorylikeid, mapid, liked, ipaddress) values ('null', '$mapid', '1', '$ipaddress')"; $db1->query($thisquery); } } ?> as can see, difference between 2 pieces of code $mapid , queries. yet reason 1 works , other doesn't. have idea might going on? i'm thinking more php problem expressionengine one.
the real question, think, why first example work...
you setting state of button based on current value of $liked, if $_post['like'] set, you're changing state of system , button incorrect. if switch code around , test $_post['like'] first, set value of $like after act on it, button show correct state.
Comments
Post a Comment