0

Hi guys, i'm tryng to check available when update a record! so i'm getting that the record is available!
Bellow my class and my proccess

//this is my function i use inside of my class

function getInfonupdate($display_name) {
        $query = $this->link->query("SELECT * FROM tbl_types WHERE display_name != '$display_name'");
        $rowcount = $query->rowCount();
        if ($rowcount == 0) {
            $result = $query->fetchAll();
            return $result;
        } else {
            return $rowcount;
        }
    }
    //and my proccess is 

     $check_availablity = $types->getInfonupdate($display_name);
                    if ($check_availablity == 0) {
                      $update = $types->editTypes($id_type_group, $display_name, $description, $date_modified, $user_modified, $type_id); 
                    if ($update == 1) {
                    $_SESSION['success'] = "<div class='alert alert-success alert-dismissable'>
        <i class='fa fa-check'></i>

   <button type='button' class='close' data-dismiss='alert' 

      aria-hidden='true'>

      &times;

   </button>
New Type {$display_name} has been successful Updated!

</div>'";
                    header('Location: ../edit_type.php?success');

            }
        }

So when i run i get the user is olready added! like i count update a query!
And i've no idea how to check when update a record!

2
Contributors
2
Replies
10
Views
2 Years
Discussion Span
Last Post by hell hansen
0

If you need to know if the row exists you should query the database for that row only.
SELECT COUNT(display_name) FROM tbl_types WHERE display_name = '$display_name'

Now you're get a zero or 1 which is easy to check so you know if you need to update or insert.

0

Hi Hericles, Thanks for you help.
But this query is only to count columns, you cant count values.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.