Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP show data using date range
    primarykey
    data
    text
    <p>Here it's, I've got the answer.</p> <p>I just change in track_reports.php to be :</p> <pre><code>if (isset($_POST['chkOtdate'])) { $date_from = $_POST['date_from']; $date_to = $_POST['date_to']; if (empty($bagianWhere)) { $bagianWhere .= "ot_date between '$date_from' and '$date_to'"; } else { $bagianWhere .= " AND ot_date between '$date_from' and '$date_to'"; } } </code></pre> <p>and now nothing problem the code can be run smoothly. Thanks for your helps friends. Appreciate with your suggestions and comments.</p> <hr> <p>I have a trouble with my code below :</p> <ol> <li>view_report.php</li> </ol> <p>We can view report based on badge_id, employee_name and ot_date (with a range). When I try to find using badge_id and employee_name no problem, data showed. But when I try to find using date range, error found. the error is : <code>: mysql_fetch_array() expects parameter 1 to be resource, boolean given in on line WarningC:\xampp\htdocs\siix_dev\overtime\track_reports.php327</code></p> <pre><code>&lt;form method="post" action="track_reports.php" name="form"&gt; &lt;table id="mytable"&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="checkbox" name="chkBadge" onClick="apply(this.checked, 'textBox')"&gt; &lt;font class="category"&gt;Badge ID&lt;/font&gt; &lt;/td&gt; &lt;td&gt; &lt;input id="textBox" class="text sign" type="text" name="badge_id"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="checkbox" name="chkEmp" onClick="apply(this.checked, 'textBox2')"&gt; &lt;font class="category"&gt;Employee Name&lt;/font&gt; &lt;/td&gt; &lt;td&gt; &lt;input id="textBox2" class="text sign" type="text" name="employee_name"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;input id="myCheckBox" type="checkbox" name="chkOtdate" onClick="apply(this.checked, 'textBox3')" onChange="apply(this.checked, 'textBox4')"&gt; &lt;font class="category"&gt;OT Date&lt;/font&gt; &lt;/td&gt; &lt;td&gt; &lt;font class="category"&gt;From&lt;/font&gt; &lt;input id="textBox3" class="text sign" type="text" name="date_from" &gt;&lt;font class="category"&gt; To&lt;/font&gt; &lt;input id="textBox4" class="text sign" type="text" name="date_to" &gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt; &lt;input type="submit" name="submit" value="Submit"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; </code></pre> <ol> <li><p>track_reports.php</p> <p> <pre><code> $bagianWhere = ""; if (isset($_POST['chkBadge'])) { $badge_id = $_POST['badge_id']; if (empty($bagianWhere)) { $bagianWhere .= "badge_id = '$badge_id'"; } } if (isset($_POST['chkEmp'])) { $employee_name = $_POST['employee_name']; if (empty($bagianWhere)) { $bagianWhere .= "employee_name LIKE '$employee_name'"; } else { $bagianWhere .= " AND employee_name LIKE '$employee_name'"; } } if (isset($_POST['chkOtdate'])) { $date_from = $_POST['date_from']; $date_to = $_POST['date_to']; $query=mysql_query("select badge_id, employee_name from t_submissions where ot_date between '$date_from' and '$date_to'"); while($row=mysql_fetch_array($query)){ echo $row['badge_id']; echo $row['employee_name']; } } $query = "SELECT * FROM t_submissions WHERE ".$bagianWhere; $hasil = mysql_query($query); echo " &lt;div id='main' class='wrapper'&gt; &lt;div class='content-area'&gt; &lt;table cellspacing='0' class='font'&gt;"; echo "&lt;tr&gt;&lt;th class='th'&gt;Badge ID&lt;/th&gt;&lt;th class='th'&gt;Employee Name&lt;/th&gt;&lt;th class='th'&gt;OT Date&lt;/th&gt;&lt;th class='th'&gt;Department&lt;/th&gt;&lt;th class='th'&gt;OT From&lt;/th&gt;&lt;th class='th'&gt;OT To&lt;/th&gt;&lt;th class='th'&gt;Remarks&lt;/th&gt;&lt;th class='th'&gt;Submissions By&lt;/th&gt;&lt;th class='th'&gt;Acknowledged By&lt;/th&gt;&lt;th class='th'&gt;Approved By&lt;/th&gt;&lt;/tr&gt;"; while ($data = mysql_fetch_array($hasil)) { echo "&lt;tr&gt;&lt;td class='td'&gt;".$data['badge_id']."&lt;/td&gt;&lt;td class='td'&gt;".$data['employee_name']."&lt;/td&gt;&lt;td class='td'&gt;".$data['ot_date']."&lt;/td&gt;&lt;td class='td'&gt;".$data['dept_name']."&lt;/td&gt;&lt;td class='td'&gt;".$data['ot_from']."&lt;/td&gt;&lt;td class='td'&gt;".$data['ot_to']."&lt;/td&gt;&lt;td class='td'&gt;".$data['remarks']."&lt;/td&gt;&lt;td class='td'&gt;".$data['submission_by']."&lt;/td&gt;&lt;/tr&gt;"; } echo "&lt;/table&gt; &lt;br&gt; &lt;input type='button' VALUE='Back' onClick='history.go(-1);return true;'&gt; &lt;/div&gt; &lt;/div&gt; "; ?&gt; </code></pre></li> </ol> <p>Someone can help me ? Appreciate with your helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload