Jump to content

Recommended Posts

I know very very little php. But I have nobody that can help me with this, so I hope somebody here will.

 

I need to create something like this http://www.ghanaweb.com/GhanaHomePage/directory/alphabet.php?L=C

 

If a user clicks on letter A he/she gets all the categories that start with the letter A and so on. All I got so far is this:

 

$result = mysql_query("SELECT * FROM xzclf_cats WHERE catname LIKE 'A%' ORDER BY catname ASC");

 

while($row = mysql_fetch_assoc($result)){

  echo $row['catname'];

  echo "<br />";

 

}

I saw that I have to start with something like this: $letters = range('A', 'Z');

 

 

I really need help with this one. It needs to go here : http://www.iheartbrooklyn.com

 

And another problem that I have is that the categories don't have fields in the database with images. I would also like to add that. That way when I display the name of the category, it will display the image as well. I added the images through a code that I got from the script's forum. But I forgot which little code it was. Too much shit going on. So please help me out on this one.

 

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/116283-php-help/
Share on other sites

To create your links A through Z use

foreach(range('a', 'z') as $letter)
{
    echo '<a href="?cat=' . strtolower($letter) . '">' . $letter . '</a>';
}

 

Then to show all categories that start with the selected letter, do

$cat = isset($_GET['cat']) ? $_GET['cat'] : null;

if(in_array($cat, range('a', 'z')))
{
    $result = mysql_query("SELECT * FROM xzclf_cats WHERE catname LIKE '$cat%' ORDER BY catname ASC");

    while($row = mysql_fetch_assoc($result))
    {
        echo $row['catname'];
        echo "<br />";
    }
}

Link to comment
https://forums.phpfreaks.com/topic/116283-php-help/#findComment-597931
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.