Limit the number of rows in the table

Limit the number of rows in the table

JustereJustere Posts: 8Questions: 4Answers: 0
edited May 2015 in Editor

Hello,

For example,
I have a table, where will be many data.
It also have foreign-key "id_example".

In my Editor-handler i use WHERE clause to filter data from it.

->where($key = 'example.id_example', $value=$myvalue)`

I need to restrict user create new records, if row count = 1.

Any suggestions?

Answers

  • aarontharkeraarontharker Posts: 41Questions: 11Answers: 0

    Have you read the sticky?

    http://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read#latest

    Would need a lot more details to really be able to help you.

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    So the Editor PHP libraries themselves won't perform the if row count = 1, then allow create restriction for you. You would need to implement that logic yourself.

    Something like:

    if ( $row_count !== 1 && ( isset( $_POST['action'] ) && $_POST['action'] === 'create' ) {
      echo json_encode( [
        "error" => "Cannot create"
      ] );
      exit(0);
    }
    

    Obviously you'll need to get $row_count from wherever you have that information (presumably in the database, so make a query to get it).

    Allan

  • JustereJustere Posts: 8Questions: 4Answers: 0

    Works very well, thank you, Allan.

This discussion has been closed.