Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 13th, 2004, 01:43 PM
Authorized User
 
Join Date: Jan 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ashleek007
Default SQL help??

ive got a web page where i want to display records from my SQL database in alphabetical categories.

I select a letter from a drop down menu, click find records and then a list of records begining with the chosen letter are displayed.

does anyone kno the SQL code i need to use to get this information

so far ive got

$letter = $_POST['letter'];
$query = "SELECT * FROM dbname WHERE name LIKE '[$letter]'";

any ideas
Thanks
ASH:D

__________________
My new web design domain
www.askmultimedia.co.uk
 
Old September 13th, 2004, 03:06 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

You're very close.
Code:
$query = "SELECT * FROM dbname WHERE name LIKE '[$letter]%'";
You want the wildcard character after the variable for the letter to signify that the field must begin with the character. Then you'd want to append an ORDER BY clause.
Code:
$query = "SELECT * FROM dbname WHERE name LIKE '[$letter]%' ORDER BY name ASC";
HTH!

Regards,
Rich

--
[http://www.smilingsouls.net]
[http://pear.php.net/Mail_IMAP] A PHP/C-Client/PEAR solution for webmail





Similar Threads
Thread Thread Starter Forum Replies Last Post
How Run .sql Script file in MS SQL Server 2000? aarkaycee SQL Server 2000 5 October 12th, 2009 05:43 AM
creating ssis packagte for sql server to sql serer Laxmikant_it ASP.NET 3.5 Professionals 0 November 26th, 2008 12:23 AM
Converting from MS SQL 2005 to Sql Epress edition saif44 SQL Language 0 February 16th, 2007 04:17 PM
Failed to copy objects from SQL server to SQL Serv monfu SQL Server 2000 4 December 4th, 2005 05:54 PM
Move SQL DB from one sql to another sql server Israr SQL Server 2000 3 January 24th, 2005 02:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.