1
<?php require_once('../includes/header.php');?>
<?php require_once('../includes/connection.php');?>
<?php include('../includes/get_username.php');?>

<?php
include('sanitise.php');
$month = sanitise($_GET['month']);
?>

<table id="contentbox">
<tr>
<td>
<?php
$color="1";
//view record
$qry = mysql_query("SELECT * FROM tbl_dv WHERE monthname(date_added) = '$month' ORDER BY dv_id DESC");
echo "<table class='dvr_table' id='alternatecolor' width='100%'>
<tr>
<th>DATE ADDED</th>
<th>CT</th>
<th>PAYEE</th>
<th>PARTICULAR</th>
<th>PM</th>
<th>VOUCHER NO.</th>
<th>NET</th>
<th>OBR NO.</th>
<th>";

//RESPO/Office
$sql = "SELECT respo FROM tbl_dv WHERE monthname(date_added) = '$month' GROUP BY respo";
$result = mysql_query($sql);

echo "<select name='respo'>
<option value=' ' disabled='disabled' selected='selected'>Select a RESPO/Office</option>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['respo'] . "'>" . $row['respo'] . "</option>";
}
echo "</th>
<th>ACCOUNT CODE</th>
<th>FPP CODE</th>
<th>DEDUCTION</th>
</tr>";

while ($row = mysql_fetch_array($qry))  {
$dv_id = $row['dv_id']; 
if($color==1){
echo "<tr bgcolor='#ffffff'>
<td style='text-align:center;'>" .date_format(date_create($row['date_added']), 'm/d/y')." </td>
<td style='text-align:center;'>" .$row['cashtype']."</td>
etc.......

$color="2";
}   else {
echo "<tr bgcolor='#ebeaea'>
<td style='text-align:center;'>" .date_format(date_create($row['date_added']), 'm/d/y')." </td>
<td style='text-align:center;'>" .$row['cashtype']."</td>
etc......
$color="1";
}
}
echo "</tr>";
?>

私はそれがすべて機能しています。1 つの問題のみ.. 選択した RESPO/OFFICE を表示できません。RESPO/OFFICE を選択すると、選択した RESPO/OFFICE が並べ替えられます...コードを修正したり、コードを追加したりするにはどうすればよいでしょうか..助けてください!

4

3 に答える 3

1
<?php require_once('../includes/header.php');?>
<?php
$respo = $_GET['respo'];
$month = (int) (!empty($_GET['date_added']) ? $_GET['date_added'] : date('m'));
$year = (int)  (!empty($_GET['date_added']) ? $_GET['date_added'] : date('Y'));

//database call here

$viewrecord = "SELECT * FROM tbl_dv WHERE respo='".mysql_real_escape_string($respo)."' AND year(date_added)='$year' GROUP BY date_added  ";
$result = mysql_query($viewrecord, $db) or die (mysql_error());
$num_result = mysql_num_rows($result);
{

echo "<table border='1' width='100%' style='border:1px solid silver' cellpadding='5px' cellspacing='0px'>
<tr bgcolor='#666666' style='color:#FFFFFF'>
<th>Date Encoded</th>
etc...... (header here)

while ($row = mysql_fetch_row($result)) {
echo '<tr>';
echo "<tr ><td align='center'>" .date_format(date_create($row[17]), "m/d/y")."</td>
etc...
}
mysql_close($db);
?>

これは私が思いついたコードです。これは単なる代替ソリューションです。しかし、このソリューションの問題はそれです。MONTH のレコードは call として表示しません。RESPO を選択すると、RESPO が機能し、要求したすべての RESPO が表示されますが、問題は、選択した RESPO に前の月がすべて含まれていることです。特定の月だけを選択すると..

于 2014-04-30T00:52:13.227 に答える
1

最初にいくつかの提案:

  • mysql は減価償却されており、PDO プリペアド ステートメントまたは mysqli に移行する必要があります。これについては、php のマニュアルを参照してください。
  • あなたのコードにコメントしてください。上から下まで読まない限り、先に進むことはできません。

今あなたのコードに:

<?php
 // Start document with includes needed, header, connection, functions.
 require_once('../includes/header.php');
 require_once('../includes/connection.php');
 include('../includes/get_username.php');   
 include('sanitise.php');

// Start with the month variable posted from $_GET, this will begin the initial display.
$month = sanitise($_GET['month']);
?>

<!-- Begin Table Display and Layout -->
<table id="contentbox">
<tr>
<td>

<?php // Open PHP Tag to get variables to display in the table

$color="1";

// Initial Query to get the data for the month passed by GET, ordering by dv_id.
$qry = mysql_query("SELECT * FROM tbl_dv WHERE monthname(date_added) = '$month' ORDER BY dv_id DESC");

// Format the table rows for display
echo "<table class='dvr_table' id='alternatecolor' width='100%'>
<tr>
<th>DATE ADDED</th>
<th>CT</th>
<th>PAYEE</th>
<th>PARTICULAR</th>
<th>PM</th>
<th>VOUCHER NO.</th>
<th>NET</th>
<th>OBR NO.</th>
<th>";

// Fill the SELECT option with all the RESPO/Office data
$sql = "SELECT respo FROM tbl_dv WHERE monthname(date_added) = '$month' GROUP BY respo";
$result = mysql_query($sql);

// Display the select with the newly populated content
echo "<select name='respo'>
<option value=' ' disabled='disabled' selected='selected'>Select a RESPO/Office</option>";
// While the result contains data we will display respo as a select option.
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['respo'] . "'>" . $row['respo'] . "</option>";
}

