Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP problem

Options
  • 01-07-2008 10:31am
    #1
    Registered Users Posts: 224 ✭✭


    :eek::confused:Hi,

    Im having a problem with some php programming. Basically i have a php page that i need to add some code to. I need a piece of script to check out where the user is from and display a gif depending where they are from. Im not accustomed to php only asp. Id usually use something like this...

    ****************************************************
    <%
    Dim strQMACImage
    Dim vMacbtn
    vMacbtn=false
    If rsFlags.Fields("user_currency").Value = "EUR" Then
    vMacbtn=true
    End If
    If vMacbtn=false then
    strQMACImage="images/irishflag.gif"
    Else
    strQMACImage="images/uk-flag.gif"
    End If

    %>
    <div align="center"><img src="<%=strQMACImage%>" border="0">

    </div>
    ***********************************************

    Below is the code to the php page. Any help would be much appreciated

    ***********************************************

    <?
    include("header.php");
    if(!session_is_registered('uid')) { header("location:logon.php");}


    $tmp = $_SERVER["PHP_SELF"];
    $myarr = explode('/',$tmp);
    $count = count($myarr);
    $page = $myarr[$count-1];

    if(isset($_POST)) {

    $num_quotes = $_POST;
    $result_rows="";
    $user = new user($_SESSION);
    $hidden_str2="<table><tr>
    <th>".get_lang('logon_username',$lang)."</th>
    <th>".get_lang('th_article',$lang)."</th>
    <th>".get_lang('th_qty',$lang)."</th>
    <th>".get_lang('th_prints',$lang)."</th>
    <th>".get_lang('th_origs',$lang)."</th>
    <th>".get_lang('th_total',$lang)."</th>
    </tr>";

    for($i=0;$i<$num_quotes;$i++){
    $article_number[$i]=$_POST;
    $quantity[$i]=$_POST;
    $prints[$i]=$_POST;
    $origs[$i]=$_POST;
    $image_name[$i]=get_image($article_number[$i]);

    $article[$i]= new article($article_number[$i],$lang,$user->print_country1);
    $result[$i]= new quote_result($article[$i],$quantity[$i],$prints[$i],$origs[$i],$user->print_country1,$user,$lang);

    $result[$i]->result_row($user,$article[$i],$_SESSION,$i);
    $result_rows.=$result[$i]->result_row1;
    $hidden_str2.=$result[$i]->email_str;
    }
    $hidden_str2.="</table>";

    email_request($user,$hidden_str2);

    $temp2=htmlspecialchars($hidden_str2);

    $hidden_str="<input type='hidden' name='email_str' value='$temp2' >";

    $temp=htmlspecialchars(serialize($user));
    $hidden_str1 ="<input type='hidden' name='user' value='$temp'>";

    $result_table_str = "<table id='quote.php'>
    <tr>
    <th>".get_lang("th_img",$lang)."</th>
    <th>".get_lang("th_article",$lang)."</th>
    <th>".get_lang("th_desc",$lang)."</th>
    <th>".get_lang("th_article_costs",$lang)."</th>
    <th>".get_lang("th_total_costs",$lang)."</th>
    <th>".get_lang("th_total",$lang)."</th>
    <th width='20'>".get_lang("th_unit",$lang)."</th>
    <th width='15'>".get_lang("th_save",$lang)."</th>
    </tr>
    <form id='save_quote' method='post' action='quote.php' >
    $result_rows
    <tr>
    <td colspan='5'> </td>
    <td colspan='3'><input type='submit' value='".get_lang('quote_save',$lang)."' /></td>
    </tr>
    <input type='hidden' name='num_saves' value='$num_quotes' />
    $hidden_str1
    $hidden_str
    </form>
    </table>";

    }
    if(isset($_POST)){
    $num_quotes = $_POST;
    }
    else $num_quotes = 1;
    if(!isset($_POST)) {
    $result_table_str = "";
    $article_number = "";
    $quantity = "";
    $prints = "";
    $origs = "";
    for($i=0;$i<$num_quotes;$i++){
    $article_number[$i]="";
    $quantity[$i]="";
    $prints[$i]="";
    $origs[$i]="";
    }
    }


    ?>
    <style type="text/css">
    <!--
    .style1 {
    color: #999999;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 9px;
    }
    .style2 {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 10px;
    }
    -->
    </style>
    <%
    Dim strQMACImage
    Dim vMacbtn
    vMacbtn=false
    If rsFlags.Fields("user_currency").Value = "EUR" Then
    vMacbtn=true
    End If
    If vMacbtn=false then
    strQMACImage="images/irishflag.gif"
    Else
    strQMACImage="images/uk-flag.gif"
    End If

    %>
    <div align="center"><img src="<%=strQMACImage%>" border="0">

    </div>
    <div id="side-b">
    <div id='top'>
    <table id="quote">
    <tr>
    <td><?echo get_lang("index_article",$lang);?></td>
    <td><?echo get_lang("index_qty",$lang);?></td>
    <td><?echo get_lang("index_prints",$lang);?></td>
    <td><?echo get_lang("index_origs",$lang);?></td>
    <td><?echo get_lang("index_num_quotes",$lang);?></td>
    <td>
    <form name="multiple_quotes" method="POST" action="index.php">
    <select name='num_quotes' onchange="multiple_quotes.submit()">
    <option value='1'>-</option>
    <option value='1'>1</option>
    <option value='2'>2</option>
    <option value='3'>3</option>
    <option value='4'>4</option>
    <option value='5'>5</option>
    </select>
    </form></td>
    </tr>
    <form id="quote" name='quote' method="POST" action="index.php" onsubmit="javascript:return validate_quote()">
    <?
    for($i=0;$i<$num_quotes;$i++) {
    if($i!=$num_quotes-1) { $submit = "&nbsp";}
    if($i==$num_quotes-1) { $submit = "<input name='options' id='options' type='submit' value='".get_lang("index_submit","en")."' />";}
    echo "<tr>
    <td><input name='article_number_$i' value='$article_number[$i]' /></td>
    <td><input name='quantity_$i' value='$quantity[$i]' /></td>
    <td><input name='prints_$i' value='$prints[$i]' /></td>
    <td><input name='origs_$i' value='$origs[$i]' /></td>
    <td>$submit</td>
    </tr>";

    }
    ?>
    <input type='hidden' name='page' value='<?echo $page;?>' />
    <input type='hidden' name='num_quotes' value='<?echo $num_quotes;?>' />
    </form>


    </table>
    </div>
    <div id='bottom'>
    <?echo $result_table_str;?>
    </div>
    </div>
    <?include("footer.php");
    ?>


