Member Avatar

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???

Recommended Answers

Hi,

Do you have naming conventions for this text files?

Regards,
Al

Jump to Post

I meant how do you name this text files?

Jump to Post

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 …

Jump to Post

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.

Jump to Post

oh sorry, please see updated post above.

please replace, joomla for your folder name.

Jump to Post

All 17 Replies

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

Member Avatar

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..

So what are you using for your backend???

Member Avatar

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..

Hi,

Do you have naming conventions for this text files?

Regards,
Al

Member Avatar

Hi,

Do you have naming conventions for this text files?

Regards,
Al

naming conventions?? What's that??

I meant how do you name this text files?

Member Avatar

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).

Member Avatar

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..

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

Member Avatar

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..

oh sorry, please see updated post above.

please replace, joomla for your folder name.

Member Avatar

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 <a href=mysite.com/country/$file>
That $file is the directory which he has fond on the country directory..

Yes,

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

Yes,

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

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

Member Avatar

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 ....

Member Avatar

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???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.