Forum Moderators: coopster

Message Too Old, No Replies

Outputting the list number

         

Joppiesaus

5:06 pm on Feb 3, 2009 (gmt 0)

10+ Year Member



Hello,

For my website I often use php to get a list of information. These lists are ordered by different variables on different pages.

What I want to do is get a number outputted which represents the place on which a certain listitem is outputted.

For instance this is the outputted list:

-Shirts
-trousers
-jackets
-hats

I then would like to be able to also show:

1 shirts
2 trousers
3 jackets
4 hats

I need this to be a variable or something like I output normal variables (<?php echo $row_Recordset1['outputnumber']; ?>) so I can use this to number the list and show special images before them (example.com/images/<?php echo $row_Recordset1['outputnumber']; ?>.jpg), so I cannot do this using an order list.

Anyone know how to do this?

[edited by: eelixduppy at 6:29 pm (utc) on Feb. 3, 2009]
[edit reason] disabled smileys [/edit]

coopster

1:23 pm on Feb 4, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You mean just an incrementing number, like a counter?
$count = 0; 
while ($count <= 9) {
print ++$count;
}

Joppiesaus

1:33 pm on Feb 4, 2009 (gmt 0)

10+ Year Member



Kind of,

Except I want to place it here:

<?php do { ?>

< OUTPUT THE NUMBER > <?php echo $row_Recordset4['name']; ?>

<?php } while ($row_Recordset4 = mysql_fetch_assoc($Recordset4)); ?>

So, Ive put a repeat region on the name, and for every name that turns up there must be a higher number...

Hope this clarifies, if you need info, please let me know.

coopster

2:05 pm on Feb 4, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Use the same type of logic demonstrated ... set a counter with an initial value outside your loop. Then inside the loop increment the counter as your logic requires. If it is on every iteration, do as I demonstrated. If it is only to be incremented based on some other logic, put the increment inside a logical control structure:
$count = 0; 
do {
// if you want it incremented every time:
++$count;
// increment based on some other logic:
if (name changed) {
++$count;
}
} while ();