Alphabetical problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
trustedfitness
Forum Newbie
Posts: 2
Joined: Thu Feb 16, 2012 6:49 am

Alphabetical problem

Post by trustedfitness »

Hi all

I've got an issue with items not listing alphabetically, i've tried various methods but have no joy, could someone give me an idea of what i'm doing wrong....


I'm trying to align product names alphabetically, but seem to only be able to get the brand names alphabetically...... :help: :help:

(our freelancer is off so am having to fix this along with some other issues myself = wet behind the ears!)



Here is the table i'm trying to alphabetically order:

<table width="940px" border="0" cellspacing="5" cellpadding="5">
<tr><td valign=top style="margin-left:10px" width="160px">
<?
$qry="select p.*,c.cat_name,c.cat_id ccat_id,b.brand_name,b.brand_id bbrand_id from product_master p,brand_master b,category_master c where p.cat_id = c.cat_id and p.brand_id = b.brand_id and p.cat_id = '".$_GET['pid']."' order by b.brand_name" ;
$query = mysql_query ($qry) or die ("Error : " . mysql_error());


$i=1;
$brk=0;
$last_brd=0;
$brook=0;
while($row = mysql_fetch_array($query))
{

if($i%$per_col_cnt == 1 && $i!=1 )
{
$brk=1;
}



if($brk==1 && $last_brd != $row['brand_id'])
{
echo '</td><td valign=top width="160px">';
$brk=0;
$brook=1;
}




if($last_brd==0 || $last_brd != $row['brand_id'])
{

if($brook==1 || $last_brd == 0)
echo "<a style='text-decoration:none' href=brand_listing.php?pid=".$row['brand_id']."><u><b><font color=blue style='font-size:13px'>".$row['brand_name']."</font></u></b></a>\n";
else
echo "<br><br><a style='text-decoration:none' href=brand_listing.php?pid=".$row['brand_id']."><u><b><font color=blue style='font-size:13px'>".$row['brand_name']."</a></b></font></u>\n";
$brook=0;
$last_brd=$row['brand_id'];

}


echo "<br><a style='text-decoration:none' href=offer_listing.php?pid=".$row['product_id']."><u><font style='font-size:11px' color=DimGray>".$row['product_name']."</u></font></a>\n";
$i++;


}
?>
</tD>

</tr>
</table>



ANY advice or help is greatly appreciated!
User avatar
theserve
Forum Newbie
Posts: 24
Joined: Wed Jan 18, 2012 6:35 am
Location: London

Re: Alphabetical problem

Post by theserve »

you need to add a second order by clause to your statement.

order by b.brand_name, p.product_name;

that's if the product name is in a field called product_name.
trustedfitness
Forum Newbie
Posts: 2
Joined: Thu Feb 16, 2012 6:49 am

Re: Alphabetical problem

Post by trustedfitness »

THANK YOU, greatly appreciated!!!!! :-)
Post Reply