- I purposely added a flag column to a table
- I want to count all rows with '1'(It can count already)
- Then, I want to add '1' to the value in No.2 so I can echo/callout the next number(I dont know how to do this)
I am making a queue management system
$sql = "SELECT COUNT(*) FROM QueueP1 WHERE STATUS = '1'"; $result = $conn->query($sql); $row = mysqli_fetch_assoc($result); echo "No ".implode($row)."<Br>";
Asked
Active
Viewed 219 times
-1

hajji rs ratunil
- 3
- 4
1 Answers
0
You can do calculations with MySQL functionality.
$sql = "SELECT (COUNT(1) + 1) AS 'next_number' FROM QueueP1 WHERE STATUS = '1'";
$result = $conn->query($sql);
$row = mysqli_fetch_assoc($result);
echo "No ".$row['next_number']."<br/>";
Use COUNT(1) to free MySQL from counting all columns and speed up query.

Aleksandr Berlin
- 16
- 2
-
For connection with databases better use class PDO. It's more secure. – Aleksandr Berlin May 20 '20 at 16:32
-
Another issue: How can i code to alter the 'next_number' status to '1' – hajji rs ratunil May 20 '20 at 16:47
-
2@AleksandrBerlin Why would you suggest that? First off, there's no user input involved. Second, PDO is only as effective as any other other api but using a prepared statement, which isn't needed here. – Funk Forty Niner May 20 '20 at 18:13
-
@FunkFortyNiner I guess it’s about developing your own habits. PDO is universal tool for working with data. It has many additional options to set up connection you need – Aleksandr Berlin May 21 '20 at 03:56
-
Mr Aleksander.. I have an else statement if the query reaches the last record. So, if its on the no 8 row of an 8 row table - it will not proceed to show no. 9. Can you help how to set my condition statement and where to put it – hajji rs ratunil May 23 '20 at 14:32