Jump to content

Recommended Posts

Hi all

 

I hope you can help me with this one. I managed to get categories in alphabetical order from a database. But I don't know how to integrate everything in the page. I wanted to get the categories by the first letter. Now all the categories are all thrown on a page. I am a beginner and promise to start learning php the proper way. But help me with this one first :D

 

This is my code

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

}

$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 "<br />";
	echo '<a style="text-decoration:none;" href="<?php echo $catlink; ?>"><img src="' . $row['thumb'] . '" /></a>';
	echo $row['catname'];
        echo "<br />";

    }
}

 

And this is where I want to integrate it

// Categories
$sql = "SELECT catid, catname AS catname FROM $t_cats WHERE enabled = '1' $sortcatsql";
$rescats = mysql_query($sql) or die(mysql_error());
$catcount = @mysql_num_rows($rescats);

$percol_short = floor($catcount/$dir_cols);
$percol_long = $percol_short+1;
$longcols = $catcount%$dir_cols;

$i = 0;
$j = 0;
$col = 0;
$thiscolcats = 0;

while($rowcat=mysql_fetch_array($rescats))
{
if ($j >= $thiscolcats)
{
	$col++;
	$thiscolcats = ($col > $longcols) ? $percol_short : $percol_long;
	$j = 0;

	echo "<td valign=\"top\" width=\"$cell_width%\">";
}

$i++;
$j++;

$catname_inurl = RemoveBadURLChars($rowcat['catname']);
if($sef_urls) $catlink = "{$vbasedir}$xcityid/posts/$rowcat[catid]_{$catname_inurl}/0/";
else $catlink = "?view=ads&catid=$rowcat[catid]&cityid=$xcityid&lang=$xlang";

$adcount = 0+$catadcounts[$rowcat['catid']];

?>

<table border="0" cellspacing="0" cellpadding="0" width="100%" class="dir_cat">
<tr>
<?php $category_icon = file_exists("images/category/{$rowcat[catid]}.png") ? "images/category/{$rowcat[catid]}.png" : "images/category.png"; ?>
<th width="25" valign="top"></th>
<th id="main_image"><a style="text-decoration:none;" href="<?php echo $catlink; ?>"><img class="main_image" src="<?php echo $category_icon; ?>" border="0" align="absmiddle"> <?php echo $rowcat['catname']; ?></a>

</th>
</tr>

<?php

 

There is more code ... something to do with sub categories. If needed I will post it all.

 

Thanks

 

 

 

 

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

Yeah ... oops ... forgot that.

 

When the page opens, it opens with the alphabet on top, and the few categories I have underneath. If you press the letter "a" for ex, you ll get all the categories with the letter "a". I would like to have it start with all the "a" categories.

 

http://www.iheartbrooklyn.com

 

Link to comment
https://forums.phpfreaks.com/topic/122619-php-link-help/#findComment-633133
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.