PDA

View Full Version : سوال: دو مشکل در کد php(درخواست کمک)



morypory
دوشنبه 11 تیر 1397, 13:02 عصر
درود بر دوستانمن 2 تا مشکل دارم در کد برنامه نویسیم امیدوارم که دوستان راهنمائیم کنند.
اولین مشکل من این است که من 6 فیلد دارم که 4 تای آن از نوع varcher است و دو تای آن از نوع date و موقعی که فیلدها پر باشند در دیتا بیس اطلاعات ذخیره میشود ولی وقتی که یکی از فیلدهای date من خالی باشد اطلاعات من ذخیره نمیشود .من برای این مشکل از کد زیر استفاده کردم


$d=strtotime("today");
$date=date("Y-m-d",$d);
if(empty( $tarikh or $tarikh1 )){

$tarikh=$date;
$tarikh1=$date;

با این کار مشکلم حل شد ولی یک مشکل که هست من نمیخواهم در دیتا بیس وقتی تاریخ را وارد نمیکنم تاریخ ثبت شود آیا راه دیگری دارید که فیلد تاریخ اگر خالی بود کاراکتر خالی داخلش ثبت بشه
و مشکل دوم در گزارش گیریه من یک صفحه دارم که دو تا انتخاب براش گذاشتم که مثلا یکی جزئی و یکی کلی گزارش میدهد در قسمت گزارشگیری جمع ستون ها را میخواهم بهم بدهد این کار را انجام داده ام ولی مشکلی که دارم این است اگر مثلا کلی را انتخاب کنم فقط جمع این ستون را میدهد و اگر جزئی را انتخاب کنم جمع ستون را نمیدهد این هم کدی که نوشتم


<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
<div class="alert alert-success">
<h2 style="text-align:center; font-family:cursive;">گزارش فیش های واریزی<b><?php echo $_SESSION["name"]; ?><b> </h2>
<a href="repfish.php" >
<i class="fas fa-home" ></i>
</a>
</div>


<thead>
<tr>
<th style="display:none">ردیف</th>
<th >جمع</th>
<th style="text-align:center; font-family:cursive; font-size:14px; color:blue;">مبلغ</th>
<th style="text-align:center; font-family:cursive; font-size:14px; color:blue;">فیش واریزی</th>
<th style="text-align:center; font-family:cursive; font-size:14px; color:blue;">تاریخ</th>
<th style="text-align:center; font-family:cursive; font-size:14px; color:blue;">توضیحات</th>
<th style="text-align:center; font-family:cursive; font-size:14px; color:blue;">مبلغ پوز</th>
<th style="text-align:center; font-family:cursive; font-size:14px; color:blue;">شماره پذیرنده</th>
<th style="text-align:center; font-family:cursive; font-size:14px; color:blue;">تاریخ تراکنش</th>
<th style="text-align:center; font-family:cursive; font-size:14px; color:blue;">مبلغ ام پوز</th>
<th style="text-align:center; font-family:cursive; font-size:14px; color:blue;">شماره پذیرنده</th>
<th style="text-align:center; font-family:cursive; font-size:14px; color:blue;">تاریخ تراکنش</th>
<th style="text-align:center; font-family:cursive; font-size:14px; color:blue;">مبلغ انتقالی</th>
<th style="text-align:center; font-family:cursive; font-size:14px; color:blue;">شماره فیش</th>
<th style="text-align:center; font-family:cursive; font-size:14px; color:blue;">تاریخ</th>


</tr>
</thead>
<tbody>
<?php
error_reporting(0);

$a=$_POST['from'];
$b=$_POST['to'];
if(!empty($_POST['from'] && $_POST['to'])){

$d=strtotime("today");
$date=date("Y-m-d",$d);
if(isset($_POST['mahal1'])){
$query=mysqli_query($db,"select * from incofish where id_user='$login_session' and tarikh between '$a' AND '$b' ");
while($row=mysqli_fetch_array($query)){

?>



<tr>
<td style="display:none"><?php echo $row['id'] ?></td>
<td ><?php ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo $english_format_number = number_format($row['income']) ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo $row['fishe'] ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo $row['tarikh'] ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo $row['expl'] ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></td>




</tr>
<?php } ?>

<?php
$add=mysqli_query($db,"SELECT SUM(income) from incofish where id_user='$login_session' and tarikh between '$a' AND '$b' ");
while($row1=mysqli_fetch_array($add))
{
$mark=$row1['SUM(income)'];

?>
<tr>
<th style="text-align:center; font-family:B titr; font-size:14px;">جمع کل</th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo $mark ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;display:none"><?php echo '-' ?></th>
</tr>
<?php } ?>

<?php }
}

if(isset($_POST['all'])){
$query=mysqli_query($db,"select * from incofish where id_user='$login_session' and tarikh between '$a' AND '$b' ")or die('امکان اتصال به پایگاه داده وجود ندارد!');
while($row=mysqli_fetch_array($query)){

?>



<tr>
<td style="display:none"><?php echo $row['id'] ?></td>
<td ><?php ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo $english_format_number = number_format($row['income']) ?> </td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo $row['fishe'] ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo $row['tarikh'] ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo $row['expl'] ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo$english_format_number = number_format($row['incom1']) ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo $row['poc'] ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo $row['tarikh1'] ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo $english_format_number = number_format($row['incom2']) ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo $row['mpos'] ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo $row['tarikh2'] ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo$english_format_number = number_format($row['incom3']) ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo $row['fish'] ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo $row['tarikh3'] ?></td>




</tr>


<?php }


if(isset($_POST['mpos'])){
$query=mysqli_query($db,"select * from incofish where id_user='$login_session' and tarikh between '$a' AND '$b' ")or die('امکان اتصال به پایگاه داده وجود ندارد!');
while($row=mysqli_fetch_array($query)){

?>



<tr>
<td style="display:none"><?php echo $row['id'] ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?> </td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo $english_format_number = number_format($row['incom2']) ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo $row['mpos'] ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo $row['tarikh2'] ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></td>
<td style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></td>




</tr>
<?php } ?>

<?php
$add=mysqli_query($db,"SELECT SUM(incom2) from incofish where id_user='$login_session' and tarikh between '$a' AND '$b' ");
while($row1=mysqli_fetch_array($add))
{
$mark=$row1['SUM(incom2)'];

?>
<tr>
<th style="text-align:center; font-family:B titr; font-size:14px;">جمع کل</th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo $mark ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;"><?php echo '-' ?></th>
<th style="text-align:center; font-family:B titr; font-size:14px;display:none"><?php echo '-' ?></th>
</tr>
<?php } ?>

<?php }
}




?>
</tbody>
</table>




</tr>
<thead>
</table>

ممنون میشوم راهنمائیم کنید.