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

?>

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

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!

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

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.