Comments

  • Closed Accounts Posts: 81 ✭✭dzy


    I don't get it. If the user currency is the Euro then display the British flag - otherwise display the Irish flag?


  • Registered Users Posts: 224 ✭✭The Mighty Dubs


    Sorry my bad,

    If its 'EUR' then display the irish flag or if its 'UK' the display the uk flag.


  • Closed Accounts Posts: 81 ✭✭dzy


    <?php
    
    $userCurrency = null;
    // Here I find what the user's currency is
    
    $image = null;
    
    if ($userCurrency == "EUR")
    {
        $image = "images/irish-flag.gif";
    }
    else
    {
        $image = "images/uk-flag.gif";
    }
    
    ?>
    


  • Registered Users Posts: 224 ✭✭The Mighty Dubs


    Hey there DZY,

    Thanks for that but it doesnt seem to be showing the jpg's. I wonder am i inputing into the overall code correctly. Could you do me a favour and have a look at what im inputing.



    ********************

    <?
    include("header.php");
    if(!session_is_registered('uid')) { header("location:logon.php");}


    $tmp = $_SERVER["PHP_SELF"];
    $myarr = explode('/',$tmp);
    $count = count($myarr);
    $page = $myarr[$count-1];

    if(isset($_POST)) {

    $num_quotes = $_POST;
    $result_rows="";
    $user = new user($_SESSION);
    $hidden_str2="<table><tr>
    <th>".get_lang('logon_username',$lang)."</th>
    <th>".get_lang('th_article',$lang)."</th>
    <th>".get_lang('th_qty',$lang)."</th>
    <th>".get_lang('th_prints',$lang)."</th>
    <th>".get_lang('th_origs',$lang)."</th>
    <th>".get_lang('th_total',$lang)."</th>
    </tr>";

    for($i=0;$i<$num_quotes;$i++){
    $article_number[$i]=$_POST;
    $quantity[$i]=$_POST;
    $prints[$i]=$_POST;
    $origs[$i]=$_POST;
    $image_name[$i]=get_image($article_number[$i]);

    $article[$i]= new article($article_number[$i],$lang,$user->print_country1);
    $result[$i]= new quote_result($article[$i],$quantity[$i],$prints[$i],$origs[$i],$user->print_country1,$user,$lang);

    $result[$i]->result_row($user,$article[$i],$_SESSION,$i);
    $result_rows.=$result[$i]->result_row1;
    $hidden_str2.=$result[$i]->email_str;
    }
    $hidden_str2.="</table>";

    email_request($user,$hidden_str2);

    $temp2=htmlspecialchars($hidden_str2);

    $hidden_str="<input type='hidden' name='email_str' value='$temp2' >";

    $temp=htmlspecialchars(serialize($user));
    $hidden_str1 ="<input type='hidden' name='user' value='$temp'>";

    $result_table_str = "<table id='quote.php'>
    <tr>
    <th>".get_lang("th_img",$lang)."</th>
    <th>".get_lang("th_article",$lang)."</th>
    <th>".get_lang("th_desc",$lang)."</th>
    <th>".get_lang("th_article_costs",$lang)."</th>
    <th>".get_lang("th_total_costs",$lang)."</th>
    <th>".get_lang("th_total",$lang)."</th>
    <th width='20'>".get_lang("th_unit",$lang)."</th>
    <th width='15'>".get_lang("th_save",$lang)."</th>
    </tr>
    <form id='save_quote' method='post' action='quote.php' >
    $result_rows
    <tr>
    <td colspan='5'> </td>
    <td colspan='3'><input type='submit' value='".get_lang('quote_save',$lang)."' /></td>
    </tr>
    <input type='hidden' name='num_saves' value='$num_quotes' />
    $hidden_str1
    $hidden_str
    </form>
    </table>";

    }
    if(isset($_POST)){
    $num_quotes = $_POST;
    }
    else $num_quotes = 1;
    if(!isset($_POST)) {
    $result_table_str = "";
    $article_number = "";
    $quantity = "";
    $prints = "";
    $origs = "";
    for($i=0;$i<$num_quotes;$i++){
    $article_number[$i]="";
    $quantity[$i]="";
    $prints[$i]="";
    $origs[$i]="";
    }
    }


    ?>
    <style type="text/css">
    <!--
    .style1 {
    color: #999999;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 9px;
    }
    .style2 {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 10px;
    }
    -->
    </style>

    <div align="center">
    <?php

    $userCurrency = null;
    // Here I find what the user's currency is

    $image = null;

    if ($userCurrency == "EUR")
    {
    $image = "images/irishflag.gif";
    }
    elsea
    {
    $image = "images/uk-flag.gif";
    }

    ?>
    </div>
    <div id="side-b">
    <div id='top'>
    <table id="quote">
    <tr>
    <td><?echo get_lang("index_article",$lang);?></td>
    <td><?echo get_lang("index_qty",$lang);?></td>
    <td><?echo get_lang("index_prints",$lang);?></td>
    <td><?echo get_lang("index_origs",$lang);?></td>
    <td><?echo get_lang("index_num_quotes",$lang);?></td>
    <td>
    <form name="multiple_quotes" method="POST" action="index.php">
    <select name='num_quotes' onchange="multiple_quotes.submit()">
    <option value='1'>-</option>
    <option value='1'>1</option>
    <option value='2'>2</option>
    <option value='3'>3</option>
    <option value='4'>4</option>
    <option value='5'>5</option>
    </select>
    </form></td>
    </tr>
    <form id="quote" name='quote' method="POST" action="index.php" onsubmit="javascript:return validate_quote()">
    <?
    for($i=0;$i<$num_quotes;$i++) {
    if($i!=$num_quotes-1) { $submit = "&nbsp";}
    if($i==$num_quotes-1) { $submit = "<input name='options' id='options' type='submit' value='".get_lang("index_submit","en")."' />";}
    echo "<tr>
    <td><input name='article_number_$i' value='$article_number[$i]' /></td>
    <td><input name='quantity_$i' value='$quantity[$i]' /></td>
    <td><input name='prints_$i' value='$prints[$i]' /></td>
    <td><input name='origs_$i' value='$origs[$i]' /></td>
    <td>$submit</td>
    </tr>";

    }
    ?>
    <input type='hidden' name='page' value='<?echo $page;?>' />
    <input type='hidden' name='num_quotes' value='<?echo $num_quotes;?>' />
    </form>


    </table>
    </div>
    <div id='bottom'>
    <?echo $result_table_str;?>
    </div>
    </div>
    <?include("footer.php");
    ?>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <table width="600" border="0" align="center" cellpadding="1" cellspacing="2" bordercolor="#999999">
    <tr>
    <td bgcolor="ececec"><span class="style2">Minimum Value Orders</span></td>
    </tr>
    <tr>
    <td bgcolor="ebebeb"><span class="style1">We have a £100/€150 minimum order value. If orders under the value of £100/ €150 are placed, a surcharge of £35.00/ €50.00 will be applied.</span></td>
    </tr>
    <tr>
    <td bgcolor="ececec" class="style2">Cancellation Charges</td>
    </tr>
    <tr>
    <td bgcolor="ebebeb" class="style1">A charge will be made on all cancelled orders as follows, If cancelled within 1 day, within 3 days 50% After 3 days the full order value will be charged.
    </td>
    </tr>
    <tr>
    <td bgcolor="ececec" class="style2">Urgent Orders</td>
    </tr>
    <tr>
    <td bgcolor="ebebeb" class="style1">Express Orders will be charged in full regardless of cancellation notice.</td>
    </tr>
    <tr>
    <td class="style1">  </td>
    </tr>
    <tr>
    <td bgcolor="ebebeb" class="style1">All prices are subject to the standard terms and conditions of sale of Macma UK Ltd. (copy available on request). All quotations are valid for 30 days from the date of issue.</td>
    </tr>

    </table>


  • Closed Accounts Posts: 81 ✭✭dzy


    The code just implements the check. It doesn't find the user's currency. I don't know how you want to do that. That's why there is a comment "Here I find what the user's currency is". Thats the bit you need to implement. I don't know where you read this bit of information from in your application.

    You'll also need the html to display the image.
    <div><img src="<?php echo $image; ?>"/></div>
    


  • Advertisement
  • Registered Users Posts: 224 ✭✭The Mighty Dubs


    if its any help, I need to look up a table called 'users' and the column is called 'user_currency'. In this it'll either state 'EUR' or 'GBP'.


  • Closed Accounts Posts: 81 ✭✭dzy


    You already have an object representing the user. Presumably it has a user_currency member variable. So just use that.
    <?php
    
    $flagUrl = null;
    
    if ($user->user_currency == "EUR")
    {
        $flagUrl = "images/irish-flag.gif";
    }
    else
    {
        $flagUrl = "images/uk-flag.gif";
    }
    ?>
    <div><img src="<?php echo $flagUrl; ?>"/></div>
    
    


  • Closed Accounts Posts: 23 Master-Geek


    this is a very simple if logical statement if the user is going to make a selectin based upon a condition to show a relvent JPG.

    like DZY did, but there would need to be a relation to what ever the logic is.
    if its any help, I need to look up a table called 'users' and the column is called 'user_currency'. In this it'll either state 'EUR' or 'GBP'.

    you need to do a query on the current user session to see if what the currency is set to in that table. and assign it to a variable or a constant.

    if it is == to EUR then you can assign it the flag.


Advertisement