I'm getting the following error before performing employee search











up vote
0
down vote

favorite












enter image description here



When i load my controller i'm getting this error in my homepage, but after performing search the error will disappear and search results will be displayed there.



This is my view page:



       <div id="toggle_tst">
<div class="scroll">
<?php
// List up all results.

echo "<table id='table'>";
echo "<tbody>";
echo "<thead>";
echo "<tr><th>NAME</th><th>Pernor No</th><th>DESIGNATION ID</th>
</tr>";
echo "</thead>";
foreach ($results as $row)
{
echo "<tr><td>";
echo $row['name'];
echo "</td><td>";
echo $row['pernor_no'];
echo "</td><td>";
echo $row['designation_id'];
echo "</td></tr>";
}
if (isset($_POST['data_rows']))
{
//if the page has been submitted, append the rows
echo $_POST['data_rows'];
}
echo "</tbody>";
echo "</table>";
?>
</div>
</div>


Controller:



       public function execute_search()
{
// Retrieve the posted search term.
$search_term = $this->input->post('search');
$data['query'] = $this->JcMeetingExpense_model->viewother();
$data['query1'] = $this->JcMeetingExpense_model->viewcatprice();

// Use a model to retrieve the results.
$data['results'] = $this->JcMeetingExpense_model-
>get_results($search_term);
// Pass the results to the view.
$this->load->view('JcMeetingExpense/jc_meeting_expense',$data);
}









share|improve this question
























  • $results is not returning array so you are getting error. are you able to get results from controller?
    – Jasmin Mistry
    Aug 30 at 5:57















up vote
0
down vote

favorite












enter image description here



When i load my controller i'm getting this error in my homepage, but after performing search the error will disappear and search results will be displayed there.



This is my view page:



       <div id="toggle_tst">
<div class="scroll">
<?php
// List up all results.

echo "<table id='table'>";
echo "<tbody>";
echo "<thead>";
echo "<tr><th>NAME</th><th>Pernor No</th><th>DESIGNATION ID</th>
</tr>";
echo "</thead>";
foreach ($results as $row)
{
echo "<tr><td>";
echo $row['name'];
echo "</td><td>";
echo $row['pernor_no'];
echo "</td><td>";
echo $row['designation_id'];
echo "</td></tr>";
}
if (isset($_POST['data_rows']))
{
//if the page has been submitted, append the rows
echo $_POST['data_rows'];
}
echo "</tbody>";
echo "</table>";
?>
</div>
</div>


Controller:



       public function execute_search()
{
// Retrieve the posted search term.
$search_term = $this->input->post('search');
$data['query'] = $this->JcMeetingExpense_model->viewother();
$data['query1'] = $this->JcMeetingExpense_model->viewcatprice();

// Use a model to retrieve the results.
$data['results'] = $this->JcMeetingExpense_model-
>get_results($search_term);
// Pass the results to the view.
$this->load->view('JcMeetingExpense/jc_meeting_expense',$data);
}









share|improve this question
























  • $results is not returning array so you are getting error. are you able to get results from controller?
    – Jasmin Mistry
    Aug 30 at 5:57













up vote
0
down vote

favorite









up vote
0
down vote

favorite











enter image description here



When i load my controller i'm getting this error in my homepage, but after performing search the error will disappear and search results will be displayed there.



This is my view page:



       <div id="toggle_tst">
<div class="scroll">
<?php
// List up all results.

echo "<table id='table'>";
echo "<tbody>";
echo "<thead>";
echo "<tr><th>NAME</th><th>Pernor No</th><th>DESIGNATION ID</th>
</tr>";
echo "</thead>";
foreach ($results as $row)
{
echo "<tr><td>";
echo $row['name'];
echo "</td><td>";
echo $row['pernor_no'];
echo "</td><td>";
echo $row['designation_id'];
echo "</td></tr>";
}
if (isset($_POST['data_rows']))
{
//if the page has been submitted, append the rows
echo $_POST['data_rows'];
}
echo "</tbody>";
echo "</table>";
?>
</div>
</div>


Controller:



       public function execute_search()
{
// Retrieve the posted search term.
$search_term = $this->input->post('search');
$data['query'] = $this->JcMeetingExpense_model->viewother();
$data['query1'] = $this->JcMeetingExpense_model->viewcatprice();

// Use a model to retrieve the results.
$data['results'] = $this->JcMeetingExpense_model-
>get_results($search_term);
// Pass the results to the view.
$this->load->view('JcMeetingExpense/jc_meeting_expense',$data);
}









share|improve this question















enter image description here



When i load my controller i'm getting this error in my homepage, but after performing search the error will disappear and search results will be displayed there.



This is my view page:



       <div id="toggle_tst">
<div class="scroll">
<?php
// List up all results.

echo "<table id='table'>";
echo "<tbody>";
echo "<thead>";
echo "<tr><th>NAME</th><th>Pernor No</th><th>DESIGNATION ID</th>
</tr>";
echo "</thead>";
foreach ($results as $row)
{
echo "<tr><td>";
echo $row['name'];
echo "</td><td>";
echo $row['pernor_no'];
echo "</td><td>";
echo $row['designation_id'];
echo "</td></tr>";
}
if (isset($_POST['data_rows']))
{
//if the page has been submitted, append the rows
echo $_POST['data_rows'];
}
echo "</tbody>";
echo "</table>";
?>
</div>
</div>


Controller:



       public function execute_search()
{
// Retrieve the posted search term.
$search_term = $this->input->post('search');
$data['query'] = $this->JcMeetingExpense_model->viewother();
$data['query1'] = $this->JcMeetingExpense_model->viewcatprice();

// Use a model to retrieve the results.
$data['results'] = $this->JcMeetingExpense_model-
>get_results($search_term);
// Pass the results to the view.
$this->load->view('JcMeetingExpense/jc_meeting_expense',$data);
}






php mysql codeigniter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 30 at 5:55









ochs.tobi

1,25061029




1,25061029










asked Aug 30 at 5:30









Srujan Ramanna Gowda

15




15












  • $results is not returning array so you are getting error. are you able to get results from controller?
    – Jasmin Mistry
    Aug 30 at 5:57


















  • $results is not returning array so you are getting error. are you able to get results from controller?
    – Jasmin Mistry
    Aug 30 at 5:57
















$results is not returning array so you are getting error. are you able to get results from controller?
– Jasmin Mistry
Aug 30 at 5:57




$results is not returning array so you are getting error. are you able to get results from controller?
– Jasmin Mistry
Aug 30 at 5:57












3 Answers
3






active

oldest

votes

















up vote
3
down vote













use isset before going to execute loop.



isset is the best practice if you are using in your code for variables and array.



For your solution : use below code



if(isset($results)){ 
// all code inside it...


}






share|improve this answer




























    up vote
    3
    down vote













    always use isset() for kind of same condition.



    For more details : Click Here!



    use below code



    if(isset($results)){ 
    // all code inside it...

    }





    share|improve this answer




























      up vote
      1
      down vote













      The reason is you haven't set the variable results. So simple solution is to add a isset() before foreach loop.



      if(isset($results)){
      foreach ($results as $row){
      .
      .
      .
      .
      }
      }





      share|improve this answer























      • Hey tat's worked.... thank you so much!!!
        – Srujan Ramanna Gowda
        Aug 30 at 6:20










      • you're welcome ;-)
        – kalanamw
        Aug 31 at 9:13











      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52089772%2fim-getting-the-following-error-before-performing-employee-search%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      3
      down vote













      use isset before going to execute loop.



      isset is the best practice if you are using in your code for variables and array.



      For your solution : use below code



      if(isset($results)){ 
      // all code inside it...


      }






      share|improve this answer

























        up vote
        3
        down vote













        use isset before going to execute loop.



        isset is the best practice if you are using in your code for variables and array.



        For your solution : use below code



        if(isset($results)){ 
        // all code inside it...


        }






        share|improve this answer























          up vote
          3
          down vote










          up vote
          3
          down vote









          use isset before going to execute loop.



          isset is the best practice if you are using in your code for variables and array.



          For your solution : use below code



          if(isset($results)){ 
          // all code inside it...


          }






          share|improve this answer












          use isset before going to execute loop.



          isset is the best practice if you are using in your code for variables and array.



          For your solution : use below code



          if(isset($results)){ 
          // all code inside it...


          }







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 at 11:11









          Coolbuddy

          23216




          23216
























              up vote
              3
              down vote













              always use isset() for kind of same condition.



              For more details : Click Here!



              use below code



              if(isset($results)){ 
              // all code inside it...

              }





              share|improve this answer

























                up vote
                3
                down vote













                always use isset() for kind of same condition.



                For more details : Click Here!



                use below code



                if(isset($results)){ 
                // all code inside it...

                }





                share|improve this answer























                  up vote
                  3
                  down vote










                  up vote
                  3
                  down vote









                  always use isset() for kind of same condition.



                  For more details : Click Here!



                  use below code



                  if(isset($results)){ 
                  // all code inside it...

                  }





                  share|improve this answer












                  always use isset() for kind of same condition.



                  For more details : Click Here!



                  use below code



                  if(isset($results)){ 
                  // all code inside it...

                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 21 at 11:18









                  vishal melwani

                  1545




                  1545






















                      up vote
                      1
                      down vote













                      The reason is you haven't set the variable results. So simple solution is to add a isset() before foreach loop.



                      if(isset($results)){
                      foreach ($results as $row){
                      .
                      .
                      .
                      .
                      }
                      }





                      share|improve this answer























                      • Hey tat's worked.... thank you so much!!!
                        – Srujan Ramanna Gowda
                        Aug 30 at 6:20










                      • you're welcome ;-)
                        – kalanamw
                        Aug 31 at 9:13















                      up vote
                      1
                      down vote













                      The reason is you haven't set the variable results. So simple solution is to add a isset() before foreach loop.



                      if(isset($results)){
                      foreach ($results as $row){
                      .
                      .
                      .
                      .
                      }
                      }





                      share|improve this answer























                      • Hey tat's worked.... thank you so much!!!
                        – Srujan Ramanna Gowda
                        Aug 30 at 6:20










                      • you're welcome ;-)
                        – kalanamw
                        Aug 31 at 9:13













                      up vote
                      1
                      down vote










                      up vote
                      1
                      down vote









                      The reason is you haven't set the variable results. So simple solution is to add a isset() before foreach loop.



                      if(isset($results)){
                      foreach ($results as $row){
                      .
                      .
                      .
                      .
                      }
                      }





                      share|improve this answer














                      The reason is you haven't set the variable results. So simple solution is to add a isset() before foreach loop.



                      if(isset($results)){
                      foreach ($results as $row){
                      .
                      .
                      .
                      .
                      }
                      }






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Aug 30 at 7:10









                      Erubiel

                      1,790318




                      1,790318










                      answered Aug 30 at 6:04









                      kalanamw

                      134




                      134












                      • Hey tat's worked.... thank you so much!!!
                        – Srujan Ramanna Gowda
                        Aug 30 at 6:20










                      • you're welcome ;-)
                        – kalanamw
                        Aug 31 at 9:13


















                      • Hey tat's worked.... thank you so much!!!
                        – Srujan Ramanna Gowda
                        Aug 30 at 6:20










                      • you're welcome ;-)
                        – kalanamw
                        Aug 31 at 9:13
















                      Hey tat's worked.... thank you so much!!!
                      – Srujan Ramanna Gowda
                      Aug 30 at 6:20




                      Hey tat's worked.... thank you so much!!!
                      – Srujan Ramanna Gowda
                      Aug 30 at 6:20












                      you're welcome ;-)
                      – kalanamw
                      Aug 31 at 9:13




                      you're welcome ;-)
                      – kalanamw
                      Aug 31 at 9:13


















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52089772%2fim-getting-the-following-error-before-performing-employee-search%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Sphinx de Gizeh

                      Dijon

                      Langue