TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-15-2009, 12:35 PM   #1 (permalink)
The Wanderer
 
shoaibmunir's Avatar
 
Join Date: Jun 2009
Location: Dubai, UAE
Posts: 23
Thanks: 2
shoaibmunir is on a distinguished road
Help Display Records From Database

I wana show records from database

All data starts with "A" under Alphabet A

All data starts with "B" Under Alphabet B

formate should be minimum 2 column.

Like that exmple i have upload please open below link

http://shoaibmunir.com/talkphp1.htm


i will be please by helping you
__________________
==========================================
http://paysha.com/Pakistan/Sialkot/Profiles/100171.html
==========================================

Last edited by shoaibmunir : 08-15-2009 at 01:20 PM. Reason: for explain
Send a message via MSN to shoaibmunir
shoaibmunir is offline  
Reply With Quote
Old 08-15-2009, 01:33 PM   #2 (permalink)
The Acquainted
 
JaoudeStudios's Avatar
 
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
JaoudeStudios is on a distinguished road
Default

SELECT * FROM tableA WHERE column1 LIKE 'A%'
__________________
JaoudeStudios.com | JaoudeStudios.com Forum | JaoudeStudios.com Blog
OpenSource is the road ahead...!
JaoudeStudios is offline  
Reply With Quote
Old 08-15-2009, 01:38 PM   #3 (permalink)
The Wanderer
 
shoaibmunir's Avatar
 
Join Date: Jun 2009
Location: Dubai, UAE
Posts: 23
Thanks: 2
shoaibmunir is on a distinguished road
Default

thank's for your reply but i want to display all a-z records.

did you check link please check then maybe you will got my point.
__________________
==========================================
http://paysha.com/Pakistan/Sialkot/Profiles/100171.html
==========================================
Send a message via MSN to shoaibmunir
shoaibmunir is offline  
Reply With Quote
Old 08-15-2009, 01:53 PM   #4 (permalink)
The Acquainted
 
JaoudeStudios's Avatar
 
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
JaoudeStudios is on a distinguished road
Default

Well you could run this query 26 times - but I wont recommend it.

You have a few options:
- (MYSQL) You could use a stored procedure
- (MYSQL) Use CASE & CONCAT in mysql
- (PHP) Loop each result and substr the 1st letter and append an array accordingly

The php option is probably the simplest to implement but maybe not the most efficient.
__________________
JaoudeStudios.com | JaoudeStudios.com Forum | JaoudeStudios.com Blog
OpenSource is the road ahead...!
JaoudeStudios is offline  
Reply With Quote
Old 08-15-2009, 01:55 PM   #5 (permalink)
The Wanderer
 
shoaibmunir's Avatar
 
Join Date: Jun 2009
Location: Dubai, UAE
Posts: 23
Thanks: 2
shoaibmunir is on a distinguished road
Default

how can i do can you explain me with write php code?
__________________
==========================================
http://paysha.com/Pakistan/Sialkot/Profiles/100171.html
==========================================
Send a message via MSN to shoaibmunir
shoaibmunir is offline  
Reply With Quote
Old 08-15-2009, 05:59 PM   #6 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

Quote:
Originally Posted by shoaibmunir View Post
how can i do can you explain me with write php code?
PHP Code:
mysql_connect....

$result mysql_query("SELECT * FROM tableA WHERE column1 LIKE 'A%'");

$count mysql_num_rows($result);

for (
$n 0$n $count$n++) {
   
$tmp mysql_fetch_array($resultMYSQL_ASSOC);
   
$ltr substr($tmp['name'], 01);
   
$data[$ltr][$n] = $tmp;

This is oversimplified but it should give you some footing on the problem.
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 08-15-2009, 06:58 PM   #7 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

A query like this should work:
Code:
SELECT 
    name,
    substring(name,1) as first_letter
FROM
    table
WHERE
    [conditions]
ORDER BY 
    name
Sample result (each space separates columns)
Code:
Apple A
Apricot A
Bannana B
Guava G
This will give you each name in alphabetical order and the letter it starts with (so save you some data processing on the script end). There are countless ways to work with this, I'll let you figure which one you want out. But here is one way to sort it into an array (my PHP is very rusty and this is not tested, so look at it as more of a concept):
PHP Code:
<?
foreach($array_results as $x)
{
    
$results[$x["first_letter"][] = $x["name"];

}
?>
Dont run 26 queries for each letter of the alphabet, it will be much much faster to grab all the data in an orderly fashion then work with it once you have it.
__________________

Village Idiot is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use the Singleton design pattern Karl Advanced PHP Programming 27 10-22-2012 08:16 AM
MySQL Database & Model Classes corey Script Giveaway 9 05-16-2009 03:18 AM
[Tutorial] How to organize your classes | Part 1 Tanax Advanced PHP Programming 10 03-01-2009 10:08 PM
Menu Display Problem in IE6+ obolus XHTML, HTML, CSS 14 03-01-2008 07:57 PM
Adding Images to a database from a folder Rendair Advanced PHP Programming 3 01-13-2008 07:40 PM


All times are GMT. The time now is 06:57 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design