php - apply code to all looped items but last one -


I looping through some mysql results and and gt; & Lt; / Span & gt; / Code> For each of those, except for the last line, what is the easiest way to do this?

Do I have to calculate rows and then use a counter and an if / else statement? Or is there any easy way?

Try something like this:

  $ result = mysql_query ($ Sql); $ List = array (); While ($ row = mysql_fetch_assoc ($ result)) {$ list [] = $ row; } $ LastItem = array_pop ($ list); Foreign currency ($ $ as list of items) {echo sprintf ('& lt; span id = "bottom">% s ; $ item [' value ']); } // Do something with the last item.  

Not very short, but it must do the trick. Alternatively, you can do what you suggested:

  $ result = mysql_query ($ sql); $ Num = mysql_num_rows ($ result); For ($ i = 0; $ i & lt; $ num-1; $ i ++) {$ element = mysql_fetch_assoc ($ result); // resonate here.} $ Item = mysql_fetch_assoc ($ result); // Get the last item.  

All the best, Fabian


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -