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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rozkan
Forum Newbie
Posts: 10
Joined: Thu Jul 02, 2009 8:08 pm

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

Post 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.
AlanG
Forum Contributor
Posts: 136
Joined: Wed Jun 10, 2009 1:03 am

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

Post 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.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

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

Post 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"]);
rozkan
Forum Newbie
Posts: 10
Joined: Thu Jul 02, 2009 8:08 pm

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

Post 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.
Post Reply