Jump to content

Default timezone and coupon_id error


paresh15

Recommended Posts

Hi,

 

Please help to resolve this script.

 

Default time zone is not working properly it shows time only in AM (PM is not working) and in the INDIAN time 7:00pm  to 7:00am table never fetch any content.

<div class="cart">
                    <table width="100%" height="100%" cellspacing="0" cellpadding="10">
                        <tbody>
                            <tr style="margin: 5px; padding-bottom: 5px; background-color:#ececec; line-height:30px">
                                <td style="width: 10%;">
                                    <span>
                                        Sr. No.
                                    </span>
                                </td>
                                <td style="width: 15%;">
                                    <span>
                                        Order Id
                                    </span>
                                </td>
                                <td style="width: 35%;">
                                    <span>
                                        Order Date / Time
                                    </span>
                                </td>
                                <td style="width: 10%;">
                                    <span>
                                         Amount
                                    </span>
                                </td>
                                <td style="width: 35%;">
                                    <span>
                                         Coupon Name
                                    </span>
                                </td>
                                <td style="width: 10%;">
                                    <span>
                                        Action
                                    </span>
                                </td>                                  
                            </tr>
                            <tr>
                              <td colspan="5" height="10"></td>
                            </tr>
                            
                            <?php
                                date_default_timezone_set("Asia/Dili");
                                $session_user_id = $_SESSION['userId'];
                                $ordercount=1;
                                $current_date = date('Y-m-d');
                                $order_id = $_SESSION['new_order_id'];
                                $query = "select * from cs_order where order_id = '$order_id'";
                                if(!($result = mysql_query($query))) { echo $query.mysql_error(); exit; }
                                $order_items = mysql_fetch_array($result);
                                
                                $order_transaction_id = $order_items['order_transaction_id'];
                                $order_transaction_date = $order_items['order_transaction_date'];
                                $order_currency_id = explode(", ", $order_items['order_currency_id']);
                                $order_amount = $order_items['order_amount'];                                            
                                $order_coupon_id = explode(", ", $order_items['order_coupon_id']);                                        
                                                                
                                $new_order_currency_id = $order_currency_id[0];                                                                                        
                                
                                if(strtotime(date('Y-m-d', strtotime($order_transaction_date)))==strtotime($current_date)) {                             
                            ?>
                            <tr>
                                <td style="width: 10%;">
                                    <span>
                                        <?=$ordercount; ?>
                                    </span>
                                </td>
                                <td style="width: 10%;">
                                    <span>
                                        <?=$order_transaction_id; ?>
                                    </span>
                                </td>
                                <td style="width: 25%;">
                                    <span>
                                        <?=date('d M Y / h:i a', strtotime($order_transaction_date)); ?>
                                    </span>
                                </td>
                                <td style="width: 10%;">
                                    <span>
                                        <?=$new_order_currency_id; ?> <?=$order_amount; ?>
                                    </span>
                                </td>
                                <td style="width: 25%;">
                                    <span>
                                    <?php
                                        $user_id = $_SESSION['userId'];
                                        $current_date = date('Y-m-d');
                                        $order_id = $_SESSION['new_order_id'];
                                        $query = "select * from cs_order as ord left join cs_countries as country on ord.order_country = country.country_id left join cs_states as state on ord.order_state = state.    state_id left join cs_cities as city on ord.order_city = city.    city_id where ord.order_id = '$order_id' and  ord.order_user_id = '$user_id' and ord.order_transaction_date like '$current_date %:%:%'";
                                        if(!($result = mysql_query($query))) { echo $query.mysql_error(); exit; }
                                        $total_invoice_amount = 0;
                                        while($invoice = mysql_fetch_assoc($result)) {
                                            $invoice_record[] = $invoice;
                                        }                        
                                    ?>
                                        <?php echo $invoice_record[0]['order_coupon_name']; ?>
                                    </span>
                                </td>
                                
                                <td style="width: 15%;" align="center">
                                    <span>
                                        <form action="" method="post" name="formGetcode">                                            
                                            <?php
                                                foreach($order_coupon_id as $coup_id) {
                                                    $checkout_couponid = $coup_id['order_coupon_id'];
                                                    $checkoutquery = "select * from cs_coupons as coup left join cs_company as comp on coup.coupons_store = comp.retailer_id where coup.coupons_id = '$checkout_couponid'";
                                                    if(!($checkoutresult = mysql_query($checkoutquery))) { echo $checkoutquery.mysql_error(); exit; }
                                                    $coupon = mysql_fetch_array($checkoutresult);
                                                    $checkout_couponurl = $coupon['coupons_website'];
                                                    $coup_type = $coupon['coupons_type'];                                        
                                            ?>
                                            <?php if($coup_type=='R') { ?>                                                                                    
                                            <button class="submit button" type="button" onclick="getCodePopup(<?=$checkout_couponid; ?>, '<?=$checkout_couponurl; ?>');" style="font-size:11px;width:86px;">Get Code</button>
                                            <?php } else { ?>
                                                <button class="submit button" type="button" onclick="getPrintPopup(<?=$checkout_couponid; ?>);" style="font-size:11px;width:86px;">Print Coupon</button>
                                            <?php } } ?>
                                        </form>
                                    </span>
                                </td>
                               
                            </tr>
                            <?php $ordercount++; } ?>  
                             
                            <tr>
                              <td colspan="5" height="20"></td>
                            </tr>                                                     
                        </tbody>
                    </table>
                </div>
                </div><!--cart container close here-->


