Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP: How do I create a numbered sequence in a foreach loop?

Featured Replies

Hi, when a search returns a listing, I'd like a numbered sequence like:

1

2

3

4

any example of how to do this?  I appreciate your help! :)

In normal PHP, you would do something like this:

<?php
$arr 
= array("one""two""three");

$c = 1;
foreach ($arr as $value) {
    echo $c.
") ".$value."<br />\n";
    $c++;
}

?>

Does this help?

If you need to set a "value" for each row returned (sort of like the @@ in FileMaker layout mode), based on the sorted results, of course:

I couldn't find any method that does this, but may be a differnt method.

 

Before loop, set $varCount to 0

$varCount = 0;

 

Then in each for-each loop (within table cell if needed) to output other found results:

 

$varCount = $varCount + 1;

echo $varCount;

 

There may be a return value for the Row Num or such in the XML results, I just don't know at the moment. If there is, than you can use that value. the xml value for the element resultset attribute 'count' of course would give you how many records/rows are returned.

 

Beverly,

Does not 

$varCount++;

increment that value by one? Curious... It does in raw PHP.

yes, of course ++ is standard PHP for increment 1 and would also work. thanks, DW!

beverly

  • Author

Thanks for everyone's suggestions, I will try them out!

  • Author

Thanks Beverly and dwdata, that worked great!

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.