StoneGut Posted July 23, 2008 Share Posted July 23, 2008 I have a page that lists all the users of a site. On the top are the letters A-Z and if the admin clicks on one it filters the result by person with first name of that letter. The code works perfectly to view all members but when I'm looking for a specific member (Right now hard-coded for letter A) I get an error: "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource" I'm guessing the if for loop isn't liking the sql statement for filtering the data? Any help will be greatly appreciated! <?php //If Order Requested then do Filtered Sort: if (!empty($_REQUEST['orderby'])) { $sql = "SELECT * FROM girls WHERE left(stage_name,1) == 'A' "; } else { //If NO Order Request then Display All: $sql = "SELECT * FROM girls ORDER BY stage_name "; } //Starting of Loop to display results $result = mysql_query($sql); for ($i = 0; $i < mysql_num_rows($result); $i++) { $id = mysql_result($result,$i,'id'); $stage_name = stripslashes(mysql_result($result,$i,'stage_name')); $full_name = stripslashes(mysql_result($result,$i,'full_name')); $contact_info = stripslashes(mysql_result($result,$i,'contact_info')); $picture = stripslashes(mysql_result($result,$i,'picture')); $rating = stripslashes(mysql_result($result,$i,'rating')); ?> Quote Link to comment Share on other sites More sharing options...
accident Posted July 23, 2008 Share Posted July 23, 2008 SQL doesnt use == just one = Second of all, doing a command on a column in the where clause is generally a very bad thing,, as it cannot use indexing so it will be very slow (although I suppose if you only have a few dozen rows you won't notice it) but if you are expecting to get hundreds of thousands of rows, this will be very slow Quote Link to comment Share on other sites More sharing options...
StoneGut Posted July 23, 2008 Author Share Posted July 23, 2008 SQL doesnt use == just one = Second of all, doing a command on a column in the where clause is generally a very bad thing,, as it cannot use indexing so it will be very slow (although I suppose if you only have a few dozen rows you won't notice it) but if you are expecting to get hundreds of thousands of rows, this will be very slow Worked! Thanks so much!! The amount of data will be around 200 users - so the WHERE clause being a bit slow isn't too bad I guess. What would you recommend? Thanks again! Quote Link to comment Share on other sites More sharing options...
accident Posted July 23, 2008 Share Posted July 23, 2008 this would be much better $sql = "SELECT * FROM girls WHERE stage_name LIKE 'A%'"; Actually, taking a quick look, it looks like the database optimizes the query to execute as the same as mine. But generally the LIKE statement is a bit better performance wise Quote Link to comment Share on other sites More sharing options...
StoneGut Posted July 23, 2008 Author Share Posted July 23, 2008 Made the adjustments and all working fine. Thanks for your help - talk again soon! Quote Link to comment 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.