my own separate numbering of fields in the table?

Questionsmy own separate numbering of fields in the table?
Alex asked 3 weeks ago

Can I make my own separate numbering of fields in the table?

7 Answers
Abu Ghufran Staff answered 3 weeks ago

By numbering, if you mean column display ordering, then you can refer:

https://www.phpgrid.org/docs/selecting-columns/

_________________________
Abu Ghufran - Dev Team
PHP Grid Framework
 
Alex answered 3 weeks ago

Example table «USERS»

1. № (1) ID (field) – AUTO_INCREMENT (in SQL table)

2. USER (2) ID_USER (field)

3. NM (3) ID_NUM (field)

1). ID_USER / NAME / ID_NUM / PRODUCT

1             Joy             1           cola

1             Joy             2           pepsi

1             Joy             3 …..

2). ID_USER NAME ID_NUM  PRODUCT

2             Jim           1           fanta

2             Jim           2          manta

2             Jim           3 …..

2             Jim          ….

……

$rows = $stmt->fetch(PDO::FETCH_ASSOC);

$ID_NUM = $rows[‘ID_NUM’];

…..

$ID_N = $ID_NUM + 1;

$col = array();

$col[“title”] = “NM”;

$col[“name”] = “ID_NUM”;.

$col[“editable”] = true;

$col[“hidden”] = false;

$col[“editoptions”] = array(“defaultValue” => $ID_N);   <—?

$cols[] = $col;

I need each group “ID_USER” to have its own numbering with saving in the table “USERS”. I get if you refresh the entire page of the site “F5”, not just “grid”

Abu Ghufran Staff answered 3 weeks ago

Please refer this ticket:

defaultValue = another column?

_________________________
Abu Ghufran - Dev Team
PHP Grid Framework
 
Alex answered 2 weeks ago

Works if there are records in the database. If the base is empty-does not work. How best to check if there are no records.

Alex answered 2 weeks ago

Hi Abu!

demo https://lttr.ru/k/max_1.php

In the clients table there is a field “clients_id” AS autoincrement, and the script works on it. If you add the field “id_num” AS integer to the table and assign max(id_num)+1.

If there are no records in the table, you must first manually add the sequence number 1, and then the script works. I need to work on any field, not just on autoincrement.

Abu Ghufran Staff answered 2 weeks ago

Instead of using max(id_num)+1 …. you can use:

ifnull(max(id_num),0)+1 … so if it return null for empty table, it will make it 0 and then you will get 1.

Code demo: https://gist.github.com/gridphp/27e1f4b009e2a838be0bfc49d66e0d0f#file-grid_get_max_id-php-L28

_________________________
Abu Ghufran - Dev Team
PHP Grid Framework
 
Alex answered 2 weeks ago

Yes!!!

Abu, Thanks, everything works fine.

Your Answer

2 + 11 =

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating / 5. Vote count:

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!