السلام عليكم
اخواني انا لدي هذا الكود لجمع حقلين في قاعدة البيانات وهو يعمل 100%
كود PHP:
$id=$_GET['id'];
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
$b=array($id=$rows['nu2']-$id=$rows['nu1']);
echo array_sum($b);
انا اريد تطبيقة على الكود هذا
كود PHP:
<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
<title>Add Employee</title>
<style type="text/css"/>
body {
font-family : tahoma;
}
</style>
</head>
<body bgcolor="#0B334F">
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="fj"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name order by id DESC";
$result=mysql_query($sql);
?>
<div align="center">
<div align="center">
<table width="393" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<div align="center">
<table width="633" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<div align="center">
<table width="615" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<div align="center">
<table border="1" cellspacing="0" cellpadding="0" style="border-left-style:solid; border-bottom-style:solid" width="610" bordercolor="#FFFFFF">
<tr>
<td align="center" width="31" bordercolorlight="#FFFFFF" bgcolor="#0B334F" style="border-bottom-style: solid; border-bottom-width: 1px; border-left-style:solid; border-left-width:1px; border-top-style:solid; border-top-width:1px">
<span lang="ar-sa"><font color="#FFFFFF" face="Times New Roman"><b>or</b></font></span></td>
<td align="center" width="71" bordercolorlight="#FFFFFF" bgcolor="#0B334F" style="border-bottom-style: solid; border-bottom-width: 1px; border-top-style:solid; border-top-width:1px">
<span lang="ar-sa"><b><font face="Times New Roman" color="#FFFFFF">المجموع</font></b></span></td>
<td align="center" width="150" bordercolorlight="#113340" bgcolor="#0B334F" bordercolordark="#113340" style="border-right-style: solid; border-right-width: 1px; border-top-style: solid; border-top-width: 1px; border-bottom-style: solid; border-bottom-width: 1px">
<strong><font color="#FFFFFF" face="Times New Roman">الاسم</font></strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td width="31" align="center" bgcolor="#FFFFFF" bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF" bordercolor="#2868A7">
<b><font face="Times New Roman" color="#113340"><span lang="ar-sa">
<a href="tran.php?id=<? echo $rows['id']; ?>" style="text-decoration: none">
<font color="#0B334F">del</font></a></span></font></b></td>
<td width="71" align="center" bgcolor="#FFFFFF" bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF" bordercolor="#2868A7"><b>
<font face="Times New Roman"><? echo array_sum($b); ?></font></b></td>
<td width="150" align="center" bgcolor="#FFFFFF" bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF" bordercolor="#2868A7"><b>
<font face="Times New Roman"><? echo $rows['name']; ?></font></b></td>
</tr>
<?php
}
?>
</table>
</div>
</td>
</tr>
<tr><td align="center"> </td></tr>
</table>
</div>
<?php
mysql_close();
?>
</body>
</html>