I have a search function on a site I'm building and would like to have it so that a user can click on a search result to see more columns from that row on the db, if you see what I mean. The best way seems to be to open a new page on which to display more detail on the chosen search result.
The problem is this - when I click through to the new page, all rows on the db are shown i.e. the search is made, result x is returned, click on x and in newpage.php x y and z (i.e. all rows) are displayed.
How do I structure things so that only x (and any other columns from row x that I choose) are displayed?
I'm thinking that I should be able to limit what it displayed with the SELECT but can't seem to find the right syntax to finish it off properly. Currently I have this on newpage.php
I know a little PHP, enough to know where the problem is but not quite enough to solve the problem. I've not found an answer yet after hours of googling!
Any help/guidance/code would be really appreciated.
There's something wrong with the $_GET since it won't echo (and it does on an earlier iteration) - I'll try and get that sorted and hopefully that will sort it out.
try to put ticks around your get variable as well as I assume word in your db is a string.
$variable = '';
$variable = $_GET['w'];
if ($variable != '') {
$query = "SELECT * FROM `pro_words` WHERE `word` = '".$variable."';
} else {
echo "NO VARIABLE PASSED IN";
}
// just an example of at least checking for the value of what $_GET['w'] is before executing a query with it.
that was my next question...
ok, I'm not sure where 'example' is coming from, but I think you need to use 'ticks'
why type of column is 'word' in your database, it is a string, no?
so
$query = "SELECT * FROM pro_words WHERE word = '" . $_GET['w']."'; // add ticks
//the query syntax is expecting a string you have no string defined in your syntax above.