Re: Resource id #2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wednesday 27 November 2002 02:09, The Cossins Fam wrote:
> Hello.
>
> I am using MySQL as a database for a departmental library.  I have written
> a quick search script, but keep getting "resource id #2" as a result to my
> search.  I have read the online documentation for the
> mysql_fetch_array() function and must say, I don't see that I'm missing
> anything.  However, I've only started programming, much less working with
> PHP, so perhaps someone can help me out.  Here's my code:
>
> <?
>
> $quickSearch = "mcse";
>
> $table1 = "Books";
> $table2 = "BookList";
> $table3 = "BoxSet";
> $table4 = "Category";
> $table5 = "Publisher";
> $table6 = "AuthUsers";
> $table7 = "CD";
>
> $connection = mysql_connect("localhost", "root") or die("Couldn't connect
> to the library database.");
>
> $db_select = mysql_select_db("library", $connection) or die("Couldn't
> select the library database.");
>
> $search = "SELECT * FROM $table1 LEFT JOIN $table2 ON Books.BookListID =
> BookList.BookListID
>         LEFT JOIN $table3 ON Books.BoxSetID = BoxSet.BoxSetID
>         LEFT JOIN $table4 ON Books.CategoryID = Category.CategoryID
>         LEFT JOIN $table5 ON Books.PublisherID = Publisher.PublisherID
>         LEFT JOIN $table6 ON Books.auID = AuthUsers.auID
>         LEFT JOIN $table7 ON Books.CD = CD.CD_ID
>         WHERE Books.Title LIKE \"%'$quickSearch'%\"
>         OR Books.Author LIKE \"%'$quickSearch'%\"
>         OR Books.ISBN LIKE \"%'$quickSearch'%\"
>         OR BookList.dbase LIKE \"%'$quickSearch'%\"
>         OR BookList.dbase_user LIKE \"%'$quickSearch'%\"
>         OR BoxSet.BoxSet LIKE \"%'$quickSearch'%\"
>         OR Category.Category LIKE \"%'$quickSearch'%\"
>         OR Category.Sub_category LIKE \"%'$quickSearch'%\"
>         OR Publisher.Publisher LIKE \"%'$quickSearch'%\"";

It's always a good idea to print out your query so you can visually check 
whether it looks OK. So:

  print $search;

> $result = mysql_query($search, $connection) or die("Couldn't search the
> library.");

It's also a good idea to see what really went wrong by using mysql_error(). 
IE:

  if (($result = mysql_query($search, $connection) === FALSE)) {
    print mysql_error();
    die("Couldn't search the library.");
  }


-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *


/*
[Crash programs] fail because they are based on the theory that, with nine
women pregnant, you can get a baby a month.
		-- Wernher von Braun
*/


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux