Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/243223-invalid-for-each/#findComment-1249173
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/243223-invalid-for-each/#findComment-1249179
Share on other sites

  // 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?

Link to comment
https://forums.phpfreaks.com/topic/243223-invalid-for-each/#findComment-1249183
Share on other sites

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);
        }

Link to comment
https://forums.phpfreaks.com/topic/243223-invalid-for-each/#findComment-1249185
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/243223-invalid-for-each/#findComment-1249188
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.