Jump to content

php and HTML displaying contraversy!


co.ador

Recommended Posts

I am trying to achieve this

 

<fieldset class="tercero" style="" >
<legend>Services</legend> 
<ol>
<li>
  <input type="checkbox" name="example" value="delivery" style=" * position:relative; left:-16px; text-indent:inherit; positio\n:inherit; lef\t:13px; text-ali\gn:inherit;" /><span class="colo23">Delivery</span><br />
  <input type="checkbox" name="example" value="eat-in" /><span class="checkboxes23">Eat-in</span><br />
  <input type="checkbox" name="example" value="wifi" /><span class="checkboxes23">Wi-Fi</span><br />
  <input type="checkbox" name="example" value="buffet" /><span class="checkboxes23">Buffet</span><br />
  <input type="checkbox" name="example" value="tv" /><span class="checkboxes23">Tv</span><br />
  <input type="checkbox" name="example" value="parking" /><span class="checkboxes23">Parking</span><br />
  <input type="checkbox" name="example" value="catering" /><span class="checkboxes23">Catering</span><br />
  <input type="checkbox" name="example" value="take-out" /><span class="checkboxes23">Take Out</span><br/>
</li></ol>
</fieldset> 

 

foreach loop the input and span tags instead of repeat the <li> input and span tags Like.

 

     <fieldset class="tercero" style="" >
			<legend>Services</legend>
                 <ol> <li class="restaurants-offerings-4">
                                  <input type="checkbox" name="frmSearch[offerings][]" value="4" id="restaurants-offerings-4">
                                  <span for="restaurants-offerings-4" class="checkboxes23">Buffet</span>

                            </li><li class="restaurants-offerings-7">
                                  <input type="checkbox" name="frmSearch[offerings][]" value="7" id="restaurants-offerings-7">
                                  <span for="restaurants-offerings-7" class="checkboxes23">Catering</span>
                            </li><li class="restaurants-offerings-1">
                                  <input type="checkbox" name="frmSearch[offerings][]" value="1" id="restaurants-offerings-1">
                                  <span for="restaurants-offerings-1" class="checkboxes23">Delivery</span>
                            </li><li class="restaurants-offerings-2">
                                  <input type="checkbox" name="frmSearch[offerings][]" value="2" id="restaurants-offerings-2">

                                  <span for="restaurants-offerings-2" class="checkboxes23">Eat-in</span>
                            </li><li class="restaurants-offerings-6">
                                  <input type="checkbox" name="frmSearch[offerings][]" value="6" id="restaurants-offerings-6">
                                  <span for="restaurants-offerings-6" class="checkboxes23">Parking</span>
                            </li><li class="restaurants-offerings-5">
                                  <input type="checkbox" name="frmSearch[offerings][]" value="5" id="restaurants-offerings-5">
                                  <span for="restaurants-offerings-5" class="checkboxes23">TV</span>

                            </li><li class="restaurants-offerings-8">
                                  <input type="checkbox" name="frmSearch[offerings][]" value="8" id="restaurants-offerings-8">
                                  <span for="restaurants-offerings-8" class="checkboxes23">Takeout</span>
                            </li><li class="restaurants-offerings-3">
                                  <input type="checkbox" name="frmSearch[offerings][]" value="3" id="restaurants-offerings-3">
                                  <span for="restaurants-offerings-3" class="checkboxes23">Wi-Fi</span>
                            </li>               
            
            </ol></fieldset>

 

What is producing to repeat the li tags is the following script, I just want the input and span tags to repeat not the li

 

The script goes as follow

 

<?php <fieldset class="tercero" style="" >
			<legend>Services</legend>
                 <ol> <?php
                    foreach($arrRestaurantsOfferings as $arrRestaurantsOffering) {
                        printf(
                            '<li class="restaurants-offerings-%u">
                                  <input type="checkbox" name="frmSearch[offerings][]" value="%u" id="restaurants-offerings-%u"%s>
                                  <span for="restaurants-offerings-%u" class="checkboxes23">%s</span>
                            </li>'
                            ,$arrRestaurantsOffering['restaurant_offerings_id']
                            ,$arrRestaurantsOffering['restaurant_offerings_id']
                            ,$arrRestaurantsOffering['restaurant_offerings_id']
                            ,in_array($arrRestaurantsOffering['restaurant_offerings_id'],$arrOfferings)?' checked="checked"':''
                            ,$arrRestaurantsOffering['restaurant_offerings_id']
                            ,$arrRestaurantsOffering['name']
                        );
                    }
                ?>
               
            
            <?php } ?></ol></fieldset>
?>
            

 

 

The problem lays down here

 

