Page 1 of 1

Problem: mysql_fetch_array() expects parameter 1 to be...

Posted: Mon Sep 28, 2009 10:33 pm
by rozkan
Hey, i am a newbie and having problem with the code i wrote, any help appreciated. I am using wampserver and PHP version 5.3 and MySQL 5.1. When i try to see the code i wrote i got this error message on left navigation bar:
mysql_fetch_array() expects parameter 1 to be resource, string given in C:\wamp\www\sporsitesi\content.php on line 20
And here's all the PHP code in content.php:

Code: Select all

<?php
                
                $subject_set = get_all_subjects();
                
                //Sorgu verisini kullan.
                while ($subject = mysql_fetch_array($subject_set)) {
                    echo "<li>{$subject["menu_adi"]}</li>";
                
                $page_set = ($subject["id"]);
                
                echo "<ul class=\"sayfalar\">";
                //Sorgu verisini kullan.
                while ($page = mysql_fetch_array($page_set)) {
                    echo "<li>{$page["menu_adi"]}</li>";    
                }
                echo "</ul>";
                }
                ?>
And this is the functions.php file:

Code: Select all

<?php
 
//Bu dosyada PHP fonksiyonlar? toplanm??t?r.
function confirm_query($result_set) {
                    if(!$result_set) {
                    die("Veritaban? sorgulamas? ba?ar?s?z" . mysql_error());
                }
                }
 
function get_all_subjects() {
                global $connection;
                        $query = "SELECT * 
                        FROM konular 
                        ORDER BY pozisyon ASC";
                $subject_set = mysql_query($query, $connection);
                confirm_query($subject_set);
                return $subject_set;
                }
 
function get_pages_for_subject_id($subject_id) {
                global $connection;
                        $query = "SELECT * 
                        FROM sayfalar 
                        WHERE subject_id = {$subject["id"]} 
                        ORDER BY pozisyon ASC";
                
                $page_set = mysql_query($query , $connection);
                confirm_query($page_set);
                }
 
?>
Thanks.

Re: Problem: mysql_fetch_array() expects parameter 1 to be...

Posted: Tue Sep 29, 2009 4:30 am
by AlanG
mysql_fetch_array accepts a resource as a parameter. A resource can mean alot of things but in this case it is looking for a result set returned from a mysql database query. $page_set is a string. You will need to query the database again or fix your logic.

Re: Problem: mysql_fetch_array() expects parameter 1 to be...

Posted: Tue Sep 29, 2009 4:47 am
by Mark Baker
I'd assume that

Code: Select all

$page_set = ($subject["id"]);
should be

Code: Select all

$page_set = get_pages_for_subject_id($subject["id"]);

Re: Problem: mysql_fetch_array() expects parameter 1 to be...

Posted: Tue Sep 29, 2009 10:22 pm
by rozkan
Yes Mark, that was the problem, i was able to solve it by myself after spending some time but thanks for help anyway.