Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Php Echo Numbering

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Php Echo Numbering

Postby jason360 » Mon Mar 04, 2013 8:06 pm

Hey guys,

Just have a problem I don't know how to fix. I would like to number each echoed item from my query within the aside id tag for "techSlide" (aside id='techSlide).

I would like it to echo like this:

<aside id='techSlide1' class='ic_container'>
<aside id='techSlide2' class='ic_container'>
<aside id='techSlide3' class='ic_container'>
<aside id='techSlide4' class='ic_container'>
<aside id='techSlide5' class='ic_container'>
<aside id='techSlide6' class='ic_container'>

Thanks in advance!

Code: Select all
 $query = mysql_query('SELECT * FROM products WHERE quantity > 0 AND featured = 1 ORDER BY RAND() LIMIT 6');

                    $i = 0;

                    while ($row = mysql_fetch_array($query))

                    {

                       
                        echo "<aside id='techSlide' class='ic_container'>

                           <a href='http://www.mysite.com/shop/product.php?pid=".$row['id']."'>

                              <img class='titleImage' src='images/shop/".$row['id'].".jpg'  alt='".$row['name']."' />

                              <div class='overlay' style='display:none;'></div>
                              

                              <div class='ic_caption'>

                                 <p class='ic_category'>&#36;".number_format($row['price'] , 2)."</p>
                                 
                                 <h3>".$row['name']."</h3>
                           </a>
                                 <p class='ic_text'>

                                   ".$row['snippet']."

                                 </p>

                              </div>

                           

                       </aside>";      

                        

                        $i++;

                    }
jason360
New php-forum User
New php-forum User
 
Posts: 6
Joined: Sun Apr 17, 2011 11:08 am

Re: Php Echo Numbering

Postby simplypixie » Mon Mar 04, 2013 11:49 pm

You are nearly there. If you want the numbering to start at 1, change $i = 0; to $i = 1; and then chnage your echo to
Code: Select all
echo "<aside id='techSlide<?php echo $i; ?>' class='ic_container'>
User avatar
simplypixie
php-forum Active User
php-forum Active User
 
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire

Re: Php Echo Numbering

Postby jason360 » Tue Mar 05, 2013 3:04 pm

Worked perfect. Thanks!
jason360
New php-forum User
New php-forum User
 
Posts: 6
Joined: Sun Apr 17, 2011 11:08 am


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.