<?php '<li class="restaurants-offerings-%u">
                                  <input type="checkbox" name="frmSearch[offerings][]" value="%u" id="restaurants-offerings-%u"%s>
                                  <span for="restaurants-offerings-%u" class="checkboxes23">%s</span>
                            </li>'
?>

 

I have changed to this

 

<ol><li> <?php
                    foreach($arrRestaurantsOfferings as $arrRestaurantsOffering) {
                        printf(
                            '
                                  <input type="checkbox" name="frmSearch[offerings][]" value="%u" id="restaurants-offerings-%u"%s>
                                  <span for="restaurants-offerings-%u" class="checkboxes23">%s</span>
                            '
                            ,$arrRestaurantsOffering['restaurant_offerings_id']
                            ,$arrRestaurantsOffering['restaurant_offerings_id']
                            ,$arrRestaurantsOffering['restaurant_offerings_id']
                            ,in_array($arrRestaurantsOffering['restaurant_offerings_id'],$arrOfferings)?' checked="checked"':''
                            ,$arrRestaurantsOffering['restaurant_offerings_id']
                            ,$arrRestaurantsOffering['name']
                        );
                    }
                ?>
               
            
            <?php } ?></li></ol>

 

In other words I have taken the <li> tags out of the loop but then "%u" which is the code that prints the name of the offering and pass in <li> tags and pass a value to the input id="restaurants-offerings-%u"> won't work, It won't pass and it will only display the id field of the food_offering tables next to the checkboxes which is the type of the input.

 

How can I get the string " %u" or the name of the offering to pass to the id of the input tags without having to put the li inside the loop and only leave the input and span tags inside the loop?

 

By the way the food_offering table has two field one is an integer called "restaurant_offerings_id" and it's represented as "%u" in the script above inside the foreach loop and the other is an string called "name" is represented as %s found inside the foreach loop as well.

Link to comment
Share on other sites

You'll need to use a double loop like the example below

 

<?php <fieldset class="tercero" style="" >
			<legend>Services</legend>
                 <ol> <?php
                    foreach($arrRestaurantsOfferings as $arrRestaurantsOffering) {
                        echo '<li class="restaurants-offerings-%u">';
                        foreach($arrRestaurantsOfferings as $arrRestaurantsOffering) {
                                printf(
                            '
                                  <input type="checkbox" name="frmSearch[offerings][]" value="%u" id="restaurants-offerings-%u"%s>
                                  <span for="restaurants-offerings-%u" class="checkboxes23">%s</span>
                            '
                        );
                        }
                        printf(
                            '
                                  <input type="checkbox" name="frmSearch[offerings][]" value="%u" id="restaurants-offerings-%u"%s>
                                  <span for="restaurants-offerings-%u" class="checkboxes23">%s</span>
                            </li>'
                            ,$arrRestaurantsOffering['restaurant_offerings_id']
                            ,$arrRestaurantsOffering['restaurant_offerings_id']
                            ,$arrRestaurantsOffering['restaurant_offerings_id']
                            ,in_array($arrRestaurantsOffering['restaurant_offerings_id'],$arrOfferings)?' checked="checked"':''
                            ,$arrRestaurantsOffering['restaurant_offerings_id']
                            ,$arrRestaurantsOffering['name']
                        );
                    }
                ?>
               
            
            <?php } ?></ol></fieldset>
?>

 

Please note that example probably won't work, it was just to show you a method that you can use to loop through all of the records and display your li tags and then display the span and input tags between each.

 

Depending on the exact output your looking for you may need to put in some if statements to stop the inner loop at a certain point so that the outter loop may continue.

Link to comment
Share on other sites

Eh you should not need two loops if I am understanding you right (which I may not be).

 

<?php
				echo '<li class="restaurants-offerings-' . $arrRestaurantsOfferings[0]['restaurant_offerings_id'] . '">';
                    foreach($arrRestaurantsOfferings as $arrRestaurantsOffering) {
                        printf('<input type="checkbox" name="frmSearch[offerings][]" value="%u" id="restaurants-offerings-%u"%s>
                                  <span for="restaurants-offerings-%u" class="checkboxes23">%s</span>'
                            ,$arrRestaurantsOffering['restaurant_offerings_id']
                            ,$arrRestaurantsOffering['restaurant_offerings_id']
                            ,in_array($arrRestaurantsOffering['restaurant_offerings_id'],$arrOfferings)?' checked="checked"':''
                            ,$arrRestaurantsOffering['restaurant_offerings_id']
                            ,$arrRestaurantsOffering['name']
                        );
                    }
				echo '</li>';
?>

 

I believe that is all you are looking for and it should work, given that the original array is 0-index based. However, I may have mis-read this and yea, mini may have the solution.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.