Avatar of Jazzy 1012
Jazzy 1012

asked on 

Add - in a loop to first and last element.

<?php
				$counter_price = 0;
				if(mysqli_num_rows($result_meal_price_option) > 1)
			while ($row_meal_price_option = mysqli_fetch_assoc($result_meal_price_option)) {
				$counter_price ++;
				$q_price_filters = "select * from main_filters where meal_options_id = '{$row_meal_price_option['id']}'";
				$result_price_filters = mysqli_query($conn,$q_price_filters);
				$row_price_filterd= mysqli_fetch_assoc($result_price_filters);
						?>
						<span class= "deliveryItem1
							 <?php 
                    		 if($row_price_filterd["vegan"] == 'Y'){echo "vegan ";}
                    		 if($row_price_filterd["vegetarian"] == 'Y'){echo "vegetarian ";}
                    		 if($row_price_filterd["pescatarian"] == 'Y'){echo "pescetarian ";}
                    		 if($row_price_filterd["dairy-free"] == 'Y'){echo "dairy-free ";}
                    		 if($row_price_filterd["egg-free"] == 'Y'){echo "egg-free ";}
                    		 if($row_price_filterd["fish-free"] == 'Y'){echo "fish-free ";}
                    		 if($row_price_filterd["shellfish-free"] == 'Y'){echo "shellfish ";}
                    		 if($row_price_filterd["tree nut-free"] == 'Y'){echo "tree ";}
                    		 if($row_price_filterd["peanut-free"] == 'Y'){echo "peanut ";}
                    		 if($row_price_filterd["soybean-free"] == 'Y'){echo "soy ";}
                    		 if($row_price_filterd["low-total-fat"] == 'Y'){echo "total-fat ";}
                    		 if($row_price_filterd["low-saturated-fat"] == 'Y'){echo "saturated-fat ";}
                    		 if($row_price_filterd["low-cholesterol"] == 'Y'){echo "cholesterol ";}
                    		 if($row_price_filterd["low-sodium"] == 'Y'){echo "sodium ";}
                    		 if($row_price_filterd["protein(25g)"] == 'Y'){echo "protein ";}
                    		 if($row_price_filterd["calories(450)"] == 'Y'){echo "calories ";}
                    		 ?>
                    		 ">
                    		 <?php
                    		 $price_soup= $row_meal_price_option['price'];
                    		 $price_soup = number_format($price_soup/100, 2);
                    		 $price_soup = "$" . $price_soup;

                    		 
                    		 //echo($counter_price>1 ? "- ":""). $price_soup;
                    		 
                    		 //echo $price_soup;
                    		 ?>
						</span>
					
						
						<?php }
								else{
									print_r($price1);
								}
								?>

Open in new window


I have this code, how can I echo out that when I have 2 prices it echos out price1-price2, if I have 3 it echos out price1-price3, if 4 = price1-price4, so technically, price1 - the last price, how is this possible with my code?
JavaScript

Avatar of undefined
Last Comment
Member_2_248744

8/22/2022 - Mon