View Full Version : specific output from sql
gurmeet
12-18-2009, 11:37 AM
hi, there are some record stored in a table and i want to retrieve some record , can i add serials numbers in front of every record?
i.e there is a table
index name designation
==============================
1 tom clerk
.
.
22 jeck clerk
.
.
100 Harry clerk
.
.
1001 Rohit clerk
a table like this...
------------------------------------------------------------------
i want out put like this
1. tom clerk
2. jeck clerk
3. harry clerk
4. rohit clerk
means i want a serial no. with every record from database.....
as 1,2,3,4 are the serial no. for every record , as its not stored in database... but i want to add it in out put...
plz, if u can understand then plz reply...
MrRSMan
12-18-2009, 07:08 PM
Try this:
$query="SELECT * FROM {$table};
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
echo'<ol>';
while ($i < $num) {
$var=mysql_result($result,$i,"field_name");
echo'<li>$var</li>';
}
echo'</ol>';
gurmeet
12-21-2009, 05:54 AM
hmm, but it will show he data in 1., 2., 3., 4., number only, but i want to assign these numbers to this data value only... means if i calls the data numbered 1, then the record belonging to 1 should be printed or called...
means i not only want to print this data in this format only, but also want to use these values(1,2,3,4) in my programse whenever its required..
djr33
12-21-2009, 06:26 AM
The usual way to do this is to create two columns, one for the number and one for the name. You can use "auto increment" to make it do 1, 2, ..., x, for every name added.
gurmeet
12-21-2009, 06:46 AM
i.e there is a table
index name designation
==============================
1 tom clerk
.
.
22 jeck clerk
.
.
100 Harry clerk
.
.
1001 Rohit clerk
a table like this...
------------------------------------------------------------------
i want out put like this
1. tom clerk
2. jeck clerk
3. harry clerk
4. rohit clerk
means i want a serial no. with every record from database.....
as 1,2,3,4 are the serial no. for every record , as its not stored in database... but i want to add it in out put...
plz, if u can understand then plz reply...
as described above, data is stored into database,
but in output i want i need a index number,
as harry is on 3rd number so 3 number is the index in output,
in some situation it comes on 2nd number the index must b 2
i think i need not to dscribe a column in database...
gurmeet
12-21-2009, 06:47 AM
is there any expert who have chat ID where i can ask in detial n make him/her understand regarding my problem?
gurmeet
01-08-2010, 02:31 PM
plz help me by giving ur suggestions ...
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.