// Finish the table header
echo "</th>
<th>ACCOUNT CODE</th>
<th>FPP CODE</th>
<th>DEDUCTION</th>
</tr>";

// While we have data from the original query we will display it
while ($row = mysql_fetch_array($qry))  {
$dv_id = $row['dv_id']; // grab the dv_id
if($color==1){ // Setup color scheme
echo "<tr bgcolor='#ffffff'> // Color for the row
// Let's begin filling the table with data
<td style='text-align:center;'>" .date_format(date_create($row['date_added']), 'm/d/y')." </td>
<td style='text-align:center;'>" .$row['cashtype']."</td>
etc.......

$color="2";
}   else {
echo "<tr bgcolor='#ebeaea'>
<td style='text-align:center;'>" .date_format(date_create($row['date_added']), 'm/d/y')." </td>
<td style='text-align:center;'>" .$row['cashtype']."</td>
etc......
$color="1";
}
}
echo "</tr>";
?>

上記のコードを確認すると、選択したオプションに基づいて表示しているデータをフィルター処理するためのクエリを設定していないことが明らかです。

最初のクエリ:

// Initial Query to get the data for the month passed by GET, ordering by dv_id.
$qry = mysql_query("SELECT * FROM tbl_dv WHERE monthname(date_added) = '$month' ORDER BY dv_id DESC");

WHERE選択したオプションに新しい変数を追加して、ステートメントを展開できます。WHERE monthname(date_added) = '$month' && respo = '$respo'このクエリを選択オプションの後に移動して、選択オプションで選択された値にアクセスできるようにします。最後に、jQuery を使用して選択ボックスの値を変更する場合を除き、選択オプションの状態の変化を表示する送信ボタンが必要になります。

疑似コード:

  • 送信の確認

  • クエリの WHERE 句で部門の値を変更する

  • 要求されたデータを表示する

    これにより、目的の結果を達成するために必要な方向に進むはずです。

編集:

あなたが投稿した3番目の回答で:

$viewrecord = "SELECT * FROM tbl_dv WHERE respo='".mysql_real_escape_string($respo)."' AND year(date_added)='$year' GROUP BY date_added  ";

渡された月でフィルタリングしていないと言いましたが、クエリ、特に WHERE 句に追加していません。したがって、次のようになります。

$viewrecord = "SELECT * FROM tbl_dv WHERE respo='".mysql_real_escape_string($respo)."' AND month(month_added)='$month' AND year(date_added)='$year' GROUP BY date_added  ";

最終編集:

$_GET['date_added']最初の問題は、ビュー ページに値を送信しないことに起因するため、何も表示されません選択ボックスを適切にフォーマットし、データベースから RESP および Date データのデータを追加します

echo "<option value='". $row['respo'] . "+". $row['date_added'] . "'>" . $row['respo'] . "  (".$row['count(*)'].")</option>";

respo と日付文字列を渡したので、次のページでデータを操作できます。

/* UNCOMMENT NEXT LINE FOR ERROR DETECTION */
//error_reporting( E_ALL );
/* GET THE ENTIRE STRING PASSED FROM THE SELECT OPTION */
$respo = $_GET['respo'];
/* EXPLODE THE DATA BY + SYMBOL TO GET THE DATA */
$data = explode("+", $respo);
/* FORMAT THE DATETIME FROM THE STRING TO A FRIENDLY FORMAT */
$month = date("m", strtotime($data[1])) . "<br />";
$year = date("Y", strtotime($data[1])) . "<br />";

これは、データを操作して必要なものを取得する方法を選択したため、クエリは次のようになります。

$viewrecord = "SELECT * FROM tbl_dv WHERE respo='".mysql_real_escape_string($data[0])."' && year(date_added)='$year' && month(date_added)='$month' ";

RESPO and the date by year and monthこれにより、 を介してページに渡されたのレコードのみが表示されます$_GET

于 2014-04-29T17:07:31.870 に答える
1
//RESPO/Office
**echo '<form action="view.php" method="post">';**
$byrespo = mysql_query("SELECT DISTINCT count(*), respo FROM tbl_dv WHERE monthname(date_added)='$month' GROUP BY respo");
echo "<select name='respo' onchange='this.form.submit()'>
<option value=' ' disabled='disabled' selected='selected'>Select a RESPO/Office</option>";
while ($row = mysql_fetch_array($byrespo)) {
echo "<option value='" . $row['respo'] . "'>" . $row['respo'] . "  (".$row['count(*)'].")</option>";
}
echo "</select></form>";

私は急いで解決策を思いついた..だから私はaを追加し、別のview.phpを作成する

于 2014-04-30T00:40:16.437 に答える