Results 1 to 1 of 1

Thread: discount code script problems needs a loop ??

  1. #1
    Join Date
    Nov 2011
    Thanked 0 Times in 0 Posts

    Default discount code script problems needs a loop ??

    to let you know i did post this problem i am having on another forum a while back but to no i thought someone here may be able to help.

    The way i have set this up is in the backend of the site i can add my own discount codes with the following rules we have a % and a value, in this case

    the % is represented by f and the = p so when ever you make a new code you enter either f or p followed by the value of the discount so examples

    lot123p5 ( this is 5 off )
    lot123f10 ( this 10% off )

    the voucher code is as follows

    PHP Code:
    // voucher code
    if (isset($_POST['vouchCode']) && $_POST['vouchCode'] == $row_rsVoucher['VCode']) {
    $mycode $row_rsVoucher['VCode'];
    $spos strpos($mycode"f");
      if (
    $spos !== false) {
    $myvalue substr($mycode$spos+1);
    $myvalue $XCart_sumTotal $myvalue 100;
      } else {
    $spos strpos($mycode"p");
        if (
    $spos !== false) {
    $myvalue substr($mycode$spos+1);
    $myTotal $XCart_sumTotal $myvalue;
    $_SESSION['vouchCode'] = $myvalue;
    } else unset(

    DoFormatCurrency($num,$dec,$sdec,$sgrp,$sym,$cnt) {
      if (
    $sdec == "C") {
    $locale_info localeconv();
    $sdec $locale_info["mon_decimal_point"];
    $sgrp $sgrp!="" $locale_info["mon_thousands_sep"] : "";
    $sym $cnt!="" $locale_info["currency_symbol"] : $sym;
    $thenum $sym.number_format($num,$dec,$sdec,$sgrp);

    what is happening is i have echoed out
    PHP Code:
    <?php echo $myvalue ?><br />
    <?php echo $_POST['vouchCode']; ?><br />
    <?php echo $row_rsVoucher['VCode']; ?> <br />
    the <?php echo $row_rsVoucher['VCode']; ?> is always showing the lot123p5 which is the first record on the DB

    when i submit the value lot123p5 i get the following

    <?php echo $myvalue ?> shows 5
    <?php echo $_POST['vouchCode']; ?> shows lot123p5
    and <?php echo $row_rsVoucher['VCode']; ?> shows lot123p5

    so thats working

    when i try the percentage and submit lot123f10 i get the following

    PHP Code:
    <?php echo $myvalue ?> shows nothing
    <?php echo $_POST['vouchCode']; ?> shows lot123f10
    and <?php echo $row_rsVoucher['VCode']; ?> shows lot123p5
    and therefor isnt working

    i have added another discount code to the discount to see if it was and issue with %


    to show 3 discount but that isnt working either so the script must only be calling the first record in the database

    since this post began i have found out more information so can expand on what i think is need.

    because the issue is the script is only checking the first record of the database an loop is needed to check all the records. But i am unclear on how to do this

    PHP Code:
    $query_rsVoucher "SELECT * FROM LOTTIE_vouchercode";
    $rsVoucher mysql_query($query_rsVoucher$lotties) or die(mysql_error());
    $row_rsVoucher mysql_fetch_assoc($rsVoucher);
    $totalRows_rsVoucher mysql_num_rows($rsVoucher); 
    is where the information is coming from

    so a loop is required to produce all the results but dont know how to do it.

    i did look at some tutorial that were suggested

    PHP Code:
    $query_rsVoucher "SELECT * FROM LOTTIE_vouchercode";
    $rsVoucher mysql_query($query_rsVoucher$lotties) or die(mysql_error());
    $row_rsVoucher mysql_fetch_assoc($rsVoucher) or die(mysql_error());
    $row_rsVoucher mysql_num_rows($rsVoucher)){
    $totalRows_rsVoucher mysql_num_rows($rsVoucher); 
    but this produced the same results

    the form that check to see if the code is present is

    HTML Code:
    <form action="<?php echo $editFormAction; ?>" method="post" name="form2" id="form2">
                    <td class="mediumPinkHeaders">Voucher Code:</td>
                    <td><input type="text" name="vouchCode" value="<?php echo @$_POST['vouchCode']; ?>" size="32" /></td>
                    <td><input type="submit" value="update" /></td>
    Last edited by jonnyfreak; 06-17-2013 at 06:17 PM.

Similar Threads

  1. discount voucher how to set up using php
    By jonnyfreak in forum PHP
    Replies: 0
    Last Post: 03-08-2013, 07:11 PM
  2. CSS code causes problems with alignment in ff
    By csshelp in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 01-31-2009, 05:05 AM
  3. problems with frog code
    By a1i.c in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 07-10-2007, 01:59 PM
  4. Problems with CSS image pop up code
    By zach101 in forum CSS
    Replies: 6
    Last Post: 06-13-2006, 12:06 PM


Posting Permissions

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