views:

62

answers:

1

Im sorry if this post is long winded

I have 2 php functions that that gets data from the database, the first one works fine but the second one doesnt seem to work and I cant find the cours. I hope somebody can find out, I have include the code for both functions and how I used them

function data_to_maani_xml() {
    $i=0;
    $xml="<chart>";
            $xml .= "<chart_type>".$this->type."</chart_type>";
            $xml .= "<chart_data>";
            $xml .= $this->first_row();
    while($row=mysql_fetch_array($this->result, MYSQL_ASSOC)) {
        $xml=$xml."<row>";
        $i=0;
        while($i < mysql_num_fields($this->result)) {
            $meta = mysql_fetch_field($this->result, $i);
            //echo $meta->name.'<br>';
            $xml=$xml."<".$meta->name.">";
            //echo $row[$meta->name];
            $xml=$xml.$row[$meta->name];
            $xml=$xml."</".$meta->name.">";
            $i++;
        }
        $xml=$xml."</row>";
    }
    $xml=$xml."</chart_data>";
            $xml .= "</chart>";
            return $xml;
            }


    function first_row()
    {
                $i=0;

    while($row=mysql_fetch_array($this->first_row_query, MYSQL_ASSOC)) {
        $xml= "<row>";
                    $xml .= "<null/>";
                     $i = 0;
        while($i < mysql_num_fields($this->first_row_query)) {
            $meta = mysql_fetch_field($this->first_row_query, $i);
            //echo $meta->name.'<br>';
            $xml=$xml."<".$meta->name.">";
            //echo $row[$meta->name];
            $xml=$xml.$row[$meta->name];
            $xml=$xml."</".$meta->name.">";
            $i++;
        }
        $xml=$xml."</row>";
    }

            return $xml;
     }

set_firstrow("SELECT name FROM mytable GROUP BY name ORDER BY name"); set_query("select * from mytable");

Im sorry for not being more clear please forgive me, Ill start again

The data_to_maani_xml() function creates an xml file from data that appears in the database and this function works fine but it does call the first_row() function wich also gets data from the database. the data_to_maani_xml() adds the return value of first_row() to the top of the xml file before prepending the rest of the data. so it would be something like this

set_firsrow() and set_query() sets the variables $this->first_row_query and $this->result respectively

everything seems to work fine when I comment out the line $xml .= $this->first_row(); in the function data_to_maani_xml() function

the error I get when I include that line is Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in C:\xampplite\htdocs\xml\db.php on line 158

this indicates that the function first_row() does not return anything. the way that I called this function is like this

$ddb->set_firstrow("SELECT name FROM mytable GROUP BY name ORDER BY name");

Im not sure if that error is due to me only selecting one column

I ran the query and it does return the results that it should

A: 

Everything you need to know is explained here:

http://catb.org/~esr/faqs/smart-questions.html

C.

symcbean