954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

From a complete list how to show index wise A,B,C,D,....

I have a complete list of a topics.
I have to create a Index for A B C D E ...
On Clicking those buttons without navigating to another page it shows only topics wich starts from that letter...
How to code it in php???

kirtan_thakkar
Junior Poster in Training
79 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

suppose your page is post.php
So for A button link should be http://doimain.com/post.php?start=a

So your query will be dynamic like below:

<?php
if(isset($_GET['start']))
{
    $sql ="select * from table name WHERE name LIKE '".$_GET['start']."%'";
}
else
{
   $sql="select * from table";
}
?>


Hope this helps
Avinash

avinashzala
Newbie Poster
4 posts since Nov 2009
Reputation Points: 9
Solved Threads: 1
 

suppose your page is post.php So for A button link should be http://doimain.com/post.php?start=a

So your query will be dynamic like below:

<?php
if(isset($_GET['start']))
{
    $sql ="select * from table name WHERE name LIKE '".$_GET['start']."%'";
}
else
{
   $sql="select * from table";
}
?>

Hope this helps Avinash

Thanks for the post but i am not using mysql...
Is there any other way to do this..

kirtan_thakkar
Junior Poster in Training
79 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

So what are you using for your backend???

avinashzala
Newbie Poster
4 posts since Nov 2009
Reputation Points: 9
Solved Threads: 1
 
So what are you using for your backend???

I have created text files and using php to open it and show that text into webpage.
There are categories for the topics so I have to create it on the index page..

kirtan_thakkar
Junior Poster in Training
79 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

Hi,

Do you have naming conventions for this text files?

Regards,
Al

ivatanako
Junior Poster
150 posts since Jul 2007
Reputation Points: 18
Solved Threads: 16
 

Hi,

Do you have naming conventions for this text files?

Regards, Al


naming conventions?? What's that??

kirtan_thakkar
Junior Poster in Training
79 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

I meant how do you name this text files?

ivatanako
Junior Poster
150 posts since Jul 2007
Reputation Points: 18
Solved Threads: 16
 

You can have a CSS (style) based system if you're not using a backend (files/DB) of any type. This means that you use php to set a classname on a div. This method isn't advised though because all your data is loaded into the page, but only a particular section (say div B) is visible to the user.

If you don't want to use a DB - an include file system would be your best bet, linked with a querystring ($_GET).

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

You can have a CSS (style) based system if you're not using a backend (files/DB) of any type. This means that you use php to set a classname on a div. This method isn't advised though because all your data is loaded into the page, but only a particular section (say div B) is visible to the user.

If you don't want to use a DB - an include file system would be your best bet, linked with a querystring ($_GET).

I am trying to say tha As if I have list of Countrys As like this:

australia
canada
europe
japan
usa
france
germany
italy
spain
asia
china
mexico
oceania
africa
netherlands
india
switzerland
sweden
singapore
ireland
brazil
england
invisible
austria
parties
belgium
thailand
norway
malaysia
finland
denmark
birthdays
uk
taiwan
college
russia
portugal

And on the page I will put A B C D ..
on clicking on A script should have to show the names which are starting from A...
And also With Hyperlink on it..

kirtan_thakkar
Junior Poster in Training
79 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

Hi,

This should get you started.

<?php
if ($handle = opendir(foldername)) {
    while (false !== ($file = readdir($handle))) {
	if(substr($file,0,1) == $_GET["start"])
		echo $file."\n";
    }

    closedir($handle);
}
?>


Your link should be like this, http://www.website.com/open.php?start=a for letter A.

And change the foldername to your folder.

Regards,
Al

ivatanako
Junior Poster
150 posts since Jul 2007
Reputation Points: 18
Solved Threads: 16
 

Hi,

This should get you started.

<?php
if ($handle = opendir('joomla')) {
    while (false !== ($file = readdir($handle))) {
	if(substr($file,0,1) == "c")
		echo $file."\n";
    }

    closedir($handle);
}
?>

Regards, Al

Oh thanks I have understood...
Thank you so much buddy..

kirtan_thakkar
Junior Poster in Training
79 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

oh sorry, please see updated post above.

please replace, joomla for your folder name.

ivatanako
Junior Poster
150 posts since Jul 2007
Reputation Points: 18
Solved Threads: 16
 

hey..
Is there any way to put a hyperlink on that list like..
After clicking on "A" I got Australia and Austria. Is there any way to put a link on Australia and Austria..
If I have created folders like these..
country > Australia, Austria
And in each folder I have index.php file.
So can I put a link like it
That $file is the directory which he has fond on the country directory..

kirtan_thakkar
Junior Poster in Training
79 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

Yes,

echo "<a href='mysite.com/country/".$file."'>".$file."</a>\n";
ivatanako
Junior Poster
150 posts since Jul 2007
Reputation Points: 18
Solved Threads: 16
 

Yes,

echo "<a href='mysite.com/country/".$file."'>".$file."</a>\n";


Thanks........................

kirtan_thakkar
Junior Poster in Training
79 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

Every one of you are bonkers. I didn't follow a single lime of the last couple of threads. But there again, I'm exceedingly ....

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 
Every one of you are bonkers. I didn't follow a single lime of the last couple of threads. But there again, I'm exceedingly ....

What was that???

kirtan_thakkar
Junior Poster in Training
79 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: