SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot naynay99's Avatar
    Join Date
    Jan 2010
    Location
    Los Angeles
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how do I give each item a name using the ++ in a FOR statement?

    I barely know PHP and a friend came over today and helped me immensely. I feel bad asking for more help. So I am hoping you guys can help me. I made a nice looking page but every product on it is called productFI1. I need them to be incremented in the for loop so I can style them in css so each can have its own name. Here is the code I have. I know I probably have to create some variable to hold them, but I have no idea how.

    Code:
       <?php
               include "connect.php";
    $conn=ShopConnect();
    
    $query = "Select * from products where featuredItem = 1;";
    $retval = mysql_query($query, $conn);
    $rowNum = mysql_num_rows($retval);
    $colcount=3;
    $rowcount= $rowNum/$colcount;
    
       ?>
      <span class="sectionTitle">Featured Items </span><br /><br />
       <div id="featuredItems">
                       <table width="802" >
      <tr>
      
        <?php
                       for($i=0;$i < $rowcount;$i++) //down
                       {
                           echo ("<td>");
                           for($j=0;$j < $colcount;$j++) //across
                           {
                                 while ($row = mysql_fetch_array($retval, MYSQL_ASSOC)) 
                                {
                                    $ID=$row['prodID'];
                         echo("<div id='productFI1'> <img src='" . $row['itemImg'] . "'/></div>" .
                          "<div id='prodName'>" . $row['prodName'] . "</div>" .
                          "<div id='prodDesc'>" . $row['prodDesc'] . "</div>" .
                          "<div id='prodPrice'>" . $row['prodPrice'] . "</div>" .
                          "<div id='prodRate'>" . $row['prodRate'] ."</div>");
                    
                                }
                           }
                       }
                       
                   
                
                   ?>

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    echo("<div id='productFI$j'> <img src='" . $row['itemImg'] . "'/></div>" .
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Zealot naynay99's Avatar
    Join Date
    Jan 2010
    Location
    Los Angeles
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    echo("<div id='productFI$j'> <img src='" . $row['itemImg'] . "'/></div>" .
    Thank you for the speedy reply fellgall( btw, I follow you on twitter), but now I am getting this error after replacing your line of code with the code I had.

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/content/62/7956662/html/test/index1.php on line 48

    line 48 is this line.
    "<div id='prodName'>" . $row['prodName'] . "</div>"

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Are you sure you just replaced the 1 with $j and didn't accidentally change anything else (such as removing the dot from the end of the line so that line 48 is no longer identified as validly continuing the same statement.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Tags for this Thread

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
  •