Jump to content

Sorting in PHP


dcuellar

Recommended Posts

I'm trying to find a way to organize my shopping cart alphabetically.

http://www.unifiedchamp.com/ucforum/cartplog.php?do=viewcategory&cartplogcatid=1

 

Here is a code within the php script that I noticed had ORDER in it.

 

$cartplog_category_infos = $db->query_read("SELECT catid, title, products
	FROM " . TABLE_PREFIX . "cartplog_categories
	ORDER BY displayorder
");

$cartplog['category_list'] = '';

while ($cartplog_category_info = $db->fetch_array($cartplog_category_infos))
{
	$cartplog['category_catid'] = intval($cartplog_category_info['catid']);
	$cartplog['category_products'] = intval($cartplog_category_info['products']);
	$cartplog['category_title'] = htmlspecialchars_uni($cartplog_category_info['title']);

	eval('$cartplog[\'category_list\'] .= "' . fetch_template('cartplog_category_list') . '";');
}

 

Can this be done?

Link to comment
Share on other sites

Not sure what you are asking for or what you like to do but here is a somthing maybe it might help.

change

ORDER BY displayorder

TO

ORDER BY title ASC

to order it by title (a-z)

OR

ORDER BY title DESC

to order it by title (z-a).

 

 

If this dont help try and look up for MYSQL ORDER BY on google loool and try and make sense of that

PS. oh n remember if you want to change it by product change "title" to "products"

 

PS

 

Link to comment
Share on other sites

I just tried it and it did not work... :(

 

I've included the full PHP script above if you don't mind taking a look at it.

 

I basically want to organize by titles, not by ID numbers. For example, instead of 1, I want it to be sorted by F for Floyd Maywe...

 

Any help with this would be greatly appreciated.

Link to comment
Share on other sites

I imagine it has to be somewhere within this:

 

$cartplog['category_list'] = '';

while ($cartplog_category_info = $db->fetch_array($cartplog_category_infos))
{
	$cartplog['category_catid'] = intval($cartplog_category_info['catid']);
	$cartplog['category_products'] = intval($cartplog_category_info['products']);
	$cartplog['category_title'] = htmlspecialchars_uni($cartplog_category_info['title']);

	eval('$cartplog[\'category_list\'] .= "' . fetch_template('cartplog_category_list') . '";');
}

$db->free_result($cartplog_category_infos);

 

But I don't see where.

Link to comment
Share on other sites

I wasnt having a go at you mate just said that so i was clear :)

find this file.on your server.

 

cartplog.php

 

and look for "ORDER BY catid"

 

if you find that then change it to "ORDER BY title"

 

hope it helps

 

also on cartplog.php look for include() function coz they may have included other pages.

Link to comment
Share on other sites

ok i think i found it not sure thought if not just check and let me know i have another look

 

replace

if ($_REQUEST['do'] == 'viewcategory')
{
$vbulletin->input->clean_array_gpc('r', array(
	'cartplogcatid' => TYPE_UINT,
));
$cartplog['categoryid'] = $vbulletin->GPC['cartplogcatid'];

$cartplog_product_infos = $db->query_read("SELECT productid, thumb, title, price
	FROM " . TABLE_PREFIX . "cartplog_products
	WHERE catid = " . intval($cartplog['categoryid']) . " 

 

 

with

if ($_REQUEST['do'] == 'viewcategory')
{
$vbulletin->input->clean_array_gpc('r', array(
	'cartplogcatid' => TYPE_UINT,
));
$cartplog['categoryid'] = $vbulletin->GPC['cartplogcatid'];

$cartplog_product_infos = $db->query_read("SELECT productid, thumb, title, price
	FROM " . TABLE_PREFIX . "cartplog_products
	WHERE catid = " . intval($cartplog['categoryid']) . " ORDER BY title ASC

 

Just add ORDER BY title ASC at the end that is the difference

Link to comment
Share on other sites

my website is shit loool n that was a minor thing but ermm i can't do that optional thing because that is a very advanced and complicated code that it wud take me a while to understand it.

 

and i would have done it if it was my web loool its coz i need to test it a few times to make sure it works try out different things loool :D

Link to comment
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.