Im new in PHP and I have create a table (bookstore) really look like this
no_id | author | id_book | id_topic | quote | comments | no_page
id_book and id_topic have another table eg
table for book :
id_book | book_name
table for topic :
id_topic | topic_name
I made this sql statement for show the output in my system,but my problem is the system show only one output when submit a keyword. even though there are few similar word in the database.
"SELECT a.*, b.book_name
FROM bookstore AS a
LEFT JOIN book AS b ON a.id_book=b.id_book
WHERE quote LIKE '%".
can anyone help me how to show all match quote? i am so confuse *_*
Edit: This is my php code.
$colname_Recordset1 = "-1";
if (isset($_GET['quote'])) {
$colname_Recordset1 = $_GET['quote'];
}
mysql_select_db($database_config, $config);
$query_Recordset1 = "SELECT a.*, b.book_name FROM bookstore a
LEFT OUTER JOIN book b ON a.id_book = b.id_book
WHERE a.quote LIKE '%'". $colname_Recordset1."%%'";
$Recordset1 = mysql_query($query_Recordset1, $config)
or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
I think, if I understand correctly, that your query should be more like:
SELECT a.*, b.book_name
FROM bookstore a
LEFT OUTER JOIN book b ON a.id_book = b.id_book
WHERE a.quote LIKE '%'
If you are still getting a single result (where you know there is more than one result), you need to post the PHP code you are using to extract records from the DB.
You should fetch the result like this, reference http://www.php.net/manual/en/function.mysql-fetch-assoc.php
while ($row = mysql_fetch_assoc($Recordset1)) {
print_r($row);
}
and you should escape the user input with mysql_escape_string
, the full php code
mysql_select_db($database_config, $config);
$filter = '';
if (isset($_GET['quote'])) {
$filter = " WHERE a.quote LIKE '%" . mysql_escape_string($_GET['quote']) . "%'";
}
$result = mysql_query(
"SELECT a.*, b.book_name FROM bookstore a
LEFT OUTER JOIN book b ON a.id_book = b.id_book" . $filter,
$config
) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
// If you need to output table, put the code here
print_r($row);
}