SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    911
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Why this codes works? (Bootstrap)

    The codes,

    Code:
    	<?php
    	echo "<div class='row'>";
    		if(!empty($records)) {
    			foreach($records as $record) {
    	?> 
    				        <div class="span6">
    				        	<div id="" align="left">
    				        		<?php echo '<h2>'. $record['title'] .'</h2>'; ?>
    				        	</div>
    				        </div>
    	<?php
    			} 
    		}
    	echo "</div>";		
    	?>
    You can see it here,
    http://coder9.com/jazportfolio/

    Thanks.
    Last edited by solidcodes; May 9, 2013 at 10:08. Reason: wrong post
    I Love coding...
    Don't click this link.

  2. #2
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    911
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    If you try to look at the codes.
    There is only one
    Code:
    <div class="span6">
    </div>
    But as you can see it prints two columns meaning it prints two of these codes below,
    Code:
    <div class="span6">
    </div>
    Thanks in advanced for explaining why it works?
    I Love coding...
    Don't click this link.

  3. #3
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,285
    Mentioned
    181 Post(s)
    Tagged
    4 Thread(s)
    Welcome to Sitepoint.

    I suspect it is printing every record, but 'the last' record has no [title] value.
    Try this, as a test:
    Code:
    <div class="row">
    <?php
    if(!empty($records)) {
    	foreach($records as $record) {
    ?> 
            <div class="span6">
            	<div align="left">
            	<h2><?php echo $record['title']; ?></h2><p>The $record looks like this: <?php var_dump($record); ?></p>
            	</div>
            </div>
    <?php
    } 
    	}
    ?>
    </div>
    Also, you may notice the 'literal' strings do not need to be enclosed in PHP tags and 'echo'ed.


    I hope that is helpful. And the result may allow someone else to better assist you.
    My PHP skills are very rusty.
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  4. #4
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    911
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I think I should rephrase my explanation.
    It prints all the records along with these codes below,
    Code:
    <div class="span6">
    </div>
    The only odd is It has only one of this codes,
    Code:
    <div class='row'>
    </div>
    The good thing here is it doesn't show any error message.
    The bad things is, I guess it is against the rule of Bootstrap?

    Thank you very much in advanced, If you give shed to this matter.
    I Love coding...
    Don't click this link.

  5. #5
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,285
    Mentioned
    181 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by solidcodes View Post
    I think I should rephrase my explanation.
    It prints all the records along with these codes below,
    Code:
    <div class="span6">
    </div>
    The only odd is It has only one of this codes,
    Code:
    <div class='row'>
    </div>
    The good thing here is it doesn't show any error message.
    The bad things is, I guess it is against the rule of Bootstrap?

    Thank you very much in advanced, If you give shed to this matter.
    That is correct; based on the way it is coded. There is only one
    Code:
    <div class='row'>
    </div>
    and it is outside (not inside) the loop. That means it will appear exactly as you placed it (as if there is no other PHP code).
    If you move it within the loop, it will be printed for each iteration of the loop.

    If your intention is to style each row based on the number you can do this (although I would restructure the loop to use a counter and not "foreach"):
    Code:
    <?php
    $odd = true;
    if(!empty($records)) {
    	foreach($records as $record) {
    ?> 
       <div class="<?php echo ($odd) ? 'odd' : 'even'; ?>">
            <div class="span6">
            	<div align="left">
            	<h2><?php echo $record['title']; ?></h2>
            	</div>
            </div>
    </div>
    <?php
        $odd = !$odd;
        } 
    }
    ?>
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •