Warning: Invalid argument supplied for foreach() in line no........

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rashgang
    New Member
    • Oct 2008
    • 17

    Warning: Invalid argument supplied for foreach() in line no........

    i have dynamically created checkbox which will like yahoo mail if check box selected it will highlight a row but deleteall function is not working plz chek it

    Code:
    function doDeleteAll($objArray){
    
    	foreach($objArray['frmcheckall'] as $strkey=>$strValue) {
    
    			$strDeleteId = $strValue;
    			
    			 doDelete($strDeleteId);
    			
    		}
    	}
    function doDelete($strDeleteId){
    
    $strQuery = "UPDATE
    			             tbl_categories 
    						 SET 
    						      IsDeleted = 'Yes' 
    						 WHERE  
    						      CategoryId = '".$strDeleteId."'";
    		if(ExecuteQry($strQuery))
    			return 1;
    		else
    			return 0;
    		
    	}
    
    
    <tr class="tablehead" id="frmcheck<?php print $i; ?>">
          <td height="25" align="center"><input name="frmcheckall<?php //print $i; ?>" type="checkbox" id="frmcheckall<?php print $i; ?>" value="<? print $strValue[$i]['CategoryId']; ?>" onclick="highlightRow('frmcheckall<?php print $i; ?>','frmcheck<?php print $i; ?>');" />
          </td>
          <td class="tablecontent"><? print $strValue[$i]['CategoryName']; ?></td>
          <td align="center" class="tablecontent"><a href="edit.php?id=<? print $strValue[$i]['CategoryId']; ?>">Edit</a>
            | <a href="javascript:deleteConfirm('cateogrylist.php?id=<? print $strValue[$i]['CategoryId']; ?>')">Delete
            </a> </td>
        </tr>
    Last edited by Markus; Oct 29 '08, 05:20 PM. Reason: added # tags
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Assuming title is the error then $objArray is empty

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Hey there, Rashgang.

      When posting code on the forums, be sure to use [code] tags. [code] .. code goes here [/code]. If you neglect to do so, you will be given a warning and possibly a temporary ban. Please read the Posting Guidelines on How To Ask A Question

      Markus.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Is $objArray['frmcheckall'] an array as well or is $objArray the only array?

        Comment

        • rashgang
          New Member
          • Oct 2008
          • 17

          #5
          its a php script coding plz answer for it
          this is the first time i am posting a question thats y

          Comment

          • rashgang
            New Member
            • Oct 2008
            • 17

            #6
            this function include in the main page of php
            Code:
              function doDeleteAll($objArray){
              
                    foreach($objArray['frmcheckall'] as $strkey=>$strValue) {
             
                         $strDeleteId = $strValue;
                
                           doDelete($strDeleteId);
              
                        }
                 }
              function doDelete($strDeleteId){
              
               $strQuery = "UPDATE
                                      tbl_categories 
                                    SET 
                                          IsDeleted = 'Yes' 
                                      WHERE  
                                         CategoryId = '".$strDeleteId."'";
                     if(ExecuteQry($strQuery))
                         return 1;
                     else
                           return 0;
                
                  }
               
              
              <tr class="tablehead" id="frmcheck<?php print $i; ?>">
                   <td height="25" align="center"><input name="frmcheckall<?php //print $i; ?>" type="checkbox" id="frmcheckall<?php print $i; ?>" value="<? print $strValue[$i]['CategoryId']; ?>" onclick="highlightRow('frmcheckall<?php print $i; ?>','frmcheck<?php print $i; ?>');" />
                 </td>
                    <td class="tablecontent"><? print $strValue[$i]['CategoryName']; ?></td>
                     <td align="center" class="tablecontent"><a href="edit.php?id=<? print $strValue[$i]['CategoryId']; ?>">Edit</a>
                       | <a href="javascript:deleteConfirm('cateogrylist.php?id=<? print $strValue[$i]['CategoryId']; ?>')">Delete
                     </a> </td>
                 </tr>
            Last edited by Markus; Oct 30 '08, 02:02 PM. Reason: added code tags. formatting will be messed up now.

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by rashgang
              its a php script coding plz answer for it
              this is the first time i am posting a question thats y
              Of course it's a PHP script. That's why you posted it in the PHP forum.
              That foreach requires that first argument to be an array expression. That's why I asked if you are sure that your first argument is an array.

              Comment

              • code green
                Recognized Expert Top Contributor
                • Mar 2007
                • 1726

                #8
                Has somebody upset rashgang?

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  Originally posted by code green
                  Has somebody upset rashgang?
                  I don't think so(not sure actually).

                  Comment

                  • Markus
                    Recognized Expert Expert
                    • Jun 2007
                    • 6092

                    #10
                    Rashgang, you have been told previously to use code tags in this thread!. You have now received a warning, and a continuation of this behaviour will typically result in a ban of some sort. It is in your best interests to follow the Posting Guidelines.

                    Markus.

                    Comment

                    • rashgang
                      New Member
                      • Oct 2008
                      • 17

                      #11
                      warning: foreach() invalid argument in line no 73

                      Code:
                      <?php
                       include "includes/connection.php";
                       include "includes/Functions_category.php";
                       include "includes/functions_db.php";
                       $Strtitle="Category Management (Category Listing)";
                       $strAddedDate=date("Y-m-d h:m:s");
                       
                          if($_POST['frmcheckall']){    
                             print doDeleteAll($_POST);
                      	   
                         }
                             if(isset($_GET['id'])){
                          //if($_POST['id']){
                          //$strDelete=doDeleteAll['id'];
                         // }
                          if(!doDelete($_GET['id'])){$strMessage= "Invalid Inputs Detected!";}
                         }
                      
                      
                       include"includes/pagestart.php"; ?>
                      <link href="css/fonts.css" rel="stylesheet" type="text/css">
                      <script type="text/javascript">
                      function checkAll(field){
                       field=document.frmcategory.frmcheckall;
                       for (i = 0; i < field.length; i++){
                       field[i].checked = true;
                       highlightRow('frmcheckall'+i,'frmcheck'+i);
                       }
                       }
                      function uncheckAll(field){
                       field=document.frmcategory.frmcheckall;
                       for (i = 0; i < field.length; i++){
                       field[i].checked = false;
                       highlightRow('frmcheckall'+i,'frmcheck'+i);
                       }
                       }
                      /*function deleteall(field){
                      
                          field=document.frmcateogry.frmcheckall;
                       flag=0;
                       for(i=0;i< field.length;i++){
                        
                        if(field[i].checked)
                        flag=1;
                        }
                       if(flag==1){
                         alert("Hi");
                         document.frmcateogry.frmcheckall.submit();
                       }else
                         alert("Please select one category to Delete");
                       }*/
                       function deleted(field){
                       //field=document.frmcategory.frmcheckall;
                        flag=0;
                        for(i=0;i< field.length;i++){
                         if(field[i].checked)
                         flag=1;
                        }
                        
                        if(flag==1){
                         if(confirm("Are You Sure To Delete The Category List?")){
                         field.submit();
                         }
                        }else
                         alert("Please Select One Category To DELETE");
                       }
                       function highlightRow(id,id1) { //alert(id1);
                       
                        if (document.getElementById(id).checked) {
                        
                         document.getElementById(id1).bgColor = '#E2E6A8';
                        }
                        else {
                        
                         document.getElementById(id1).bgColor = '#FFFFFF';
                        }
                        }
                       
                      function deleteConfirm(delUrl) {
                        if (confirm("Are You Sure To Delete This Category?")) {
                          document.location = delUrl;
                          }
                        }
                      </script>
                      <form name="frmcategory" method="post" action="">
                      
                        <table width="90%" border="0" cellspacing="3" cellpadding="3" align="center">
                        <tr><td><? print $strMessage ;?></td></tr>
                          <tr>
                            <td align="center">
                              <?
                        $strQuery="select * from tbl_categories where IsDeleted='No'";
                        $strValue=SelectQry($strQuery);
                         if(is_array($strValue)){
                         ?>
                              <span class="tablehead">Category List</span></td>
                          </tr>
                        </table>
                        <div align="center">&nbsp;
                          <table width="414" height="20" border="0" cellpadding="0" cellspacing="0" class="size">
                            <tr>
                              <td width="414" class="headerfont"><a href="javascript:onclick=checkAll();" class="headerfont">SELECT
                                ALL | </a><a href="javascript:onclick=uncheckAll();" class="headerfont">UNSELECT
                                ALL </a>| <a href="javascript:onclick=deleted(frmcategory);" class="headerfont">DELETE
                                SELECTED </a></td>
                            </tr>
                          </table>
                        </div>
                        <table width="421" border="1" align="center" cellpadding="5" cellspacing="0" bordercolor="#999999" class="headerfont" style="border-collapse:collapse">
                          <tr class="tablehead">
                            <td width="44" height="29">&nbsp;</td>
                            <td width="278" align="center">CATEGORY NAME </td>
                            <td width="179" align="center">ACTION </td>
                          </tr>
                          <?
                       //while($rows = mysql_fetch_object($stredit)){
                       for($i=0;$i<count($strValue);$i++) {
                        ?>
                          <tr class="tablehead" id="frmcheck<?php print $i; ?>">
                            <td height="25" align="center"><input name="frmcheckall" type="checkbox" id="frmcheckall<?php print $i; ?>" value="<? print $strValue[$i]['CategoryId']; ?>" onclick="highlightRow('frmcheckall<?php print $i; ?>','frmcheck<?php print $i; ?>');" />
                            </td>
                            <td class="tablecontent"><? print $strValue[$i]['CategoryName']; ?></td>
                            <td align="center" class="tablecontent"><a href="edit.php?id=<? print $strValue[$i]['CategoryId']; ?>">Edit</a>
                              | <a href="javascript:deleteConfirm('cateogrylist.php?id=<? print $strValue[$i]['CategoryId']; ?>')">Delete
                              </a> </td>
                          </tr>
                          <?
                       }
                      //mysql_free_result($stredit);
                      ?>
                          <tr align="left" class="tablehead">
                            <td height="25" colspan="3"><span class="tablecontent2"><a href="javascript:onclick=checkAll();" class="size">Select
                              all | </a><a href="javascript:onclick=uncheckAll();" class="size">UnSelect
                              All</a> | <a href="javascript:onclick=deleted(frmcategory);" class="size">Delete
                              SELECTED </a></span>
                              <div align="center"></div>
                              <div align="center"></div></td>
                          </tr>
                          <? }else{?>
                          <font face="Verdana, Arial, Helvetica, sans-serif" size="+1" color="#FF0000">
                          <center>
                            <? print "Sorry!No Records Found !!!";?>
                          </center>
                          </font>
                          <? }?>
                        </table>
                       
                        <p class="headerfont">&nbsp;</p>
                      </form>
                      <? include "includes/pageend.php"; ?>
                      
                      this is the function category coding
                      
                      <?
                      function doDeleteAll($objArray){
                      
                      
                      	foreach((array)$objArray['frmcheckall'] as $strkey=>$strValue) {
                      			$strDeleteId = $strValue;
                      			
                      			 doDelete($strDeleteId);
                      			  //print_r($strDeleteId);
                      						/*$strQuery=  "UPDATE 
                      			               tbl_categories  
                      						  SET 
                      						      IsDeleted = 'Yes' 
                      						  WHERE
                      						      Ident =".$strDeleteId." 
                      						   LIMIT 1";*/
                      						  
                      						  //doDelete($objGetArray['id']);
                      						 
                      /*if(doDelete($objGetArray['id'])){
                      			return 1;
                      			//print_r(($objGetArray['id']));
                      			}
                      			else{
                      			return 0;}*/
                      		}
                      	}
                      
                      /*function doDelete($objGetArray){
                      	if(is_numeric($objGetArray['id'])){
                      		$strQuery="SELECT * 
                      		           FROM
                      					      tbl_categories 
                      				   WHERE 
                      					  Ident=".$objGetArray['id'];
                      		$strRows = SelectQry($strQuery);
                      		if(is_array($strRows)){
                      			$strQuery = "UPDATE
                      			                 tbl_categories 
                      						 SET 
                      						      IsDeleted = 'Yes' 
                      						 WHERE  
                      						      Ident =".$objGetArray['id']." 
                      						 LIMIT 1";
                      			ExecuteQry($strQuery);
                      			return 1;
                      		}else{
                      			return 0;
                      		}
                      	}else{
                      			return 0;
                      	}
                      } */
                      function doDelete($strDeleteId){
                      //print_r($objGetArray);
                      //if($objGetArray['id']){
                      $strQuery = "UPDATE
                      			             tbl_categories 
                      						 SET 
                      						      IsDeleted = 'Yes' 
                      						 WHERE  
                      						      CategoryId = '".$strDeleteId."'";
                       // print_r($strQuery);
                      		if(ExecuteQry($strQuery))
                      			return 1;
                      		else
                      			return 0;
                      		
                      	}
                      
                      ?>
                      Last edited by Markus; Oct 31 '08, 02:09 PM. Reason: added # tags

                      Comment

                      • nathj
                        Recognized Expert Contributor
                        • May 2007
                        • 937

                        #12
                        I'd love to help but I can't bothered to find the line.

                        Use code tags and you get line numbers and people are much more likely to help you out.

                        nathj

                        Comment

                        • Markus
                          Recognized Expert Expert
                          • Jun 2007
                          • 6092

                          #13
                          rashgang, you are precariously close to border between ignorance and justified newby-ness. You have, in 4 posts, double posted and not once used code tags - something you were previously warned about. Therefore, this is your second formal warning. Please take note of this or you may receive a ban.

                          Posting Guidelines - read them.

                          Comment

                          • rashgang
                            New Member
                            • Oct 2008
                            • 17

                            #14
                            thank u for ur advice then i have tagged the php see clearly i have used code tags for example <?php
                            ?>

                            Comment

                            • Markus
                              Recognized Expert Expert
                              • Jun 2007
                              • 6092

                              #15
                              Originally posted by rashgang
                              thank u for ur advice then i have tagged the php see clearly i have used code tags for example <?php
                              ?>
                              If you look at post 3 you will see I explain what code tags are.

                              Comment

                              Working...