Re: [PHP] reading records alphebetically
You can either select the letter you want through mysql with SELECT * FROM table WHERE name LIKE '$letter%' Or you can select everything: $result = mysql_query(SELECT * FROM table order by name); while ($row = mysql_fetch_array($result)) { extract($row); $first_letter = strtolower($name[0]); } lets say $name = Fred; then $name[0] is set to F; $name[1] is set to r; $name[2] is set toe; and so on... - Original Message - From: Jamie Saunders [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, June 30, 2001 9:29 AM Subject: [PHP] reading records alphebetically Hi, I have a MySQL database set-up containing a few hundred records. I'm trying to make a script that reads the 'name' field of the records and displays only the records of which the name field begins with a specific letter: if ($letter = A) { display all records of which field 'name' beings with A } else if ($letter = B) { ... I'm just starting out on this, so please excuse my ignorance :) Jamie Saunders [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] reading records alphebetically
If you are planning to have a lot of records, you may want to create a column with just that letter and index it, followed by the full name. SELECT name from Table WHERE first_letter = $letter ORDER by name should produce pretty fast results if first_letter, name is indexed. Warren Vail -Original Message- From: Jamie Saunders [mailto:[EMAIL PROTECTED]] Sent: Saturday, June 30, 2001 10:30 AM To: [EMAIL PROTECTED] Subject: [PHP] reading records alphebetically Hi, I have a MySQL database set-up containing a few hundred records. I'm trying to make a script that reads the 'name' field of the records and displays only the records of which the name field begins with a specific letter: if ($letter = A) { display all records of which field 'name' beings with A } else if ($letter = B) { ... I'm just starting out on this, so please excuse my ignorance :) Jamie Saunders [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] reading records alphebetically
Try using a query like select * from table_name where name like '$letter%'; Julia Quoting Jamie Saunders ([EMAIL PROTECTED]): Hi, I have a MySQL database set-up containing a few hundred records. I'm trying to make a script that reads the 'name' field of the records and displays only the records of which the name field begins with a specific letter: if ($letter = A) { display all records of which field 'name' beings with A } else if ($letter = B) { ... I'm just starting out on this, so please excuse my ignorance :) Jamie Saunders [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- [ Julia Anne Case ] [Ships are safe inside the harbor, ] [Programmer at large] [ but is that what ships are really for.] [ Admining Linux ] [ To thine own self be true. ] [ Windows/WindowsNT ] [ Fair is where you take your cows to be judged. ] PGP signature
Re: [PHP] reading records alphebetically
Since you only have a few records, creating a second index with the first letter doesn't apply to you, but is a good idea in a huge db scheme. The simplest fastest way is to take the suggestions a few people made which is SELECT * FROM table WHERE name LIKE '$letter%' I would not suggest this $result = mysql_query(SELECT * FROM table order by name); while ($row = mysql_fetch_array($result)) { extract($row); $first_letter = strtolower($name[0]); } NOT that it won't work, but you should consider CPU in your design, and you don't want to make the computer go through all the records sequentially to display the valid records. This would take a lot longer to deliver the results in a large file, and would consume more resources... Jack Ethan Schroeder wrote: You can either select the letter you want through mysql with SELECT * FROM table WHERE name LIKE '$letter%' Or you can select everything: $result = mysql_query(SELECT * FROM table order by name); while ($row = mysql_fetch_array($result)) { extract($row); $first_letter = strtolower($name[0]); } lets say $name = Fred; then $name[0] is set to F; $name[1] is set to r; $name[2] is set toe; and so on... - Original Message - From: Jamie Saunders [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, June 30, 2001 9:29 AM Subject: [PHP] reading records alphebetically Hi, I have a MySQL database set-up containing a few hundred records. I'm trying to make a script that reads the 'name' field of the records and displays only the records of which the name field begins with a specific letter: if ($letter = A) { display all records of which field 'name' beings with A } else if ($letter = B) { ... I'm just starting out on this, so please excuse my ignorance :) Jamie Saunders [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- ___ Jack Sasportas Innovative Internet Solutions Phone 305.665.2500 Fax 305.665.2551 www.innovativeinternet.com www.web56.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]