Web Analytics Made Easy -
StatCounter Calling in data - CodingForum

Announcement

Collapse
No announcement yet.

Calling in data

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

  • Calling in data

    I have created a database with currency conversions like this:

    CREATE TABLE `currency` (
    `ID` double default NULL,
    `Cont` varchar(255) default NULL,
    `Rate` double default NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

    --
    -- Dumping data for table `currency`
    --

    INSERT INTO `currency` (`ID`, `Cont`, `Rate`) VALUES (1, 'American Dollars', 1.87121),
    (2, 'Euros', 1.48475),
    (3, 'British Pounds', 1);


    I then have a drop down menu on the page to choose 'Euros' British Pounds' etc.

    <form id="frmCurr" name="frmCurr" method="post">
    <select name="Currency" OnChange="UpdateQuantity()">
    <option selected="selected">GBP</option>
    <option value="British Pounds">British Pounds</option>
    <option value="American Dollars">American Dollars</option>
    <option value="Euro">Euro</option>

    </select>
    </form>

    I want to be able to select a currency and call that data from the database, do I do this via a session?

    I am new to this any help would be great thanks

  • #2
    some tut's may help you but here simple hint:

    PHP Code:
    $sql "SELECT * FROM currency";
    $result mysql_query($sql);

    echo 
    '<form id="frmCurr" name="frmCurr" method="post">
    <select name="Currency" OnChange="UpdateQuantity()">'
    ;
    while (
    $row mysql_fetch_assoc($result)) {
    echo 
    '<option value="'.$row['ID'].'">'.$row['Cont'].'</option>';
    }
    echo 
    '</select></form>'
    Free php image upload script
    Personal web developing blog

    Comment


    • #3
      It depends what you are trying to do, and how the HTML form needs to work. You could use a little AJAX here and have your UpdateQuantity() function access a PHP script that accesses your database, and then return the results via another JS function....Or you could just submit the HTML form, force the current page to refresh, grab the $_POST value of your select menu, and then access your database....With AJAX you don;t need a page refresh; without AJAX, you do need a refresh....

      If you want to keep things simple, I would just use the latter method, w/o AJAX, and access the $_POST value after page refresh...
      Regards, R.J.

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

      Help spread the word! Like our YouTube-to-Mp3 Conversion Script on Facebook !! :-)
      [Instructional videos and tutorials are also available on YouTube, Dailymotion, and Vimeo]
      Explore all products and services, view demos, review documentation, check prices, and more!
      ♪♪ …Need Web Hosting For Our YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

      Comment


      • #4
        Originally posted by kreoton View Post
        some tut's may help you but here simple hint:

        PHP Code:
        $sql "SELECT * FROM currency";
        $result mysql_query($sql);

        echo 
        '<form id="frmCurr" name="frmCurr" method="post">
        <select name="Currency" OnChange="UpdateQuantity()">'
        ;
        while (
        $row mysql_fetch_assoc($result)) {
        echo 
        '<option value="'.$row['ID'].'">'.$row['Cont'].'</option>';
        }
        echo 
        '</select></form>'
        I don;t think selecting every currency in his database, and iterating throught the results, will do him any good....he wants to access the DB based on the selection in the select menu...so that requires a diff approach then what you have there...
        Regards, R.J.

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

        Help spread the word! Like our YouTube-to-Mp3 Conversion Script on Facebook !! :-)
        [Instructional videos and tutorials are also available on YouTube, Dailymotion, and Vimeo]
        Explore all products and services, view demos, review documentation, check prices, and more!
        ♪♪ …Need Web Hosting For Our YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

        Comment


        • #5
          Thanks

          I dont know if I have done this correctly as its not calling in theinfo

          <?php
          $sql = "SELECT * FROM currency";
          $result = mysql_query($sql);
          echo '<form id="frmCurr" name="frmCurr" method="post">
          <select name="Currency" OnChange="UpdateQuantity()">';
          while ($row = mysql_fetch_assoc($result)) {
          echo '<option value="'.$row_rsCurr['Cont'].'">'.$row_rsCurr['Cont'].'</option>';
          }
          echo '</select></form>'; ?>


          many thanks

          Comment


          • #6
            I guess I misinterpreted what you wanted to do...

            You just want to populate the select menu with the values from your database?

            If so, for your code, you should do it like kreoton suggested...so:

            PHP Code:
             while ($row mysql_fetch_assoc($result)) {
             echo 
            '<option value="'.$row_rsCurr['Cont'].'">'.$row_rsCurr['Cont'].'</option>';
             } 
            should be

            PHP Code:
            while ($row mysql_fetch_assoc($result)) {
            echo 
            '<option value="'.$row['Cont'].'">'.$row['Cont'].'</option>';

            also make sure your connection to the database is working...
            Regards, R.J.

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

            Help spread the word! Like our YouTube-to-Mp3 Conversion Script on Facebook !! :-)
            [Instructional videos and tutorials are also available on YouTube, Dailymotion, and Vimeo]
            Explore all products and services, view demos, review documentation, check prices, and more!
            ♪♪ …Need Web Hosting For Our YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

            Comment


            • #7
              help!

              Hi thanks for your time, I dont think I have explained my self properly.

              HI thanks for your help!

              I have had to start again hopefully I can explain myself better

              The Database:
              mysql_select_db($database_jag, $jag);
              $query_rsCurrency = "SELECT * FROM `currency`";
              $rsCurrency = mysql_query($query_rsCurrency, $jag) or die(mysql_error());
              $row_rsCurrency = mysql_fetch_assoc($rsCurrency);
              $totalRows_rsCurrency = mysql_num_rows($rsCurrency);



              The Drop down menu:
              <form id="frmCurr" name="frmCurr" method="post">
              <select name="Currency" id="Currency" OnChange="UpdateQuantity()">
              <option selected="selected">GBP</option>
              <option value="British Pounds">British Pounds</option>
              <option value="American Dollars">American Dollars</option>
              <option value="Euro">Euro</option>

              </select>
              </form>

              The result
              <?php
              //Price x currency to give result
              $number1 = $HTTP_SESSION_VARS["icJag"]->col("ItemSubTotal");
              $number2 = $row_rsCurrency['Rate'];
              $newnumber = ($number1 * $number2);
              echo $english_format_number = number_format($newnumber, 2, '.', '');

              ?>



              What I am trying to do is:
              The user selects there currency
              The price is in GBP on the page, when the uaer selects the currency it calculates the result on the page with out going to another page.

              The url for the page is http://gtr.spgrouponline.co.uk/resul...mageField_y=10

              As you can see I have a postage area option too this works fine and there are some results on the bottom right where the calculation works (as it is picking up the first option in the database)

              Thanks

              Comment

              Working...
              X