الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

حساب العمر

بدأه ضيء في 5 ديسمبر 2011 · 5 رد · 1,224 مشاهدة · في منتدى تطوير المواقع بـ PHP
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

بسم الله الرحمن الرحيم

السلام عليكم ورحمة الله وبركاته ..

كيف حال الجميع .

لو سمحتوا ابي منكم خدمة اتنمى تساعدوووني ..

أبي أكواد للـ PHP يمكنني من خلالها عمل حساب العمر

( تكون لدي خانه من خلالها ادخل سنة ميلادك + وخانة اخرى اسمك )

ثم يضغط المستخدم ارسال وينتقل الى صفحة اخرى يظهر له

( أهلا بك يا فلان عمرك وهو .. )

//////////////////////////////////////////////

وأتمنى من كل قلبي أن تساعدونني ..

أكون شاكره لكم

تم تعديل هذه المشاركة بواسطة فيصل الحربي في 5 ديسمبر 2011 في 23:04 — السبب: كل سؤال في موضوع مستقل

#2

أين الصعوبة؟ :blink:

صفحة html عادية يكون فيها فورم بسيط :

<html><head><title>Welcome</title></head>
<body>
<fieldset><legend>Form :</legend>
<form action="target.php" method="post">
Name:<input type="text" name="name" maxlength="40" />
<br />
Age:<input type="text" name="age" maxlength="3" />
<br />
<input type="submit" value="Submit" />
</form></fieldset>
</body>
</html>

وصفحة php تأخذ متغيرات الفورم!!

<?php
 echo "welcome ".$_POST['name']." your age is :". $_POST['age'];
 ?>

تحياتي.

عفواً أحبتي انقطاعي بسبب الدراسة دعواتكم بالتوفيق..

{ لا ينال العلم مستحٍ ولا مستكبر }

#3

شكرا لك ولكن لا أريد الـ HTML

ابيها كلها بصفحة الـ PHP

ابي كل الاكواد PHP

وايه صح انا ابي من المستخدم يدخل سنة ميلاده موب عمره ..

والصفحه الثانيه انا اطلع له عمره ..

تم تعديل هذه المشاركة بواسطة ضيء في 5 ديسمبر 2011 في 21:47

#4

تم عمل اللازم بالنسبة لحساب العمر

3 ملفات داخل الملف المضغوط

age.rar

ملف index.php

<?php
include_once('myFunctions.php'); 

$time1  = $_POST['time1']; 
$name1 = $_POST['T1'] ;
?>

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Page 1</title>
</head>

<body>



<p align="center"><span style="background-color: #FFFF00; font-weight:700"><font size="6">Birth Date 
calculation</font></span></p>



<table border="0" width="100%" cellspacing="3" cellpadding="3" height="343">

	<tr>
		<td width="25"></td>
		<td align="center">
        <form name="form1"  action="result.php" method="POST" >
        <p align="center"> </p>
		<p align="center"> </p>
		<p align="center">Your Name : <input type="text" name="T1" size="63"></p>
		<p align="center">Enter your birth day : <input type="text"  name="time1" /> 
		<br>
		<br />
         <font color="#FF0000"><input type="submit" name="submit" value="Calculate birth date" style="color: #FF0000; font-weight: bold" /></font></p>
		<p align="center"> </p>
        </form>
        </td>
	</tr>

	</table>


<center>
<p><b><font size="2" color="#FF0000"> By : Faisal Al-Harbi 2011 </font></b></p>
</center>


</body>

</html>

ملف myFunctions.php

