By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,664 Members | 1,669 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,664 IT Pros & Developers. It's quick & easy.

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

P: 17
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

Expand|Select|Wrap|Line Numbers
  1. function doDeleteAll($objArray){
  2.  
  3.     foreach($objArray['frmcheckall'] as $strkey=>$strValue) {
  4.  
  5.             $strDeleteId = $strValue;
  6.  
  7.              doDelete($strDeleteId);
  8.  
  9.         }
  10.     }
  11. function doDelete($strDeleteId){
  12.  
  13. $strQuery = "UPDATE
  14.                          tbl_categories 
  15.                          SET 
  16.                               IsDeleted = 'Yes' 
  17.                          WHERE  
  18.                               CategoryId = '".$strDeleteId."'";
  19.         if(ExecuteQry($strQuery))
  20.             return 1;
  21.         else
  22.             return 0;
  23.  
  24.     }
  25.  
  26.  
  27. <tr class="tablehead" id="frmcheck<?php print $i; ?>">
  28.       <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; ?>');" />
  29.       </td>
  30.       <td class="tablecontent"><? print $strValue[$i]['CategoryName']; ?></td>
  31.       <td align="center" class="tablecontent"><a href="edit.php?id=<? print $strValue[$i]['CategoryId']; ?>">Edit</a>
  32.         | <a href="javascript:deleteConfirm('cateogrylist.php?id=<? print $strValue[$i]['CategoryId']; ?>')">Delete
  33.         </a> </td>
  34.     </tr>
Oct 29 '08 #1
Share this Question
Share on Google+
14 Replies


code green
Expert 100+
P: 1,726
Assuming title is the error then $objArray is empty
Oct 29 '08 #2

Markus
Expert 5K+
P: 6,050
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.
Oct 29 '08 #3

10K+
P: 13,264
Is $objArray['frmcheckall'] an array as well or is $objArray the only array?
Oct 30 '08 #4

P: 17
its a php script coding plz answer for it
this is the first time i am posting a question thats y
Oct 30 '08 #5

P: 17
this function include in the main page of php
Expand|Select|Wrap|Line Numbers
  1.   function doDeleteAll($objArray){
  2.  
  3.         foreach($objArray['frmcheckall'] as $strkey=>$strValue) {
  4.  
  5.              $strDeleteId = $strValue;
  6.  
  7.                doDelete($strDeleteId);
  8.  
  9.             }
  10.      }
  11.   function doDelete($strDeleteId){
  12.  
  13.    $strQuery = "UPDATE
  14.                           tbl_categories 
  15.                         SET 
  16.                               IsDeleted = 'Yes' 
  17.                           WHERE  
  18.                              CategoryId = '".$strDeleteId."'";
  19.          if(ExecuteQry($strQuery))
  20.              return 1;
  21.          else
  22.                return 0;
  23.  
  24.       }
  25.  
  26.  
  27.   <tr class="tablehead" id="frmcheck<?php print $i; ?>">
  28.        <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; ?>');" />
  29.      </td>
  30.         <td class="tablecontent"><? print $strValue[$i]['CategoryName']; ?></td>
  31.          <td align="center" class="tablecontent"><a href="edit.php?id=<? print $strValue[$i]['CategoryId']; ?>">Edit</a>
  32.            | <a href="javascript:deleteConfirm('cateogrylist.php?id=<? print $strValue[$i]['CategoryId']; ?>')">Delete
  33.          </a> </td>
  34.      </tr>
Oct 30 '08 #6

10K+
P: 13,264
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.
Oct 30 '08 #7

code green
Expert 100+
P: 1,726
Has somebody upset rashgang?
Oct 30 '08 #8

10K+
P: 13,264
Has somebody upset rashgang?
I don't think so(not sure actually).
Oct 30 '08 #9

Markus
Expert 5K+
P: 6,050
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.
Oct 30 '08 #10

