nubble Posted March 12, 2007 Share Posted March 12, 2007 Hey folks - got a new feature I want to add to a page on my site. It's a page that shows all the snakes in our database with a status of "available". I want to be able to filter the record set by price, locality and sex - e.g. available.php?sex=female - which would show only the female snakes, or available.php?price=750 - which would show only those with a price of $750. I am a wicked newbie - have no idea where to even begin. Here's what I've got now. Would appreciate any help or similar code you've used before that I can go from. Thanks! Amy <? $query = "SELECT `snakeID`, `locality`, `sex`, `price`, `status`, `birthyear` FROM `general` WHERE `status` LIKE 'available'"; $result=mysql_query($query); $num=mysql_num_rows($result); $count_to_four = 0; echo "<tr>"; while($row = mysql_fetch_assoc($result)){ $count_to_four++; echo '<td width="25%"><table width="100%" cellpadding="0" cellspacing="10" class="crittergrid"><tr><td width="85" valign="top" ><a href="'; echo $row['snakeID']; echo '.php"><img src="/images/chondros/'; echo $row['snakeID']; echo '_tn.jpg" alt="Green Tree Python for Sale" width="85" height="85" border="0"></a><br><br><b>ID:</b> '; echo $row['snakeID']; echo '<br><b>Sex: </b>'; echo $row['sex']; echo '<br><b>Type: </b>'; echo $row['locality']; echo '<br><b>Price</b>: $'; echo $row['price']; echo '<br><b>Sex:</b> '; echo $row['sex']. '<br />'; echo '<br><br><a href="'; echo $row['snakeID']; echo '"><img src="/images/learn_more.jpg" width="85" height="20" border="0"></a></td></tr></table></td>'; if ($count_to_four == 4) { $count_to_four = 0; echo "</tr><tr>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/42287-crude-search-filter-of-available-animals/ Share on other sites More sharing options...
redarrow Posted March 12, 2007 Share Posted March 12, 2007 add this ok. available.php?sex=female - which would show only the female snakes, or available.php?price=750 <?php $query = "SELECT `snakeID`, `locality`, `sex`, `price`, `status`, `birthyear` FROM `general` WHERE `status` LIKE 'available' and `price`=".$_GET['price']." and `sex`=."$_GET['sex']." "; $result=mysql_query($query); $num=mysql_num_rows($result); ?> Link to comment https://forums.phpfreaks.com/topic/42287-crude-search-filter-of-available-animals/#findComment-205126 Share on other sites More sharing options...
nubble Posted March 12, 2007 Author Share Posted March 12, 2007 You really are a super guru - holy cow man Thanks so much! -Amy Link to comment https://forums.phpfreaks.com/topic/42287-crude-search-filter-of-available-animals/#findComment-205420 Share on other sites More sharing options...
nubble Posted March 12, 2007 Author Share Posted March 12, 2007 OK - this is proving harder to integrate than I thought. Have been fiddling with it for a while. I think it must have something to do with a quote or apostrophe out of order or something. I also tried out a test page using this select statement, which is working just fine http://sprucenubblefarm.com/chondros/filter_old.php $query = "SELECT `snakeID`, `locality`, `sex`, `price`, `status`, `birthyear` FROM `general` WHERE `status` LIKE 'available' and `price`='600' "; When I change the select statement to the one shown below, I just get a white page - no err codes or anything. http://sprucenubblefarm.com/chondros/filter.php Can anyone find the bug in this code? I'm stumped. <?php $query = "SELECT `snakeID`, `locality`, `sex`, `price`, `status`, `birthyear` FROM `general` WHERE `status` LIKE 'available' and `price`=".$_GET['price']." and `sex`=."$_GET['sex'].""; $result=mysql_query($query); $num=mysql_num_rows($result); $j = 0; echo "<tr>"; while($row = mysql_fetch_assoc($result)){ $j++; echo '<td width="25%"><table width="100%" cellpadding="0" cellspacing="10" class="crittergrid"><tr><td width="85" valign="top" ><a href="'; echo $row['snakeID']; echo '.php"><img src="/images/chondros/'; echo $row['snakeID']; echo '_tn.jpg" alt="Green Tree Python for Sale" width="85" height="85" border="0"></a><br><br><b>ID:</b> '; echo $row['snakeID']; echo '<br><b>Sex: </b>'; echo $row['sex']; echo '<br><b>Type: </b>'; echo $row['locality']; echo '<br><b>Price</b>: $'; echo $row['price']; echo '<br><b>Sex:</b> '; echo $row['sex']. '<br />'; echo '<br><br><a href="'; echo $row['snakeID']; echo '"><img src="/images/learn_more.jpg" width="85" height="20" border="0"></a></td></tr></table></td>'; if ($j == 4) { $j = 0; echo "</tr><tr>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/42287-crude-search-filter-of-available-animals/#findComment-205457 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.