darkfreaks Posted July 29, 2011 Share Posted July 29, 2011 need some help i can't figure out what i am doing wrong foreach($ct->data as $key => $value){ $ct->data[$key][3]='<a class="ezjax" href="view_message.php?id='.$ct->data[$key][0].'">'.$ct->data[$key][3].'</a>'; } Quote Link to comment https://forums.phpfreaks.com/topic/243223-invalid-for-each/ Share on other sites More sharing options...
The Little Guy Posted July 29, 2011 Share Posted July 29, 2011 Run this code, to see how a foreach loop works: $myArray = array("cat"=>"a cat", "dog"=>"a dog"); foreach($myArray as $key => $value){ echo "Key: $key<br>"; echo "Valaue: $value<br>"; echo "<br>"; } It is hard to work with your code, because I have no idea what $ct->data is or what it looks like. My example may help you out though. Quote Link to comment https://forums.phpfreaks.com/topic/243223-invalid-for-each/#findComment-1249173 Share on other sites More sharing options...
Maq Posted July 29, 2011 Share Posted July 29, 2011 Are you sure the variable 'data' from the $ct object is an array? Show us how it's being generated. Quote Link to comment https://forums.phpfreaks.com/topic/243223-invalid-for-each/#findComment-1249176 Share on other sites More sharing options...
darkfreaks Posted July 29, 2011 Author Share Posted July 29, 2011 im getting errors in the file which all that is defined about mysql_free result and fetch_row() $this->total_items=mysql_fetch_row($result); mysql_free_result($result) i am not sure if this code is the problem or just apart of it NOT a valid MYSQL resource Quote Link to comment https://forums.phpfreaks.com/topic/243223-invalid-for-each/#findComment-1249179 Share on other sites More sharing options...
Maq Posted July 29, 2011 Share Posted July 29, 2011 That usually means your query failed, which means mysql_query() returned false, which means $result is false, hence your error. Quote Link to comment https://forums.phpfreaks.com/topic/243223-invalid-for-each/#findComment-1249182 Share on other sites More sharing options...
darkfreaks Posted July 29, 2011 Author Share Posted July 29, 2011 // total of items if($this->total_items<=0){ if($this->table_key) $result=mysql_query(str_replace($bd_fields,'count('.$this->table_key.')',$this->get_sql_select()).$this->get_sql_where(false)); else $result=mysql_query(str_replace($bd_fields,'count('.$this->sql_fields[0].')',$this->get_sql_select()).$this->get_sql_where(false)); $this->total_items=mysql_fetch_row($result); $this->total_items=$this->total_items[0]; mysql_free_result($result); } how would i fix this? Quote Link to comment https://forums.phpfreaks.com/topic/243223-invalid-for-each/#findComment-1249183 Share on other sites More sharing options...
Maq Posted July 29, 2011 Share Posted July 29, 2011 Added some debugging code: // total of items if($this->total_items if($this->table_key) { $sql = "str_replace($bd_fields,'count('.$this->table_key.')',$this->get_sql_select()).$this->get_sql_where(false)"; echo "IF QUERY: " . $sql; $result=mysql_query($sql) or die(mysql_error()); } else { $sql = "str_replace($bd_fields,'count('.$this->sql_fields[0].')',$this->get_sql_select()).$this->get_sql_where(false)"; echo "ELSE QUERY: " . $sql; $result=mysql_query($sql) or die(mysql_error()); $this->total_items=mysql_fetch_row($result); $this->total_items=$this->total_items[0]; } mysql_free_result($result); } Quote Link to comment https://forums.phpfreaks.com/topic/243223-invalid-for-each/#findComment-1249185 Share on other sites More sharing options...
darkfreaks Posted July 29, 2011 Author Share Posted July 29, 2011 ELSE QUERY: str_replace(id,received_by,date,subject,'count('.Array[0].')',()).(false)You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'str_replace(id,received_by,date,subject,'count('.Array[0].')',()).(false)' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/243223-invalid-for-each/#findComment-1249188 Share on other sites More sharing options...
Maq Posted July 29, 2011 Share Posted July 29, 2011 Oops, sorry take of the double quotes for the query strings. Quote Link to comment https://forums.phpfreaks.com/topic/243223-invalid-for-each/#findComment-1249190 Share on other sites More sharing options...
darkfreaks Posted July 29, 2011 Author Share Posted July 29, 2011 $result = mysql_query("SELECT * FROM notifications WHERE status=1 AND member_id=$m_id") or die(mysql_error()); i rearranged the statement abit still getting same error ithe original way it was told me the error was near 'AND Quote Link to comment https://forums.phpfreaks.com/topic/243223-invalid-for-each/#findComment-1249193 Share on other sites More sharing options...
Maq Posted July 29, 2011 Share Posted July 29, 2011 What type is the status column? Quote Link to comment https://forums.phpfreaks.com/topic/243223-invalid-for-each/#findComment-1249196 Share on other sites More sharing options...
darkfreaks Posted July 29, 2011 Author Share Posted July 29, 2011 Welcome: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND status=1' at line 1 i am assuming this is something wrong with members? Quote Link to comment https://forums.phpfreaks.com/topic/243223-invalid-for-each/#findComment-1249205 Share on other sites More sharing options...
Maq Posted August 1, 2011 Share Posted August 1, 2011 You're changing your query around... First it was: WHERE status=1 Now it's: AND status=1 Quote Link to comment https://forums.phpfreaks.com/topic/243223-invalid-for-each/#findComment-1250201 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.