P: 17
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  include "includes/connection.php";
  3.  include "includes/Functions_category.php";
  4.  include "includes/functions_db.php";
  5.  $Strtitle="Category Management (Category Listing)";
  6.  $strAddedDate=date("Y-m-d h:m:s");
  7.  
  8.     if($_POST['frmcheckall']){    
  9.        print doDeleteAll($_POST);
  10.  
  11.    }
  12.        if(isset($_GET['id'])){
  13.     //if($_POST['id']){
  14.     //$strDelete=doDeleteAll['id'];
  15.    // }
  16.     if(!doDelete($_GET['id'])){$strMessage= "Invalid Inputs Detected!";}
  17.    }
  18.  
  19.  
  20.  include"includes/pagestart.php"; ?>
  21. <link href="css/fonts.css" rel="stylesheet" type="text/css">
  22. <script type="text/javascript">
  23. function checkAll(field){
  24.  field=document.frmcategory.frmcheckall;
  25.  for (i = 0; i < field.length; i++){
  26.  field[i].checked = true;
  27.  highlightRow('frmcheckall'+i,'frmcheck'+i);
  28.  }
  29.  }
  30. function uncheckAll(field){
  31.  field=document.frmcategory.frmcheckall;
  32.  for (i = 0; i < field.length; i++){
  33.  field[i].checked = false;
  34.  highlightRow('frmcheckall'+i,'frmcheck'+i);
  35.  }
  36.  }
  37. /*function deleteall(field){
  38.  
  39.     field=document.frmcateogry.frmcheckall;
  40.  flag=0;
  41.  for(i=0;i< field.length;i++){
  42.  
  43.   if(field[i].checked)
  44.   flag=1;
  45.   }
  46.  if(flag==1){
  47.    alert("Hi");
  48.    document.frmcateogry.frmcheckall.submit();
  49.  }else
  50.    alert("Please select one category to Delete");
  51.  }*/
  52.  function deleted(field){
  53.  //field=document.frmcategory.frmcheckall;
  54.   flag=0;
  55.   for(i=0;i< field.length;i++){
  56.    if(field[i].checked)
  57.    flag=1;
  58.   }
  59.  
  60.   if(flag==1){
  61.    if(confirm("Are You Sure To Delete The Category List?")){
  62.    field.submit();
  63.    }
  64.   }else
  65.    alert("Please Select One Category To DELETE");
  66.  }
  67.  function highlightRow(id,id1) { //alert(id1);
  68.  
  69.   if (document.getElementById(id).checked) {
  70.  
  71.    document.getElementById(id1).bgColor = '#E2E6A8';
  72.   }
  73.   else {
  74.  
  75.    document.getElementById(id1).bgColor = '#FFFFFF';
  76.   }
  77.   }
  78.  
  79. function deleteConfirm(delUrl) {
  80.   if (confirm("Are You Sure To Delete This Category?")) {
  81.     document.location = delUrl;
  82.     }
  83.   }
  84. </script>
  85. <form name="frmcategory" method="post" action="">
  86.  
  87.   <table width="90%" border="0" cellspacing="3" cellpadding="3" align="center">
  88.   <tr><td><? print $strMessage ;?></td></tr>
  89.     <tr>
  90.       <td align="center">
  91.         <?
  92.   $strQuery="select * from tbl_categories where IsDeleted='No'";
  93.   $strValue=SelectQry($strQuery);
  94.    if(is_array($strValue)){
  95.    ?>
  96.         <span class="tablehead">Category List</span></td>
  97.     </tr>
  98.   </table>
  99.   <div align="center">&nbsp;
  100.     <table width="414" height="20" border="0" cellpadding="0" cellspacing="0" class="size">
  101.       <tr>
  102.         <td width="414" class="headerfont"><a href="javascript:onclick=checkAll();" class="headerfont">SELECT
  103.           ALL | </a><a href="javascript:onclick=uncheckAll();" class="headerfont">UNSELECT
  104.           ALL </a>| <a href="javascript:onclick=deleted(frmcategory);" class="headerfont">DELETE
  105.           SELECTED </a></td>
  106.       </tr>
  107.     </table>
  108.   </div>
  109.   <table width="421" border="1" align="center" cellpadding="5" cellspacing="0" bordercolor="#999999" class="headerfont" style="border-collapse:collapse">
  110.     <tr class="tablehead">
  111.       <td width="44" height="29">&nbsp;</td>
  112.       <td width="278" align="center">CATEGORY NAME </td>
  113.       <td width="179" align="center">ACTION </td>
  114.     </tr>
  115.     <?
  116.  //while($rows = mysql_fetch_object($stredit)){
  117.  for($i=0;$i<count($strValue);$i++) {
  118.   ?>
  119.     <tr class="tablehead" id="frmcheck<?php print $i; ?>">
  120.       <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; ?>');" />
  121.       </td>
  122.       <td class="tablecontent"><? print $strValue[$i]['CategoryName']; ?></td>
  123.       <td align="center" class="tablecontent"><a href="edit.php?id=<? print $strValue[$i]['CategoryId']; ?>">Edit</a>
  124.         | <a href="javascript:deleteConfirm('cateogrylist.php?id=<? print $strValue[$i]['CategoryId']; ?>')">Delete
  125.         </a> </td>
  126.     </tr>
  127.     <?
  128.  }
  129. //mysql_free_result($stredit);
  130. ?>
  131.     <tr align="left" class="tablehead">
  132.       <td height="25" colspan="3"><span class="tablecontent2"><a href="javascript:onclick=checkAll();" class="size">Select
  133.         all | </a><a href="javascript:onclick=uncheckAll();" class="size">UnSelect
  134.         All</a> | <a href="javascript:onclick=deleted(frmcategory);" class="size">Delete
  135.         SELECTED </a></span>
  136.         <div align="center"></div>
  137.         <div align="center"></div></td>
  138.     </tr>
  139.     <? }else{?>
  140.     <font face="Verdana, Arial, Helvetica, sans-serif" size="+1" color="#FF0000">
  141.     <center>
  142.       <? print "Sorry!No Records Found !!!";?>
  143.     </center>
  144.     </font>
  145.     <? }?>
  146.   </table>
  147.  
  148.   <p class="headerfont">&nbsp;</p>
  149. </form>
  150. <? include "includes/pageend.php"; ?>
  151.  
  152. this is the function category coding
  153.  
  154. <?
  155. function doDeleteAll($objArray){
  156.  
  157.  
  158.     foreach((array)$objArray['frmcheckall'] as $strkey=>$strValue) {
  159.             $strDeleteId = $strValue;
  160.  
  161.              doDelete($strDeleteId);
  162.               //print_r($strDeleteId);
  163.                         /*$strQuery=  "UPDATE 
  164.                            tbl_categories  
  165.                           SET 
  166.                               IsDeleted = 'Yes' 
  167.                           WHERE
  168.                               Ident =".$strDeleteId." 
  169.                            LIMIT 1";*/
  170.  
  171.                           //doDelete($objGetArray['id']);
  172.  
  173. /*if(doDelete($objGetArray['id'])){
  174.             return 1;
  175.             //print_r(($objGetArray['id']));
  176.             }
  177.             else{
  178.             return 0;}*/
  179.         }
  180.     }
  181.  
  182. /*function doDelete($objGetArray){
  183.     if(is_numeric($objGetArray['id'])){
  184.         $strQuery="SELECT * 
  185.                    FROM
  186.                           tbl_categories 
  187.                    WHERE 
  188.                       Ident=".$objGetArray['id'];
  189.         $strRows = SelectQry($strQuery);
  190.         if(is_array($strRows)){
  191.             $strQuery = "UPDATE
  192.                              tbl_categories 
  193.                          SET 
  194.                               IsDeleted = 'Yes' 
  195.                          WHERE  
  196.                               Ident =".$objGetArray['id']." 
  197.                          LIMIT 1";
  198.             ExecuteQry($strQuery);
  199.             return 1;
  200.         }else{
  201.             return 0;
  202.         }
  203.     }else{
  204.             return 0;
  205.     }
  206. } */
  207. function doDelete($strDeleteId){
  208. //print_r($objGetArray);
  209. //if($objGetArray['id']){
  210. $strQuery = "UPDATE
  211.                          tbl_categories 
  212.                          SET 
  213.                               IsDeleted = 'Yes' 
  214.                          WHERE  
  215.                               CategoryId = '".$strDeleteId."'";
  216.  // print_r($strQuery);
  217.         if(ExecuteQry($strQuery))
  218.             return 1;
  219.         else
  220.             return 0;
  221.  
  222.     }
  223.  
  224. ?>
Oct 31 '08 #11

nathj
Expert 100+
P: 938
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
Oct 31 '08 #12

Markus
Expert 5K+
P: 6,050
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.
Oct 31 '08 #13

P: 17
thank u for ur advice then i have tagged the php see clearly i have used code tags for example <?php
?>
Nov 1 '08 #14

Markus
Expert 5K+
P: 6,050
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.
Nov 1 '08 #15

Post your reply

Sign in to post your reply or Sign up for a free account.