CodeIgniter Forums
Problem with Search Function with codeigniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Problem with Search Function with codeigniter (/showthread.php?tid=17310)



Problem with Search Function with codeigniter - El Forum - 04-01-2009

[eluser]Unknown[/eluser]
Hi Guys,


I have a question to you I have a problem how to get value of my dropdown in a my code with a press drop down Account Number and type the account number and press the button search i will get the result of the following number see my attachment
code for controller/customer.php
Code:
function search()
    {
        
        $this->load->view('/cust/display');
    }
    function search_id()
    {
    $custid = (strlen($this->uri->segment(3))>0) ? ($this->uri->segment(3)) : ($this->input->post('account_number'));
    
    //echo "id ".$custid;

    //$data['query'] = $this->customer_model->querybyid($custid);
    //$datax = $this->customer_model->querybyid($custid);
    /*$qry = 'SELECT b.cf_454,
                b.cf_456,
                b.cf_450,
                b.cf_452,
                b.cf_458,
                c.survey_id,
                c.lastname,
                c.firstname
            FROM survey_accounts a LEFT OUTER JOIN vtiger_accountscf b
            ON b.accountid = a.account_id LEFT OUTER JOIN households c
            ON a.survey_id = c.survey_id
            WHERE b.cf_452 = "'.$custid.'"';*/
        $qry = "SELECT
                b.cf_454,
                b.cf_450,
                b.cf_452,
                b.cf_456,
                b.accountid,
                a.rcpt_lname,
                a.rcpt_fname,
                a.rcpt_mi,
                a.survey_id,
                a.completed,
                a.date_completed,
                a.survey_date
            FROM survey_accounts a, vtiger_accountscf b
            WHERE b.cf_452 = a.account_number
            and a.account_number = '$custid'";
        $data['query'] = $this->db->query($qry);
//echo $this->db->last_query();
        if(strlen($custid)>0) {
            
            if ($data['query']->num_rows()>0) {
                $data['myvar'] = '';
                $this->load->view('cust/GetCustomerData',$data);
            } else {
                $this->db->where('cf_452',$custid);
                $myquery = $this->db->get('vtiger_accountscf');
                if ($myquery->num_rows()>0) {
                    redirect('customer_survey/add/'.$custid);
                } else {
                    $data['myvar'] = '1';
                    $this->load->view('cust/display.php',$data);
                    //redirect('customer/index');
                }
            }
        } else {
            redirect('customer/index');
        }
    
    }
code for model/customer.php
Code:
function querybyid($custid)
    {
    $query = 'SELECT a.cf_454,
             a.cf_456,
             a.cf_452,
             a.cf_458,
             c.survey_id,
             c.lastname
        FROM vtiger_accountscf a LEFT OUTER JOIN survey_accounts b
        ON b.account_id = a.accountid LEFT OUTER JOIN households c
        ON b.survey_id = c.survey_id
        WHERE a.cf_452 = "'.$custid.'"';
    return $this->db->query($query);
    }
code for views/display.php
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&lt;html&gt;

&lt;head&gt;
&lt;title&gt;Customer Account Information&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<center>
&lt;form method="POST" action="&lt;?php echo base_url() ?&gt;index.php/customer/search_id" name="form1"&gt;
    <p><b>Enter Customer Account Number to Retrieve Information:</p></b>
<p align="center"><strong>Select Your Choices </p></strong>
<div align="center">
<select name="dropdown">
<option value="cf-452">Account Number</option>
<option value="cf_454">Customer Subscriber Name</option>
</select>
<p align="center"><IMG  alt="Sky" width="84" height="49" align="center" border="0"></p>
    <p><b>Customer Account Number:</b> &lt;input type="text" name="account_number" /&gt;
    &lt;?php
     if (strlen($myvar)>0) {
      echo "<font color='red'><strong>No records founds. Try another search criteria.</font></strong>";
     }
   ?&gt;
    </p>
    <p>&lt;input type="submit" value="Search Account Number" /&gt;&lt;/p>

&lt;/form&gt;
Code for views/GetCustomerData.php
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&lt;html&gt;

&lt;head&gt;
&lt;title&gt;Customer Account Information&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<center>
&lt;form method="POST" action="&lt;?php echo base_url() ?&gt;index.php/customer/search_id" name="form1"&gt;
    <p><b>Enter Customer Account Number to Retrieve Information:</p></b>
<p align="center"><strong>Select Your Choices </p></strong>
<div align="center">
<select name="dropdown">
<option value="cf-452">Account Number</option>
<option value="cf_454">Customer Subscriber Name</option>
</select>
<p align="center"><IMG  alt="Sky" width="84" height="49" align="center" border="0"></p>
    <p><b>Customer Account Number:</b> &lt;input type="text" name="account_number" /&gt;
    &lt;?php
     if (strlen($myvar)>0) {
      echo "<font color='red'><strong>No records founds. Try another search criteria.</font></strong>";
     }
   ?&gt;
    </p>
    <p>&lt;input type="submit" value="Search Account Number" /&gt;&lt;/p>

&lt;/form&gt;
Hoping for your kind help and consinderation.

Thanks