Scooby08 Posted August 21, 2008 Share Posted August 21, 2008 I found a simple snipplet online for a database A to Z search by name and am having troubles understanding what's going on with the do/while section.. Here is the code I'm using: <?php $sort = $_REQUEST['letter']; if($sort = "") { $query = "SELECT * FROM dw_customers ORDER BY customer_bride ASC" ; } else { $query = "SELECT * FROM dw_customers WHERE customer_bride LIKE '$sort%' ORDER BY customer_bride ASC" ; } $result = mysql_query($query) or die(mysql_error()); for ($i = 65; $i < 91; $i++) { printf('<a href = "%s?letter=%s">%s</a> | ', $PHP_SELF, chr($i), chr($i)); } echo "</p>" ; if (mysql_num_rows($result) > 0) { do { echo "<p>" .$row['customer_bride']. "</p>" ; } while ($row = mysql_fetch_assoc($result)); } else { echo "<p>No customer found.</p>" ; } ?> Everything seems to work fine except for when I click a letter that is not in my database, I cannot seem to get to the else { echo "<p>No customer found.</p>"; } Can somebody help me to understand why I cannot get that to echo?? Quote Link to comment https://forums.phpfreaks.com/topic/120746-solved-a-to-z-search-help/ Share on other sites More sharing options...
adam84 Posted August 21, 2008 Share Posted August 21, 2008 Maybe try something like this..... if($sort = "") { $query = "SELECT * FROM dw_customers ORDER BY customer_bride ASC" ; } else { $query = "SELECT * FROM dw_customers WHERE SUBSTRING(customer_bride,1) = '$sort' ORDER BY customer_bride ASC" ; } Quote Link to comment https://forums.phpfreaks.com/topic/120746-solved-a-to-z-search-help/#findComment-622300 Share on other sites More sharing options...
Zane Posted August 21, 2008 Share Posted August 21, 2008 change this line if($sort = "") { to this if($sort == "") { One equal sign is an assignment....meaning it forces it to equal.... nothing. Two equal signs are a comparison...meaning it compares it against....nothing. And then there is === Which is a really strict comparison...usually for true and false comparisons That's the most basic description I can come up with Quote Link to comment https://forums.phpfreaks.com/topic/120746-solved-a-to-z-search-help/#findComment-622301 Share on other sites More sharing options...
Scooby08 Posted August 21, 2008 Author Share Posted August 21, 2008 Ha!! It was the double == This code must be for an older version of php possibly?? Anyways, Thanks you guys for the input!! Quote Link to comment https://forums.phpfreaks.com/topic/120746-solved-a-to-z-search-help/#findComment-622305 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.