I have a problem assigning position (number) based on the total marks. Here is the code. TQvm for your assistance
the calculation is done perfectly, the ranking is shown correctly but with no numbers, 1, 2 ,3.....
how to set autoincrement for this field (ranking) which is based on the calculation of the sum.
Tq

$sql ="SELECT idPeserta, SUM(JumlahMarkah) AS JumlahKeseluruhan, PurataMarkah,Kedudukan FROM penilaian GROUP BY idPeserta ORDER BY PurataMarkah DESC"; want to assign the rank to 'Kedudukan'

Sorry, I'm not understanding your question. The SQL you provided is performing a SELECT on the database, retrieving data. But you want to assign data? Does that mean you want to update the database? I don't understand what you mean by autoincrementing the field? Autoincrement is when a field is numeric and increases on its own for each record inserted into the table.

If you wish to display this data that the Select is retrieving, then you set a position variable at 1, list or display on screen one at a time, including the position variable, then finish the displaying loop by setting position at position++

Hope that makes sense.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.