Announcement

Collapse
No announcement yet.

PHP parse errors

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    PHP parse errors

    I've just learnt some basic php and I'm trying to make my new v8 layout with featured products in 3 columns at the top of the page above the rest of the products. Pretty much like our v7 site here for example: http://www.ukbikestore.co.uk/acatalo...BIKES_153.html

    Norman gave me some advice in another thread about how to do it and I've decided to use one product template for the listed products, and a different one for the featured ones at the top (which will be product duplicates).

    The list layout settings for the template have had the row and column parts removed and instead they are put into the beginning and end of the product template.

    the featured products now need code in them to start a new row if they are the first product, and end that row if they are the third. i have come up with this but it comes up with parse errors:

    Code:
    <actinic:block php="true" >
    $colnum = "0";
    $colnum++;
    if ($colnum = "1")
    echo "<tr>";
    </actinic:block>
    <td>
    
    REST OF PRODUCT TEMPLATE
    
    </td>
    <actinic:block php="true" >
    if ($colnum = "3")
    echo "</tr>";
    $colnum = "0";
    </actinic:block>
    I've messed around with it lots and now my head hurts! Anyone see any reason why this shouldnt work?

    Thanks

    Dave

    #2
    if ($colnum = "1")

    should be

    if ($colnum == 1)
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment


      #3
      Also you've set $colnum to be "0" This is a string that just happens to contain a zero. Best use $colnum = 0; and no quotes elsewhere.
      Norman - www.drillpine.biz
      Edinburgh, U K / Bitez, Turkey

      Comment


        #4
        Hi norman,

        thanks for that, it now doesnt come up with any parse errors, however it doesnt seem to work either!

        having looked at the page preview source code it looks like it has put <tr> and </td> in every single product regardless of wether it is the 1st or 3rd item, as if $colnum always equals 1 and 3 at the same time

        Thanks

        Dave

        Comment


          #5
          There are two basic steps to programming. You have to write code that does the job you want and you have to get that code syntactically correct.

          Look through your code and you'll see that $colnum will never get past 1. You should set it to 0 outside the product layout.
          Norman - www.drillpine.biz
          Edinburgh, U K / Bitez, Turkey

          Comment


            #6
            Also it's best to use { } blocks with if statements.

            E.g.
            Code:
            if ($colnum == 3)
              {
              echo "</tr>";
              $colnum = "0";
              }
            Norman - www.drillpine.biz
            Edinburgh, U K / Bitez, Turkey

            Comment


              #7
              Finally. Use the echo statment liberally while testing. E.g.

              echo "<br>At line 4 and column number is $colnum";
              Norman - www.drillpine.biz
              Edinburgh, U K / Bitez, Turkey

              Comment


                #8
                Many thanks Norman, got it sorted now - moving the variable to a higher template sorted it.

                Dave

                Comment


                  #9
                  Nicely done Dave. There's a huge capability in having PHP built-in. As you've just discovered, it's a lot more satisfying being able to create the solution yourself.
                  Norman - www.drillpine.biz
                  Edinburgh, U K / Bitez, Turkey

                  Comment

                  Working...
                  X