-1

I create two table

customers  | customer_details

This is from "customers" table This is from "customer_details"

I create two search field and the given value search between two tabel

Here is the code

<form>
    <input  type="text" id="example1" name="example1" value="<?php echo date('d/m/Y'); ?>">
    <input  type="text" id="example2" name="example2" value="<?php echo date('d/m/Y'); ?>">
    <button class="btn" name="submit" type="submit"> Search </button>
</form>
<table border="1">
    <thead>
      <tr>
        <th> SL</th>
        <th> U_ID</th>
        <th> NAME </th>
        <th> BOX_NO </th>
        <th> ACC_NO </th>
        <th> BOX CHRG </th>
        <th> INSTL CHRS </th>
        <th> OTHER CHRG </th>
        <th> PKG VAL </th>
        <th> TOTAL AMT </th>
        <th> RECD BY </th>
        <th> Date </th>
        </tr>
    </thead>
    <tbody>
<?php
if(isset($_GET['submit']))
{
    $db_host="localhost";
    $db_username="root";
    $db_password="";
    $db_name="administrator";
    $db_tb_name="customer_details";
    $db_tb1_name="customers";
    $db_tb_atr_name="u_id";
    $db_tb_btr_name="name";
    $db_tb_ctr_name="box_no";
    $db_tb_dtr_name="acc_no";
    $db_tb_etr_name="box_chrs";
    $db_tb_ftr_name="instl_chrs";
    $db_tb_gtr_name="other_val";
    $db_tb_htr_name="pkg_val";
    $db_tb_itr_name="total";
    $db_tb_jtr_name="rec_by";
    $db_tb_ktr_name="reg_date";
    $db_tb_ltr_name="id";
    $db_tb_mtr_name="date";

    mysql_connect("$db_host","$db_username","$db_password");
    mysql_select_db("$db_name");

    $s_name=mysql_real_escape_string($_GET['example1']);
    $m_name=mysql_real_escape_string($_GET['example2']);

    $query_for_result=mysql_query("SELECT * FROM $db_tb_name WHERE 
    $db_tb_mtr_name BETWEEN '".$s_name."' AND '".$m_name."'

    UNION

    SELECT * FROM $db_tb1_name WHERE 
    $db_tb_ktr_name BETWEEN '".$s_name."' AND '".$m_name."' 
    ORDER BY $db_tb_dtr_name, $db_tb_ltr_name DESC");

    $i = 1;
    while($data_fetch=mysql_fetch_array($query_for_result))
    {
?>
    <tr>
        <td><?php echo $i; ?></td>
        <td><?php echo substr($data_fetch[$db_tb_atr_name], 0,160); ?></td>
        <td><?php echo substr($data_fetch[$db_tb_btr_name], 0,160); ?></td>
        <td><?php echo substr($data_fetch[$db_tb_ctr_name], 0,160); ?></td>
        <td><?php echo substr($data_fetch[$db_tb_dtr_name], 0,160); ?></td>
        <td><?php echo substr($data_fetch[$db_tb_etr_name], 0,160); ?></td>
        <td><?php echo substr($data_fetch[$db_tb_ftr_name], 0,160); ?></td>
        <td><?php echo substr($data_fetch[$db_tb_gtr_name], 0,160); ?></td>
        <td><?php echo substr($data_fetch[$db_tb_htr_name], 0,160); ?></td>
        <td><?php echo substr($data_fetch[$db_tb_itr_name], 0,160); ?></td>
        <td><?php echo substr($data_fetch[$db_tb_jtr_name], 0,160); ?></td>
        <td><?php echo substr($data_fetch[$db_tb_ktr_name], 0,160); ?></td>
      </tr>
<?php
    $i++;
    } 
    mysql_close();
}
?>
    </tbody>
</table>

In the out put a error is shown

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\projects\MainWork\administrator\report.php on line 63

What is the wrong in my code?

How to solve this problem?

Thank you for helping.

Subhajit
  • 371
  • 3
  • 18

1 Answers1

0

As i can see ur problem is in query error.

You are applying UNION in query. This is rule of UNION that there should be same number of fields in both queries when applying UNION.

In your case it is not happening. Please try to redesign your query.

Hope this help u. :)

Pradeep
  • 61
  • 5