Jump to content

shaunmckinnon

Members
  • Posts

    30
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

shaunmckinnon's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Fixed with this: public function deleteIt($id) { $conn = $this -> connect_open(); // set the table $table = $this -> table; // delete the row required $sql = "DELETE FROM $table WHERE id = $id"; if($conn -> query($sql)) { try { return (int)(($conn->affected_rows > 0) ? true : false); } catch (Exception $e) { echo '<br>Caught exception: ', $e -> getMessage(), '<br>'; } } else { return (int)false; } $conn = $this -> connect_close(); } Thanks again for the help.
  2. Thanks!!! That is exactly what I want. My brain is fried. I've been doing this for 12 hours straight. Time to unplug.
  3. Never mind. I var_dump'd the value in my file that's getting the returned value and it comes up bool(false). $dbman = new DBManipulate; $dbman -> set_Table('users'); $result = $dbman -> deleteIt(6); var_dump($result); I need to learn more. Cheers and thanks for the help!
  4. Thank you. I never knew that, but it makes perfect sense. I'm not doing anything yet. I just want a returned value of either true or false. It's so bizarre. I could just return 1 or 0 and It works. But the second I change it to true or false, even with (int)false, it refuses to obey. Here is the adjusted code: public function deleteIt($id) { $conn = $this -> connect_open(); // set the table $table = $this -> table; // delete the row required $sql = "DELETE FROM $table WHERE id = $id"; if($conn -> query($sql)) { try { return (int)$conn -> affected_rows > 0; } catch (Exception $e) { echo '<br>Caught exception: ', $e -> getMessage(), '<br>'; } } else { return (int)false; } $conn = $this -> connect_close(); }
  5. I don't know if this makes a difference, but here is the whole method: public function deleteIt($id) { $conn = $this -> connect_open(); // set the table $table = $this -> table; // delete the row required $sql = "DELETE FROM $table WHERE id = $id"; if($conn -> query($sql)) { try { return $conn -> affected_rows > 0; } catch (Exception $e) { echo '<br>Caught exception: ', $e -> getMessage(), '<br>'; } } else { return false; } $conn = $this -> connect_close(); }
  6. False should return as "0", as True returns as "1". Either way, it doesn't return. Thanks for the help on getting rid of the ternary. I've tried a crazy amount of things and now I'm stuck in a circle of bad practice. lol However, even with your change, it still won't return the boolean. I still get nothing. Here is the current code: $sql = "DELETE FROM $table WHERE id = $id"; if($conn -> query($sql)) { try { return $conn -> affected_rows > 0; } catch (Exception $e) { echo '<br>Caught exception: ', $e -> getMessage(), '<br>'; } } else { return false; }
  7. Hello: I've just started learning OOPHP, and I love it!!! However, I've come across a strange issue. I'm trying to return a boolean value from my ternary statement. It will not return the boolean. I can return a string literal, an integer, anything else you can think of, but not a boolean. I'm curious if someone could explain why. Here's the code: // delete the row required $sql = "DELETE FROM $table WHERE id = $id"; if($conn -> query($sql)) { try { $num = ($conn -> affected_rows > 0) ? true : false; return $num; } catch (Exception $e) { echo '<br>Caught exception: ', $e -> getMessage(), '<br>'; } } else { return false; } Any help is appreciated. Thank you so much in advance.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.