Jump to content

crude search / filter of available animals


nubble

Recommended Posts

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

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);
?>

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>";
  }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.