0

Let´s say i perform a query like this:

$charsnamequery = mysql_query("SELECT * FROM 'bookstable' WHERE 'bookcharactersname' = 'JHON'")

This will give back a resource that i then put in an array and use to print the results like this:

while ( $fullist = mysql_fetch_array( $charsnamequery ))
{ Print "book title: ".$fullist['id_book'] . ", book author:".$fullist['book_author'] . "
.....etc etc etc";
 }

So, lets say that now i want to do is: Search on my database for customers who have showed interest in any of those id_book in the past and gather their emails.

I know i am suposed to reformat the array in someway so that i can do a new query like:

$newquery = mysql_query("SELECT 'email' FROM 'customerstable' WHERE 'id_book_interested_in' IN ($value1,$value2,$value3....etc etc etc)"

Hope you can give me a hand with this! Thanks you in advance!

PS: I rather not join the querys even if it were possible for im trying to learn step by step.-

Khul
  • 19
  • 1
  • 1
  • 8
  • 1
    [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](http://j.mp/XqV7Lp). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. – Kermit Apr 15 '13 at 03:02
  • Thanks for the pointers! I did not know that! I guess i have been reading old tutorials =/ – Khul Apr 15 '13 at 03:54

1 Answers1

1

The reason why the query is not working is because you are wrapping the table name as well as column name with single quote.

SELECT * FROM bookstable WHERE bookcharactersname = 'JHON'

These are identifiers and not string literals. In this case, backticks are optional since non of them are reserved keywords.

Community
  • 1
  • 1
John Woo
  • 258,903
  • 69
  • 498
  • 492
  • Thanks for the info. I guess i just wrote it down badly while posting the question. My actual issue it with getting the "SOMEWAY" (highlighted on the text) done. That is the step i do not know how to perfom – Khul Apr 15 '13 at 03:56