| 197 | | $sql = db_query("SELECT shortsubject from entries where user_id = ".$this->id." and (shortsubject = '".$shortsubject."' or shortsubject like '".$shortsubject."\\\_%') order by char_length(shortsubject) desc, shortsubject desc;"); |
|---|
| 198 | | $sqlNum = db_num_rows($sql); |
|---|
| 199 | | //if so we grab the last one, and add 1 to it.. |
|---|
| 200 | | if ($sqlNum != 0) { |
|---|
| 201 | | $sqlRow = db_getrow($sql); |
|---|
| 202 | | (int)$newNum = array_shift(array_reverse(explode('_',$sqlRow['shortsubject']))); |
|---|
| 203 | | $shortsubject .= '_'.++$newNum; //new non-colliding short subject |
|---|
| 204 | | } |
|---|
| | 197 | $sql = db_query("SELECT shortsubject FROM entries WHERE user_id = {$this->id} AND shortsubject ~ '{$shortsubject}(_[0-9]{1,3}$|$)' ORDER BY char_length(shortsubject) DESC, shortsubject DESC;"); |
|---|
| | 198 | $sqlNum = db_num_rows($sql); |
|---|
| | 199 | |
|---|
| | 200 | //if so we grab the last one, and add 1 to it.. |
|---|
| | 201 | if ($sqlNum != 0) { |
|---|
| | 202 | $sqlRow = db_getrow($sql); |
|---|
| | 203 | // Put the matched _number into $matches[0] if there is one |
|---|
| | 204 | if (preg_match("/\_[0-9]{1,3}$/",$sqlRow['shortsubject'],$matches)) { |
|---|
| | 205 | // Remove the _ to get the number, add 1 and append |
|---|
| | 206 | $shortsubject .= '_' . ((int)substr($matches[0],1) + 1); |
|---|
| | 207 | } else { |
|---|
| | 208 | $shortsubject .= '_1'; |
|---|
| | 209 | } |
|---|
| | 210 | } |
|---|