I think i narrowed down the problem and know what is wrong, and just
solved the problem:). The problem wasn't with mysql or php it was because of
my poor i should say object-oriented skill. I will tell why I had this
problem so that it might be a good reference for someone else who are likely
to get in the same trap:)
  I wrote a class in PHP which serves as a template to all other pages. It
is called "page_layout.inc" and also have another include file (db.inc)
which takes care of db connection.
  So, everypage I have has require("../../page_layout.inc"); and require
("../../db.inc"); lines.
  Normally, my pages just set title of the page and the content of the page
by either giving arguments to SetTitle() and SetContent() functions or
overridding DisplayContent() function. So the code pretty much looks like
this in every page:
  For those setting SetTitle and SetContent functions:
     require (   "../../page_layout.inc");
     require ( "../../db.inc" );

     $query="select * from $tab where encoding = 0 and
articleid=$articleid";
     $result=mysql_query($query);
     $row = mysql_fetch_array($result);


     $page = new page_layout();
     $page -> SetTitle($row[title]);
     $page -> SetContent($row[content]);
     $page -> DisplayPage();

   And For those overridding DisplayContent() function:

    require ("../../page_layout.inc");
    require ("../../db.inc");
    class testpage extends page_layout
    {
        function DisplayContent()
        {
         .
         .
         .
        } // End of DisplayContent() function
   } //end of class testpage
        $page= new testpage();
        $title= "TITLE";

       $page -> SetTitle($title);
       $page -> DisplayPage();

  Ok, the problem i was having with mysql_num_rows have occured in the
DisplayContent() function in the new class. Here are some of the things I
have tried:

                $query="select distinct(nodeid), nodename from books";
                $result=mysql_query($query);
                $num_results =  mysql_num_rows($result);
       This has worked ok. It didn't have a where clause and it did work.

                $query="select distinct(nodeid), nodename from books where
bookid=1002";
                $result=mysql_query($query);
        $num_results =  mysql_num_rows($result);
      This has worked fine as well. When i hard coded the bookid it works.

                $query="select distinct(nodeid), nodename from books where
bookid=$bookid";
                $result=mysql_query($query);
                $num_results =  mysql_num_rows($result);
      This didn't work because I haven't paid enough attention to the
object-oriented methodology. I  failed because when i pass the variable
bookid as an argument to the pagename (i.e. show_book.php?bookid=1001),  it
is not passing the value inside new the class. So I had to find a way to
pass that vaue into the class so that the new overridding DisplayContent()
function could use it. There are a couple ways to do this, and I have used a
set function. I have created a variable in the new class called $booknum.
Then I wrote a function to set it called SetBooknum. It took an argument and
set the variable $booknum to the argument. then Inside the DisplayContent()
function I have used a variable called $booknumber to correspond to the
bookid column in the table. So it looked like this:

   class testpage extends page_layout
    {
        var $booknum;
         function SetBooknum($num)
        {
                 $this -> booknum = $num;
        }
         function DisplayContent()
        {
           $booknumber= $this -> booknum;
           $query="select distinct(nodeid), nodename from books where
bookid=$booknumber";
         .
         .
         .
       } //end of function DisplayContent()
    } //end of class testpage

 And then after creating the instance of the new class I have just used
SetBooknum() function to pass the bookid variable into the new class and use
it as the search criteria in the query.

   Thanks to all who tried to help me.

Gurhan


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to