I've searched through what "I think I should be searching for" - but not really understanding or getting anywhere, please could someone point me in the right direction?
I'd like to be able to filter a result set using the th
of one column (region) and although I tried the w3cs tutorial I ended up confusing myself as to "what bit of code goes where" etc and the dropdown form thingie looked very clunky.
This is my example website, myTrader clicking the All Trade Regions link on the left displays as far as I've got & that took me days of cobbling tutorials and guddling about in the dark.
query.php code so far:
<table id="mainTable">
<tr><td width="300" valign="top"><H1>Welcome to myTrader!</H1>
<span class="mainText">Glass & Paper Recycled Commodities Trading Site</span></td>
<td valign="top" align="right"><img src="images/largeLogo.jpg" width="406" height="113" border="0"></td></tr></tab开发者_如何学JAVAle>
<P><span class="paraHeadingOne">All Region Paper Sales</span> </P>
<P>
<table class="dbTable">
<tr>
<tr><th>Commodity</th> <th>Region</th> <th>Member</th> <th>Size</th> <th>Price</th> <th>Date Posted</th>
</tr>
<?php
$link = mysql_connect('localhost', 'palegall', '******');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('palegall_newTrader', $link);
if (!$db_selected) {
die ('cant find newTrader' . mysql_error());
}
$query = mysql_query ("SELECT * FROM `sell` WHERE `commodity`='Paper' ORDER BY `price`") or die( mysql_error() );
$row=mysql_fetch_assoc($query);
do
{
echo'<table class="dbTable">';
echo '<tr><td>'.$row['commodity'].'</td>
<td>'.$row['region'].'</td>
<td>'.$row['member'].'</td>
<td>'.$row['size'].'</td>
<td>'.$row['price'].'</td>
<td>'.$row['posted'].'</td>
</tr>';
}while($row=mysql_fetch_assoc($query));
echo "</table>";
?>
</td></tr></table>
</td></tr></table>
</body></html>
To filter results you need to add WHERE columnName = 'desiredValue'
at the end of the query. Optionally, you can specify several conditions using AND
or OR
, for example:
WHERE columnName = 'possibleValue' OR columnName = 'otherPossibleValue'
I think I know what you mean,
have you tried playing around with the WHERE area of the query. This can change how many results are returned.
I had something similar to this, except it was tagged locations. I had two ideas, first, a table with each column of a tinyint, each one was a certain area. Or the other, where there was just one extra column with space delimited values for specific areas. That was the one I went for and used a query similar to
SELECT * FROM 'items' WHERE `locations` LIKE '% $area %'
as long as there was always a space at the beginning of the string, it was fine at it allowed for multiple options for a single item which didn't take a load of queries to load and lots of memory to sift through the data.
in this case, the data included was
ID Title locations
1 Test 1 blank
2 Test 2 london surrey
When a search was done for just london, then "test 2" was displayed
Hope that helps
精彩评论