Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Sep 2009
    Posts
    40
    Thanks
    3
    Thanked 0 Times in 0 Posts

    read data from Mysql Database using (ajax-php) depends on 4 variables

    I need to read data from mysql database using ajax php mysql without loading the page. The data depends on 4 variable in the page (dgree_now,new_alawa,status,no_child). When the user select 2 variables (dgree_now,new_alawa) then it must search from mysql database (another table:basic1) and return these columns (pre_salary,kla_mesha,alsakn,badl_trhil) and the page recieve these data from mysql database then check another 2 variables (status, no_child)
    if the status is (married) & no of child (not zero) then the total in (badel_nakdy) must become the sum of ((pre_salary+kla_mesha+alsakn+badl_trhil)*0.25)
    if the status is (married) & no of child (zero) then the total in (badel_nakdy) must become the sum of ((pre_salary+kla_mesha+alsakn+badl_trhil)*0.17)
    if the status is (not married) then the total in (badel_nakdy) must become the sum of ((pre_salary+kla_mesha+alsakn+badl_trhil)*0.08)
    PHP Code:

    <script src="jquery-1.11.1.min.js"></script>
    <link rel="stylesheet" type="text/css" href="jquery.datepick.css"> 
    <script type="text/javascript" src="jquery.plugin.js"></script> 
    <script type="text/javascript" src="jquery.datepick.js"></script>
    <script src="jquery.chained.min.js"></script>
    <script>

      $(document).ready(function () {
     
    $("#new_alawa").chained("#dgree_now"); /* or $("#series").chainedTo("#mark"); */
    document.getElementById('new_alawa').addEventListener('change', function(){
    document.getElementById('pre_salary').value = this.options[this.selectedIndex].getAttribute('data-value') || '';
    });
    });
    </script>
    <script>
    $(function() {
        $('#popupDatepicker').datepick({dateFormat: 'yyyy-mm-dd'});
                       $('#popupDatepicker1').datepick({dateFormat: 'yyyy-mm-dd'});
                       $('#popupDatepicker2').datepick({dateFormat: 'yyyy-mm-dd'});
        $('#inlineDatepicker').datepick({onSelect: showDate});
    });

    function showDate(date) {
        alert('The date chosen is ' + date);
    }
    </script>

    <script type="text/javascript">
        $(document).ready(function () {

            //iterate through each textboxes and add keyup
            //handler to trigger sum event
            $(".txt").each(function () {

                $(this).keyup(function () {
                    calculateSum();
                });
            });

        });

        function calculateSum() {

            var sum = 0;
            //iterate through each textboxes and add the values
            $(".txt").each(function () {

                //add only if the value is number
                if (!isNaN(this.value) && this.value.length != 0) {
                    sum += parseFloat(this.value);
                }

            });
            //Assign the total value to Textbox 11
            $("#TextBox11").val(sum);
        }
    </script>
    <script type="text/javascript">
        $(document).ready(function () {

            //iterate through each textboxes and add keyup
            //handler to trigger sum event
            $(".txt1").each(function () {

                $(this).keyup(function () {
                    calculateSum1();
                });
            });

        });

        function calculateSum1() {

            var sum1 = 0;
            //iterate through each textboxes and add the values
            $(".txt1").each(function () {

                //add only if the value is number
                if (!isNaN(this.value) && this.value.length != 0) {
                    sum1 += parseFloat(this.value);
                }

            });
            //Assign the total value to Textbox 11
            $("#TextBox12").val(sum1);
        }
    </script>
    </head>
    <?php
    include("conn.php");
    echo
    "<script language='javascript' src='script.js'></script><link rel='stylesheet' type='text/css' href='main.css'/><body dir='rtl' onload='note()'>
    <center>
    <div style='width:990;border:groove 15px #7ACB83'>"
    ;
    echo
    "<font face='Terminal' color='green'><h1>البيانات الأساسيــة للموظفين</h1>";

    //$w=$_POST['id'];
    $a=$_POST['emp_name'];
    $b=$_POST['date_mounth'];
    $c=$_POST['acount_no'];
    $d=$_POST['day_mounth'];
    $e=$_POST['unit'];
    $f=$_POST['dept'];
    $g=$_POST['pay_type'];
    $h=$_POST['side_sarf'];
    $i=$_POST['job'];
    $j=$_POST['barth_day'];
    $k=$_POST['tain_date'];
    $l=$_POST['gender'];
    $m=$_POST['status'];
    $n=$_POST['dreeba'];
    $o=$_POST['no_child'];
    $p=$_POST['dgree_now'];
    $q=$_POST['new_alawa'];
    $r=$_POST['old_alawa'];
    $r1=$_POST['car_gov'];
    $s=$_POST['home_gov'];
    $t=$_POST['pre_salary'];
    $u=$_POST['kla_mesha'];
    $v=$_POST['natural_job'];
    $v1=$_POST['certy'];
    $w=$_POST['sp1_alawa'];
    $x=$_POST['sp2_alawa'];
    $y=$_POST['sp3_alawa'];
    $z=$_POST['sp4_alawa'];
    $a13=$_POST['sp5_alawa'];
    $a1=$_POST['sp1_de'];
    $a2=$_POST['sp2_de'];
    $a3=$_POST['sp3_de'];
    $a4=$_POST['sp4_de'];
    $a5=$_POST['sp5_de'];
    $a6=$_POST['sp6_de'];

    $a7=$_POST['mutbagee_lend'];
    $a8=$_POST['sum_replace'];
    $a9=$_POST['sum_discount'];
    $a10=$_POST['salary_pure'];
    $a11=$_POST['const_discount_cost'];

    /* $a12=$_POST['de1'];$a13=$_POST['de2'];$a14=$_POST['de3'];$a15=$_POST['de4'];$a16=$_POST['de5'];
    $a17=$_POST['de6'];$a18=$_POST['de7'];$a19=$_POST['de8'];$a20=$_POST['de9'];$a21=$_POST['de10'];$a22=$_POST['de11'];
    $a23=$_POST['de12'];$a24=$_POST['de13'];$a25=$_POST['de14'];$a26=$_POST['de15'];$a27=$_POST['de16'];
    $a28=$_POST['de17'];$a29=$_POST['de18'];$a30=$_POST['de19'];$a31=$_POST['de20'];
    $a32=$_POST['alawa_chidren'];$a33=$_POST['alawa_wagba'];$a34=$_POST['alawa_sociaty'];
    $a35=$_POST['alwa_year'];$a36=$_POST['alwa_no'];                    $a37=$_POST['alwa_perosn'];
    $a38=$_POST['alsakn'];$a39=$_POST['menha'];$a40=$_POST['tamseal'];$a41=$_POST['badl_trhil'];
    $a42=$_POST['badl_adwa'];$a43=$_POST['badel_nakdy'];$a44=$_POST['eltsam_mash'];$a45=$_POST['eltsam_tamen_egtmaee'];$a46=$_POST['eltsam_tamen_healthy']; */
    if(isset($_POST['xxx'])and $_POST['xxx']=='admin')
    {
    $add=mysql_query("INSERT INTO basic(id,emp_name,date_mounth,acount_no,day_mounth,
    unit,dept,pay_type,side_sarf,job,barth_day,tain_date,gender,status,dreeba,no_child,
    dgree_now,new_alawa,old_alawa,car_gov,home_gov,pre_salary,kla_mesha,natural_job,certy,
    sp1_alawa,sp2_alawa,sp3_alawa,sp4_alawa,sp5_alawa,sp1_de,sp2_de,sp3_de,sp4_de,
    sp5_de,sp6_de,mutbagee_lend,sum_replace,sum_discount,
    salary_pure,const_discount_cost)
    values('$w','$a','$b','$c','$d','$e','$f','$g','$h','$i','$j','$k','$l','$m','$n',
    '$o','$p','$q','$r','$r1','$s','$t','$u','$v','$v1','$w','$x','$y','$z','$a13','$a1','$a2',
    '$a3','$a4','$a5','$a6','$a7','$a8','$a9',
    '$a10','$a11')"
    )or die("لم يتم حفظ بيانات الموظف");
    if(isset(
    $add)){
    echo
    " تم حفظ بيانات الموظف بنجاح<br>";
    }
    }

    echo
    "<form action='".$server['PHP_SELF']."' method='post'>
    <table bgcolor='#7ACB83'  border='1'>
     <tr><td>    إسم الموظـــف : </td><td><input type='text'size='37' name='emp_name' /></td></tr>

    </table>
    <table bgcolor='#7ACB83' width='98%' border='1'>
      <tr> <td>تاريخ الشهر:</td><td><input type='date' id='popupDatepicker' name='date_mounth' />
    </td>
    <td>رقم حساب البنك:</td><td><input type='number' name='acount_no' /></td>
    <td>أيام الشهر المستحقة:</td><td><input type='number' name='day_mounth' /></td>
    <tr><td>المحلية:</td><td><select name='unit'>
            <option value=''>الرجاء اختيار المحلية</option>
            <option value='المتمة'>المتمة</option>
            <option  value='شندي'>شندي</option>
            <option value='الدامر'>الدامر</option>
            <option value='عطبرة'>عطبرة</option>
            <option value='بربر'>بربر</option>
            <option value='أبو حمد'>أبو حمد</option>
            <option value='البحيرة'>البحيرة</option>
          </select></td>

    <td>القسم:</td><td><select name='dept'>
       <option value=''>الرجاء اختيار القسم</option>
    <option value='كينةالثانوية' >كينةالثانوية</option>
            <option value='اًم سرح الثانوية'>اًم سرح الثانوية</option>
            <option value='الكاب الثانوية'>الكاب الثانوية</option>
         
          </select></td>
    <td>طريقة الدفع:</td><td><select name='pay_type'>
    <option value=''>الرجاء اختيار طريقة الدفع</option>
    <option value='كـاش' >كـاش</option>
            <option value='بنـك'>بنـك</option>
          </select></td> 
    <tr><td>جهة الصرف:</td><td><select name='side_sarf'>
    <option value=''>الرجاء اختيار جهة الصرف</option>
    <option value='بربر لثانوية بنين' >بربر لثانوية بنين</option>
            <option value='بربر لثانوية بنات'>بربر لثانوية بنات</option>

          </select></td>
    <td>الوظيفــة:</td><td><select name='job'>
    <option value=''>الرجاء اختيار الوظيفة</option>
    <option value='بياطرة' >بياطرة</option>
            <option value='اًمومة' >اًمومة</option>
    <option value='تقني'>تقني</option>
    <option value='زراعيين'>زراعيين</option>
          </select></td>
    <td>تاريخ الميلاد:</td><td><input type='date' id='popupDatepicker1' name='barth_day' /></td>
    <tr><td>تاريخ التعيين:</td><td><input type='date' id='popupDatepicker2' name='tain_date' /></td>
    <td>النوع:</td><td><select name='gender'>
    <option value=''>الرجاء اختيار النوع</option>
            <option value='ذكر' >ذكر</option>
            <option value='اُنثي'>اُنثي</option>

          </select></td>
     <td>الحالة الإجتماعية:<td><select id='status' name='status'>
    <option value=''>الرجاء اختيار الحالة الاجتماعية</option>
    <option value='married' >married</option>
            <option value='single'>single</option>
      <option value='divorce'>divorce</option>
            <option value='multiple'>multiple</option>
          </select></td>
    <tr><td>خاضع للضريبة:</td><td><select name='dreeba'>
            <option value=''>الرجاء اختيار خاضع للضريبة</option>
            <option value='نعــم' selected>نعــم</option>
            <option value='لا'>لا</option>
          </select></td>
     <td>عدد الأطفال:</td><td><input type='number' id='no_child' name='no_child' /> </td>
     <td>الدرجة الوظيفية:</td><td><select id='dgree_now' name='dgree_now'>
             <option value=''>اختار الدرجة</option>
            <option value='1'>الاُولى</option>
            <option value='2'>الثانية</option>
            <option value='3'>الثالثة</option>
            <option value='4'>الرابعة</option>
            <option value='5'>الخامسة</option>
            <option value='6'>السادسة</option>
            <option value='7'>السابعة</option>
    <option value='8'> الثامنة</option>
    <option value='9'> التاسعة</option>
    <option value='10'>العاشرة </option>
    <option value='11'>الحادية عشر</option>
    <option value='12'>الثانية عشر </option>
    <option value='13'>الثالثة عشر </option>
     <option value='14'>الرابعة عشر</option>
    <option value='15'>الخامسة عشر </option>
    <option value='16'>السادسة عشر </option>
    <option value='17'> السابعة عشر</option>
    <option value='18'> اُولي خاصــة</option>
          </select></td>
    <tr><td>عدد العلاوات بالهيكل الجديد:</td><td><select id='new_alawa' name='new_alawa'>
      <option value=''>اختار رقم العلاوة</option>
    <option value='A1' data-value='959' class='1'>A1</option>
     <option value='A2' data-value='998' class='1'>A2</option>
      <option  value='A3' data-value='1038' class='1'>A3</option>
    <option value='A4' data-value='1079' class='1'>A4</option>
      <option value='B1' data-value='887' class='2'>B1</option>
      <option value='B2' data-value='923' class='2'>B2</option>
      <option value='B3' data-value='959' class='2'>B3</option>
      <option value='B4' data-value='998' class='2'>B4</option>
      <option value='C1' class='3'>C1</option>
      <option value='C2' class='3'>C2</option>
      <option value='C3' class='3'>C3</option>
      <option value='C4' class='3'>C4</option>
      <option value='D1' class='4'>D1</option>
      <option value='D2' class='4'>D2</option>
      <option value='D3' class='4'>D3</option>
      <option value='D4' class='4'>D4</option>
      <option value='E1' class='5'>E1</option>
      <option value='E2' class='5'>E2</option>
      <option value='E3' class='5'>E3</option>
      <option value='E4' class='5'>E4</option>
    <option value='E5' class='5'>E5</option>
    <option value='F1' class='6'>F1</option>
      <option value='F2' class='6'>F2</option>
      <option value='F3' class='6'>F3</option>
      <option value='F4' class='6'>F4</option>
    <option value='F5' class='6'>F5</option>
    <option value='G1' class='7'>G1</option>
      <option value='G2' class='7'>G2</option>
      <option value='G3' class='7'>G3</option>
      <option value='G4' class='7'>G4</option>
    <option value='G5' class='7'>G5</option>
    <option value='G6' class='7'>G6</option>
    <option value='H1' class='8'>H1</option>
      <option value='H2' class='8'>H2</option>
      <option value='H3' class='8'>H3</option>
      <option value='H4' class='8'>H4</option>
    <option value='H5' class='8'>H5</option>
    <option value='H6' class='8'>H6</option>
    <option value='I1' class='9'>I1</option>
      <option value='I2' class='9'>I2</option>
      <option value='I3' class='9'>I3</option>
      <option value='I4' class='9'>I4</option>
    <option value='I5' class='9'>I5</option>
    <option value='I6' class='9'>I6</option>
      <option value='I7' class='9'>I7</option>
    <option value='I8' class='9'>I8</option>
    <option value='I9' class='9'>I9</option>
    <option value='J1' class='10'>J1</option>
      <option value='J2' class='10'>J2</option>
      <option value='J3' class='10'>J3</option>
      <option value='J4' class='10'>J4</option>
    <option value='J5' class='10'>J5</option>
    <option value='J6' class='10'>J6</option>
    <option value='K1' class='11'>K1</option>
      <option value='K2' class='11'>K2</option>
      <option value='K3' class='11'>K3</option>
      <option value='K4' class='11'>K4</option>
    <option value='K5' class='11'>K5</option>
    <option value='K6' class='11'>K6</option>
    <option value='L1' class='12'>L1</option>
      <option value='L2' class='12'>L2</option>
      <option value='L3' class='12'>L3</option>
      <option value='L4' class='12'>L4</option>
    <option value='L5' class='12'>L5</option>
    <option value='L6' class='12'>L6</option>
    <option value='M1' class='13'>M1</option>
      <option value='M2' class='13'>M2</option>
      <option value='M3' class='13'>M3</option>
      <option value='M4' class='13'>M4</option>
    <option value='M5' class='13'>M5</option>
    <option value='M6' class='13'>M6</option>
    <option value='N1' class='14'>N1</option>
      <option value='N2' class='14'>N2</option>
      <option value='N3' class='14'>N3</option>
      <option value='N4' class='14'>N4</option>
    <option value='N5' class='14'>N5</option>
    <option value='N6' class='14'>N6</option>
    <option value='O1' class='15'>O1</option>
      <option value='O2' class='15'>O2</option>
      <option value='O3' class='15'>O3</option>
      <option value='O4' class='15'>O4</option>
    <option value='O5' class='15'>O5</option>
    <option value='O6' class='15'>O6</option>
    <option value='P1' class='16'>P1</option>
      <option value='P2' class='16'>P2</option>
      <option value='P3' class='16'>P3</option>
      <option value='P4' class='16'>P4</option>
    <option value='P5' class='16'>P5</option>
    <option value='P6' class='16'>P6</option>
    <option value='Q1' class='17'>Q1</option>
      <option value='Q2' class='17'>Q2</option>
      <option value='Q3' class='17'>Q3</option>
      <option value='Q4' class='17'>Q4</option>
    <option value='Q5' class='17'>Q5</option>
    <option value='لا يوجد علاوة' class='18' disabled>لا يوجد علاوة</option>
    </select>
    </td>
     
      <td>عدد العلاوات بالهيكل القديم:</td><td><input type='number' name='old_alawa' /></td>

     <td>عربة حكومية:</td><td><select name='car_gov'>
    <option value=''>الرجاء اختيار عربة حكومية</option>
    <option value='نعــم' >نعــم</option>
            <option value='لا'>لا</option>
           
          </select></td>
     <tr><td>منزل حكومي:</td><td><select name='home_gov'>
    <option value=''>الرجاء اختيار منزل حكومي</option>
           <option value='نعــم' >نعــم</option>
            <option value='لا'>لا</option>
           
          </select></td>

     <td>المرتب الأساسي:</td><td><input type='text' id='pre_salary' name='pre_salary' /></td>

     <td>غلاء المعيشة:</td><td><input type='number' name='kla_mesha' /></td>

     </table>
    <table bgcolor='#7ACB83'  border='1'>
     <tr><td>طبيعة عمـل:</td><td><input type='number' name='natural_job' /></td>
    <td>المؤهل العلمي:</td><td><select name='certy'>
    <option value=''>الرجاء اختيار المؤهل العلمي</option>
           <option value='50'>دكتوراة</option>
             <option value='35'>زمالة</option>
              <option value='30'>ماجستير</option>
           
          </select></td>
    <td>البديل التقدي:</td><td><input type='number' id='badel_nakdy' name='badel_nakdy' /></td>
    </table>
    <table bgcolor='#7ACB83' width='19%' border='1'>
    <br>البدلات الخاصــة
    </table>
    <table bgcolor='#7ACB83' width='58%' border='1'>

     <td><input type='text' value='علاوة خ1' size='10'></td><td><input type='text' class='txt' size='7' name='sp1_alawa' /></td>

    <td><input type='text' value='علاوة خ2' size='10'></td><td><input type='text' class='txt' size='7' name='sp2_alawa' /></td>

    <td><input type='text' value='علاوة خ3'size='10'></td><td><input type='text' class='txt' size='7' name='sp3_alawa' /></td>

    <td><input type='text' value='علاوة خ4'size='10'></td><td><input type='text' class='txt' size='7' name='sp4_alawa' /></td>

    <td><input type='text' value='علاوة خ5' size='10'></td><td><input type='text' class='txt' size='7' name='sp5_alawa' /></td>
    </table>
    <table bgcolor='#7ACB83' width='19%' border='1'> 
    <br>الإستقطاعات الخاصــة
     </table>
    <table bgcolor='#7ACB83' width='58%' border='1'>

    <td><input type='text' value='سلفية' size='10'></td><td><input type='text' class='txt1' size='7' name='mutbagee_lend' /></td>

    <td><input type='text' value='خصم من الكل' size='10'></td><td><input type='text' class='txt1' size='7' name='const_discount_cost' /></td>

    <td><input type='text' value='خصم2' size='10'></td><td><input type='text' size='7' class='txt1' name='sp1_de' /></td>

    <td><input type='text' value='خصم3' size='10'></td><td><input type='text' size='7' class='txt1' name='sp2_de' /></td>

    <td><input type='text' value='خصم4' size='10'></td><td><input type='text' size='7' class='txt1' name='sp3_de' /></td>
    </table>
    <table bgcolor='#7ACB83' width='48%' border='1'>
    <tr><td><input type='text' value='خصم 5' size='10'></td><td><input type='text' size='7' class='txt1' name='sp4_de' /></td>

    <td><input type='text' value='خصم 6' size='10'></td><td><input type='text' size='7' class='txt1' name='sp5_de' /></td>
    <td><input type='text' value='خصم 7' size='10'></td><td><input type='text' size='7' class='txt1' name='sp6_de' /></td>
    </table>
    <table bgcolor='#7ACB83'  border='1'>
     <td>مجموع البدلات:</td><td><input type='number' ID='TextBox11' name='sum_replace' /></td>
     <td>مجموع الإستقطاعات:</td><td><input type='text' ID='TextBox12' name='sum_discount' /></td>
     <td>صافي المرتب:</td><td><input type='text' name='salary_pure' /></td>  </table>
    </table>
    <table bgcolor='#7ACB83' width='35%' border='1'>
    <input type='submit'  value='حفظ بيانات الموظف'/><br>
    <input type='hidden' name='id'/>
    <input type='hidden' name='xxx' value='admin'/>"
    ;
    echo
    "</table>
    </form><a href='main.php'><font size='3' color='green'>  الانتقال الى القائمة الرئيسية للنظام</a>
    <a href='login.php'><font size='3' color='green'> <br>الخروج من النظام</a>
    "
    ;

    ?>
    <br>

    </body>
    </html>
    Thanks in Advance

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,342
    Thanks
    13
    Thanked 349 Times in 345 Posts
    well, you need some JavaScript AJAX code to connect to the server (and receive the data) and a PHP script that queries the DB for the desired data.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    New Coder
    Join Date
    Sep 2009
    Posts
    40
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Dormilich View Post
    well, you need some JavaScript AJAX code to connect to the server (and receive the data) and a PHP script that queries the DB for the desired data.
    ok the concept become clear,but the question how can I do this. I need the code that do this
    Thanks in advance

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,342
    Thanks
    13
    Thanked 349 Times in 345 Posts
    if you want someone coding it for you, post an offer in the Web-projects forum.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #5
    New Coder
    Join Date
    Sep 2009
    Posts
    40
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Dormilich View Post
    if you want someone coding it for you, post an offer in the Web-projects forum.
    Ok Thank you. I will check it


  •  

    Posting Permissions

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