Jump to content

[SOLVED] Sort Data alphabetically after post


StoneGut

Recommended Posts

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

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.