<?php

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function get_Age_difference($start_date,$end_date){



//    list($start_year,$start_month,$start_date) = split('-', $start_date);
//    list($current_year,$current_month,$current_date) = split('-', $end_date);

       list($start_year,$start_month,$start_date) = preg_split("/[\-,]+/",  $start_date);
        list($current_year,$current_month,$current_date) = preg_split("/[\-,]+/",$end_date);


     $result = '';

    /** days of each month **/

    for($x=1 ; $x<=12 ; $x++){

        $dim[$x] = date('t',mktime(0,0,0,$x,1,date('Y')));

    }

    /** calculate differences **/

    $m = $current_month - $start_month;
    $d = $current_date - $start_date;
    $y = $current_year - $start_year;

    /** if the start day is ahead of the end day **/

    if($d < 0) {

        $today_day = $current_date + $dim[$current_month];
        $today_month = $current_month - 1;
        $d = $today_day - $start_date;
        $m = $today_month - $start_month;
        if(($today_month - $start_month) < 0) {

            $today_month += 12;
            $today_year = $current_year - 1;
            $m = $today_month - $start_month;
            $y = $today_year - $start_year;

        }

    }

    /** if start month is ahead of the end month **/

        if($m < 0) {

        $today_month = $current_month + 12;
        $today_year = $current_year - 1;
        $m = $today_month - $start_month;
        $y = $today_year - $start_year;

        }

    /** Calculate dates **/

    if($y < 0) {


        echo '<p><a href="javascript:history.go(-1)" title="Return to the previous page"> Go back </a></p>' ." <br /> ";
        die("Start Date Entered is a Future date than End Date.");



    } else {

        switch($y) {

            case 0 : $result .= ''; break;
            case 1 : $result .= $y.($m == 0 && $d == 0 ? ' year old' : ' year'); break;
            default : $result .= $y.($m == 0 && $d == 0 ? ' years old' : ' years');

        }

        switch($m) {

            case 0: $result .= ''; break;
            case 1: $result .= ($y == 0 && $d == 0 ? $m.' month old' : ($y == 0 && $d != 0 ? $m.' month' : ($y != 0 && $d == 0 ? ' and '.$m.' month old' : ', '.$m.' month'))); break;
            default: $result .= ($y == 0 && $d == 0 ? $m.' months old' : ($y == 0 && $d != 0 ? $m.' months' : ($y != 0 && $d == 0 ? ' and '.$m.' months old' : ', '.$m.' months'))); break;

        }

        switch($d) {

            case 0: $result .= ($m == 0 && $y == 0 ? 'Today' : ''); break;
            case 1: $result .= ($m == 0 && $y == 0 ? $d.' day old' : ($y != 0 || $m != 0 ? ' and '.$d.' day old' : '')); break;
            default: $result .= ($m == 0 && $y == 0 ? $d.' days old' : ($y != 0 || $m != 0 ? ' and '.$d.' days old' : ''));

        }

    }

    return $result;

}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




?>

ملف النتائج

result.php

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 2</title>
</head>

<body>

<table border="0" cellpadding="0" cellspacing="0" width="1439" height="812">

	<tr>
		<td valign="top" colspan="3" height="111">

		 </td>
	</tr>
	<tr>
		<td> </td>
		<td valign="top" align="center">

		 <p> </p>
		<p> </p>
		<p> </p>
		<p> </p>
		<p> </p>
		<p><font size="7"> 


		<?php

include_once('myFunctions.php'); 

$time1  = $_POST['time1']; 
$name1 = $_POST['T1'] ;


//sum_the_time($time1, $time2); // Comes From  myFunctions.php Function No.1  



//        echo "<center>";
//        echo "<br />" ;
//        echo "<br />";
//        echo "<br />";
//        echo "<br />";
//        echo "<br />";


       echo "Name : " .$name1 ." <BR /> " ;

        /* Call this function as */
        $date_difference= get_Age_difference($time1,date("Y-m-d")); /* get_Age_difference(Birthdate,Todays_date) */
        echo  " Age : " .$date_difference;


//        echo "<br />" ;
//        echo "<br />";
//        echo "<br />";
//        echo "<br />";
//        echo "<br />";
//

        echo '<p><a href="javascript:history.go(-1)" title="Return to the previous page"> Go back </a></p>';

//        echo "<center />";





?>




		</font>




		</p>
		<p align="center"> </td>
		<td height="627"> </td>
	</tr>
	<tr>
		<td width="99"> </td>
		<td width="1240"> </td>
		<td height="74" width="100"> </td>
	</tr>
</table>

</body>

</html>
1

صورة
صورة

حسابي في الفيس بوك
http://goo.gl/XIzwL

حسابي في تويتر
http://goo.gl/6p4e3

 

 
 
#5

شكرررررررررررررررررا جزيــــــــــــلا

الله يعطيك العافيه ..

( بس باقي لي كود عدد الزوار :( )

#6

ربنا يفتح عليك أستاذ فيصل على هذا العمل الكبير :)

فاعلم أنه لا إله إلا الله

مواضيع مشابهة