Forum Moderators: coopster

Message Too Old, No Replies

PHP and Mysql problem

Select from where not fetching results

         

dskaushik5

8:32 pm on Apr 2, 2003 (gmt 0)

10+ Year Member



hi
this is the code i have

$query = "SELECT B.bookCategory,B.bookAuthor,B.bookTitle,B.bookISBN,B.bookPrice,B.bookContact,B.bookRate FROM books B WHERE B.bookCategory = 'Antropology' ";

$result = mysql_query($query) or die("The query has failed");

and this is the corresponding HTML

while ($line = mysql_fetch_array($result))

{
print"

<tr>
<td width=\"14%\">$line[bookCategory]</td>
<td width=\"14%\">$line[bookAuthor]</td>
<td width=\"14%\">$line[bookTitle]</td>
<td width=\"14%\">$line[bookISBN]</td>
<td width=\"14%\">$line[bookPrice]</td>
<td width=\"15%\">$line[bookContact]</td>
<td width=\"15%\">$line[bookRate]</td>
</tr>

In my database i have category Antropology but still its not pulling the results.

Any suggestions.
thanks
Deepak

jatar_k

8:48 pm on Apr 2, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



why not try a simpler version to start.

select * from books where bookCategory = 'Antropology'

make sure the fieldnames and tablenames are exact (spelling and case)

DrDoc

9:10 pm on Apr 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is "books" the name of the database, and "B" the table name?

If so, do this:

$query = "SELECT bookCategory,bookAuthor,bookTitle,bookISBN,bookPrice,bookContact,bookRate FROM B WHERE bookCategory = 'Antropology' ";

WebJoe

9:24 pm on Apr 2, 2003 (gmt 0)

10+ Year Member



dskaushik5, why are you using the alias (B)? From my experience, it makes debugging a lot harder and I wouldn't use it unless absolutely necessary (i.e. you want two instances of the same tabel). So your code qould look like this:

$query = "SELECT bookCategory, bookAuthor, bookTitle, bookISBN, bookPrice, bookContact, bookRate FROM books WHERE bookCategory = 'Antropology' ";

or, to use full reference names in case you want to join other tables with the same fieldnames:


$query = "SELECT books.bookCategory, books.bookAuthor, books.bookTitle, books.bookISBN, books.bookPrice, books.bookContact, books.bookRate FROM books WHERE bookCategory = 'Antropology' ";