Announcement

Collapse
No announcement yet.

php /MySql code into fragment & multiple products into cart via hyperlink

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

    php /MySql code into fragment & multiple products into cart via hyperlink

    Sorry for long post!
    Help needed to integrate a working php / html page into a fragemnt.
    Actinic Support have failed so far!!

    I have a client who has 1100 small products with very similar part numbers.
    To help the end user I have created a MySql database and was planning to use this to build a part number and Qty to insert into the cart using for example - http://eogb.co.uk/cgi-bin/ca000001.p...Da-1.1-80-H=10
    Once my client has added all 1100 products I propose to hide the section containing the products then use the code running in the fragment to generate the part number and quantity which will be then be inserted into the cart via a string generated as above.

    The Section ID and part number I will extract from the Actinic db and import into the product selector php/MySqL database.


    Here is the code I am trying to insert into a fragment as either code enclosed within !!< >!! or a variable.
    I have tried code within !!< >!!, also !!<[variable name ]>!! in the text box, also inserting the variable into the fragment layout.
    I have also tried <actinic:block> include <filename> etc.
    All have not worked.

    Tested and working page as standalone php - http://www.neobium.net/testing/EOGB/results_EOGB4.php

    make selections and add quantity and press +

    This gives this page - http://www.neobium.net/testing/EOGB/proof.php

    Code

    <?php
    session_start ();

    //connect to server and select database
    $db_name ="neobium_net";
    $table_name ="EOGB";
    $connection =@mysql_connect("localhost","neobium_net","b1u3t4c") or die(mysql_error());
    $db =@mysql_select_db($db_name,$connection) or die(mysql_error());

    // count rows
    // get rows results
    $result = mysql_query("SELECT * from $table_name")
    or die(mysql_error());
    $dbrows= mysql_num_rows($result);

    // check if qty posted or reset pushed , clear all sessions for another search
    if (isset($_POST['Qty'])||isset($_POST['reset']) ) {
    //clear all sessions
    $_SESSION['mk'] = "";
    $_SESSION['pat'] = "";
    $_SESSION['ds'] = "";
    $_SESSION['cs'] = "";
    }


    // get form results
    $Make = $_POST['Make'];
    $Pattern = $_POST['Pattern'];


    //set sessions
    if($Make !=''){
    $_SESSION['mk'] = "$Make";
    //clear pat sessions
    $_SESSION['pat'] = "";
    }
    // set pat session
    if($Pattern !=''){
    $_SESSION['pat'] = "$Pattern";
    }

    ?>

    <HTML>
    <HEAD>
    <TITLE>EOGB Nozzles Data Demo</TITLE>
    </head>
    <body>
    <style type="text/css">
    <!--
    body {background-color: #ffffff;}
    .red {background-color: #ff0000;}
    .green{background-color: #339933;}
    -->
    </style>
    <h3>EOGB Nozzles Search<br></h3>
    <hr size="3" width="100%">
    <h3><p>Searching <? echo $table_name; ?> Database</p></h3>
    <p>The database contains <? echo $dbrows; ?> nozzles</p>
    <div align="right">
    <div id="show" align="right"></div>
    </div>
    <h4>Please Select an item from each box</h4>
    <form name='form1' method='post' action=''>
    Maker:&nbsp;<select name='Make' onChange='document.form1.submit()'>
    <option value="">Maker</option>
    <option <? if($_SESSION[mk]=="Danfoss"){echo"selected";} ?> value="Danfoss">Danfoss</option>
    <option <? if($_SESSION[mk]=="Delevan"){echo"selected";} ?> value="Delevan">Delevan</option>
    </select>
    </form>

    <form name='form4' method='post' action=''>
    Spray Pattern:&nbsp;<select name='Pattern' onChange='document.form4.submit()'>
    <option value="">Spray Pattern</option>
    <?
    if($_SESSION['mk']!=''){
    //run query to get next box here.
    $Extract3 = mysql_query("SELECT DISTINCT Pattern FROM $table_name WHERE Make = '$_SESSION[mk]' ORDER BY Pattern ASC")
    or die(mysql_error());
    while ($row = mysql_fetch_array($Extract3)){
    $Items3 = $row['Pattern'];
    if($_SESSION[pat]!="$Items3"){$t3="";}else{$t3="selected";}
    echo"<option $t3 value=\"$Items3\">$Items3</option>";
    }
    }
    ?>
    </select>
    </form>
    If you make no selection on any displayed table, press reset to make another choice.<br>
    <form action="" method="post" name="reset">
    <input type="hidden" name="reset" id="reset" value="1">
    <input name="Reset " type="submit" Value = "Reset">
    </form>
    <?
    //Diagnostic echo
    //echo "<strong>Diagnostic Output</strong> <br>";
    //echo "<strong>Posted Vars</strong> <br>";
    //echo "Posted Make = ".$Make ."<br>";
    //echo "Posted Pattern = ".$Pattern ."<br>";
    //echo "<strong>Sessions Vars</strong> <br>";
    //echo " Make Session = ".$_SESSION['mk']. "<br>";
    //echo " Pattern Session = ".$_SESSION['pat']. "<br><br>";
    // start table
    ?>
    <table cellspacing="0" width="400" cellpadding="0" border="1">
    <tr>
    <td class="" width="60">USgal/hr</td>
    <?
    // get angles for column headers based on make
    $n=0;
    $Extract4 = mysql_query("SELECT DISTINCT Angle FROM $table_name WHERE Make = '$_SESSION[mk]' AND Pattern = '$_SESSION[pat]' ORDER by ANGLE ASC")
    or die(mysql_error());
    while ($row = mysql_fetch_array($Extract4)){
    echo "<td width='50' align='center'>" .$row['Angle']. "</td>";
    $n = $n+1;
    $ang[$n] = $row['Angle'];
    }
    ?>
    </tr>
    <!-- start new fetched rows -- >
    <tr>
    <?
    $Extract5 = mysql_query("SELECT DISTINCT GPH FROM $table_name WHERE Make = '$_SESSION[mk]' AND Pattern = '$_SESSION[pat]'")
    or die(mysql_error());
    $row = mysql_fetch_array($Extract5);

    $count = 1;

    do{
    echo "<td width='50' align='center' valign='middle'>" .$row['GPH']. "</td>";

    // each angle query
    for ( $counter = 1; $counter <= $n; $counter += 1) {
    $Extract6 = mysql_query("SELECT * FROM $table_name WHERE Make = '$_SESSION[mk]' AND Pattern = '$_SESSION[pat]' AND GPH = '$row[GPH]' AND Angle='$ang[$counter]' ")
    or die(mysql_error());
    $row1 = mysql_fetch_array($Extract6);
    // assemble part strings
    $actcart1 = "http://eogb.co.uk/cgi-bin/ca000001.pl?SID=";
    $actcart2 = "&PAGE=PRODUCT&Q_";
    $partdesc = $_SESSION[mk]."-".$_SESSION[pat]."-".$row['GPH']."-".$ang[$counter];
    $partnum = $row1['Part_num'];
    $SID = $row1['SID'];
    $cartstring = $actcart1.$SID.$actcart2.$partnum."=";
    $cartstring = urlencode($cartstring);
    // set strings as sessions
    $_SESSION['ds'] = "$partdesc";
    $_SESSION['cs'] = "$cartstring";

    //echo " Diags <br>";
    //echo " gph= ".$row['GPH']."<br>";
    //echo "angle=".$ang[$counter]."<br>";
    //echo "partdesc=".$_SESSION[ds]."<br>";
    //echo "partnum=".$partnum."<br>";
    //echo "SID=".$SID."<br>";
    //echo "cartstring=".$_SESSION[cs]."<br>";
    //echo "cart2=".$actcart2."<br>";

    // start rows
    if(!empty($row1))
    {
    echo "<td class='green' align='center' valign='middle'>";
    echo "<form name=\"form$count\" method=\"post\" action=\"basket.php\">";
    echo "<input type=\"text\" size=\"3\" maxlength=\"3\" name=\"Qty\" >";
    echo" <input type=\"image\" src=\"plus.gif\" alt=\"Submit button\" width=\"20\" height=\"20\" border=\"0\" >";
    echo "</form>";
    echo "</td>";
    }else{
    echo "<td class='red' align='center' valign='middle'>&nbsp;</td>";
    }
    } //end counter for
    echo "</tr>"; // end row

    $count++;
    }while($row = mysql_fetch_array($Extract5));


    ?>
    </table>


    <hr>

    </body>
    </HTML>

    #2
    Have you given the page name a .php extension instead of the normal .html?

    You can't have HEAD, HTML, TITLE, BODY tags etc. as the overall template has these also, so will be guaranteed to bork something. Having code within a fragment is like having that code inserted in the body tag in effect, within the overall site framework. Firebug it as you will see you are trying to put a page framework within a framework that exists already.

    The inbuilt php engine runs on the desktop for page compilation, not online as i suspect you might be thinking.

    Comment


      #3
      All have not worked.
      In what way?

      i.e. Is the PHP not in the page? Are you seeing the PHP rather than it being parsed? etc.

      Mike
      -----------------------------------------

      First Tackle - Fly Fishing and Game Angling

      -----------------------------------------

      Comment


        #4
        php in fragment

        Lee, thanks for pointing out what I had missed .php is required! duh.
        I have tried using htaccess control to allow a single .html page to be run as php, but this is very messy.
        The working php also has a session start () as the first line which if I remember php will not work if called half way down the page, as it will be in the fragment.
        I think I am pushing water up hill.
        I have the display part working as a stand alone pop-up window, using standard javascript inserted into the fragment plus my working php code, now moving on to getting the items into the basket.

        Thanks for pointing out the obvious.
        A wise man said " When you are up to your a$%e in alligators it is difficult to remember you were trying to drain the swamp".

        Comment


          #5
          If you need certain code to be in a certain area on a certain page, that's quite easy to do using a blockif. Add the code into the overall layout and wrap it in a blockif that checks to see whether a new variable you create is set to either true or false. You can then have a switch to add or exclude this on any page you wish.

          The croc analogy made me chuckle, been there only too many times myself .

          Comment


            #6
            in fact, none of this will work.

            in order for an item to be purchasable in actinic, it needs a *.cat file entry.

            it does not matter what you insert where and build from what, without a cat file, you're goosed.

            create the products in actinic

            Comment


              #7
              What does work is creating a template, with a block of php in it, and using that template in your store.

              just duplicate a template and find the content part in that template. replace it with your php, <? ?> and all.

              as said before, set the extension to php.

              you could also use htaccess hacks to make your html/htm files render as php.

              AddType application/x-httpd-php .php .htm .html
              AddHandler x-httpd-php .php .htm .html

              Comment


                #8
                with respect to using mysql, why dont you use odbc and connect to the local database, and build your lists locally.

                for an example of odbc connections, look at my php navigation.

                Comment


                  #9
                  php in fragment

                  Gabriel,
                  Thanks for comments, I was adding products into Actinic, they number 1100 so the php code is a database product selector to avoid a lengthy navigation.
                  I am using php/MySQL as I am familier with it.
                  I now understand the problem, the php in Actinic is a programatic tool to build html pages, my php code is for server side execution. A pity Actinic support could not have pointed this out having sent them a snapshot, my code and a working url, it would have saved me 12 days and a lot of confusion.
                  They have insisted all along php can run in Actinic, missed the elephant in the room!
                  Lee pointed this out and set me on the path to sanity.
                  I have it working as I wanted by using my original php file pulled into Actinic by using iframe.
                  The forum is THE place for technical answers.

                  Comment


                    #10
                    Another thing worth checking is that sometimes Actinic pages are served via Perl scripts and this may not let you process .php pages.

                    Examples are pages linked from search results and the error page if you add to cart with invalid parameters (try buying 20,000,000) of something.

                    The search results links can be fixed by unchecking "Highlight Located Text" in the search settings.

                    The error display page may be more problematical.

                    Your IFRAME way of doing things may bypass these problems but I thought it might be worth mentioning just in case...
                    Norman - www.drillpine.biz
                    Edinburgh, U K / Bitez, Turkey

                    Comment


                      #11
                      Multiple products into cart via hyperlink?

                      Has anyone any experience of putting multiple products into the cart via hyperlink. From the advanced users manual this can be done.
                      Technical support suggest multiples can be achieved with an '&' between products.

                      This example has two products, both from the same section and qty = 25

                      http://www.eogb.com/cgi-bin/ca000001...01-030B0203=25

                      One product works with no problems, this code adds only the first product.
                      Background
                      I am trying to put multiple products into the cart using a script to generate the complete string based on the customer choosing any number of products from a matrix.

                      Comment


                        #12
                        Have you looked at the single add to cart solution provided as standard, seems like it will do all you need. Example - http://www.hobuk.co.uk/acatalog/Trend_Stub_Augers1.html

                        Comment


                          #13
                          Multiple Products to cart

                          The products number over 1200, so I am using a MYSql database + php to reduce the choices down to smaller numbers. These are presented as a simple matrix with quantity boxes.

                          See -http://www.eogb.com/selector_RR.php
                          This php code here will be inserted into the shop in a frame within a fragment.
                          The 1200 products are hidden in the shop.

                          The script then accumulates those with positive quantities and builds the string ready to be sent to the cart.
                          My customer wants multiple products to be added to the cart from the matrix.

                          Comment


                            #14
                            I've merged your threads Ray, seems sensible to have all the information in one place .

                            Comment


                              #15
                              Comment

                              Not sure it is a good idea.
                              Same project but completly different problem, hence the different title!
                              Anyone with experience of cart issues will not be looking in sql and fragment titles
                              IMO

                              Comment

                              Working...
                              X