And

<script type="text/javascript">
    function getCodePopup(str1, str2) {
        var cid = str1;
        var curl = str2;                    
        window.open('getcouponcode.php?id=' +cid, 'open_window',  ' width=540, height=480, left=0, top=0');        
        window.open(curl,'_blank');
    }
    
    function getPrintPopup(str1) {
        var cid = str1;                                
        window.open('printCoupon.php?id=' +cid, 'open_window1',  ' width=640, height=320, left=0, top=0');                
    }
</script>

Pop Up code not fetching Coupon ID after number 9.

 

Please help me to solve this.

 

Thanks.

 

Paresh

 

 

 

Edited by mac_gyver
code tags please
Link to comment
Share on other sites

some comments about your code (some of which actually have something to do with why it is not working) -

 

1) Please use the forum's


bbcode tags (the edit form's <> button) around code when posting it in the forum. this will increase the chance of people even looking at your code. i edited your post above to add code tags.

 

2) you need to separate your business logic (the php code that determines what to do on the page and gets the data that the page needs) from the presentation logic (the html/css/javascipt and minimal php code that outputs the content on the page.) this alone will reduce the amount of code because the majority of the php logic will be in one place and you will be able to see things like the duplicated lines of code, values that are defined but never used, values that are used that are not defined... it will also let you see the main program logic in one consolidated place so that you and us can figure out what it is doing (some of your code makes no sense, such as only displaying the output if the current date and the order_transaction_date are the same - what happens if someone placed an order before midnight and tries to view the order after midnight?)

 

3) don't run database queries inside of loops. this results in a noticeable performance loss. for related queries, you should use one joined query. for getting the information about a list of input data, you should run one query that gets all the information at once.

 

4) don't store comma separated lists of values in a column in a database table. you should have one more table that holds the values, one per row, that is related back to the parent table using the id's.

 

5) the error listed in post #2 likely refers to this line - $checkout_couponid = $coup_id['order_coupon_id']; $coup_id isn't an array, it's a value from the foreach(){} loop that is itself looping over an exploded list of values. if you follow my recommendations about your code, this foreach loop and the query you are running inside of it will be eliminated anyway.

Edited by mac_gyver
Link to comment
Share on other sites

This code must be worthy of an award

 


$current_date = date('Y-m-d');

. . .

if(strtotime(date('Y-m-d', strtotime($order_transaction_date)))==strtotime($current_date)) {

 

 

Let's add the comments

// Store current date in Y-m-d format
. . .
// Get date from database (which should be in Y-m-d format)
// Convert this to Unix time
// Convert this Unix time back to Y-m-d
// Convert the Y-m-d back to Unix time

and compare against the current stored Y-m-d date converted to Unix time

instead of 

if ($order_transaction_date == $current_date) {
Edited by Barand
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.