cip6791 Posted July 23, 2008 Share Posted July 23, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/116283-php-help/ Share on other sites More sharing options...
wildteen88 Posted July 23, 2008 Share Posted July 23, 2008 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 />"; } } Quote Link to comment https://forums.phpfreaks.com/topic/116283-php-help/#findComment-597931 Share on other sites More sharing options...
cip6791 Posted July 23, 2008 Author Share Posted July 23, 2008 Nice ... it worked. Now how do I set up the database to have an image for each category? Can I set up the image path by hand in the database? Quote Link to comment https://forums.phpfreaks.com/topic/116283-php-help/#findComment-597978 Share on other sites More sharing options...
wildteen88 Posted July 23, 2008 Share Posted July 23, 2008 Yes, just set the path to the image for each category in your database. To display the image do something like echo '<img src="' . $row['your_img_col'] . '" />'; in your while loop. Quote Link to comment https://forums.phpfreaks.com/topic/116283-php-help/#findComment-598036 Share on other sites More sharing options...
cip6791 Posted July 24, 2008 Author Share Posted July 24, 2008 so i would have to make a new field in my database? i know how to make the field. but what attributes do i give it? Quote Link to comment https://forums.phpfreaks.com/topic/116283-php-help/#findComment-598217 Share on other sites More sharing options...
MasterACE14 Posted July 24, 2008 Share Posted July 24, 2008 give it varchar(225) that should be fine that for it. varchar is a "string" column type so you can insert the url of the image or whatever. Quote Link to comment https://forums.phpfreaks.com/topic/116283-php-help/#findComment-598252 Share on other sites More sharing options...
cip6791 Posted July 24, 2008 Author Share Posted July 24, 2008 nice ... thank you. I will try it out. Quote Link to comment https://forums.phpfreaks.com/topic/116283-php-help/#findComment-598324 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.