Hi All,
I have a PHP Code That is Search Input Value from Database and Print it. but i want to Print Serial Number (1,2,3......) before my Every Query. For Ex:
1. Name F Name Add
2. Name F Name Add
3. Name F Name Add
4. Name F Name Add
5. Name F Name Add

Please Suggest me The Code for Done This. Thank You.

Dani AI

Generated

Quick follow-up: marked the thread solved after applying 's suggestion. For future readers, a few practical tips that go beyond the simple loop counter.

If results are paginated, compute the serial relative to the page so numbers keep increasing across pages (for example, start = (page - 1) * per_page + 1). Make sure the ORDER BY used for the query matches the order you number, otherwise row numbers will not reflect the visible sort.

When numbering should come from the database (useful for server-side pagination, joins, or stable ordering), prefer a window function such as ROW_NUMBER() OVER (ORDER BY some_column) AS rn. That delegates numbering to the DB and avoids off-by-one bugs when using LIMIT/OFFSET. See MySQL window functions and PostgreSQL window functions for details: MySQL window functions and PostgreSQL window functions.

Presentation and safety reminders: put the serial column in a numeric-aligned table column and use a proper header (<thead>), always escape output with htmlspecialchars() to prevent XSS, and use prepared statements for queries. For very large datasets, avoid large OFFSET values (consider keyset pagination) to keep queries fast. Relevant PHP docs: htmlspecialchars.

Recommended Answers

All 3 Replies

Show us your current code, we don't know you database schema or what to change if you don't

try something like this

$i = 1;
while(.....){
echo $i; echo $yourdata;
$i++;
}

try something like this

$i = 1;
while(.....){
echo $i; echo $yourdata;
$i++;
}

Thanx Dude for Help....
I am Solve my Problem with your Suggestion..
and mark this thread to Solved..

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.