How to create a counter field?
I have the database authors & books
Authors list:
id, name, etc..
List Books
id, title, authorid, numord
I wish numord were to increase by 1 each time I post a book by that author.
I set numord as calc with the following code:
$a={libri___authorid_raw};
$db =& JFactory::getDBO();
$query = "SELECT NumOrd FROM libri where authorid=($a) ORDER BY NumOrd DESC LIMIT 1";
$db->setQuery($query);
$result = $db->loadResult();
return $result+1;
but when I insert a new book increases the value of a numord but also changes the value of all previous records
Eg.
id title authorid numorder
1 xxx 5 1
2 xxy 1 1
3 xyx 5 2
4 yxx 5 ? I want to insert records
after the insertion becomes:
id title authorid numorder
1 xxx 5 3
2 xxy 1 1
3 xyx 5 3
4 yxx 5 3
Help me please
I have the database authors & books
Authors list:
id, name, etc..
List Books
id, title, authorid, numord
I wish numord were to increase by 1 each time I post a book by that author.
I set numord as calc with the following code:
$a={libri___authorid_raw};
$db =& JFactory::getDBO();
$query = "SELECT NumOrd FROM libri where authorid=($a) ORDER BY NumOrd DESC LIMIT 1";
$db->setQuery($query);
$result = $db->loadResult();
return $result+1;
but when I insert a new book increases the value of a numord but also changes the value of all previous records
Eg.
id title authorid numorder
1 xxx 5 1
2 xxy 1 1
3 xyx 5 2
4 yxx 5 ? I want to insert records
after the insertion becomes:
id title authorid numorder
1 xxx 5 3
2 xxy 1 1
3 xyx 5 3
4 yxx 5 3
Help me please