Ok.. hopefully the codesnip isnt too long.. isnt there a simpler way of doing this?
moduleslt = mainmenu,L,Mx,2,search,L,Mx,1,recomus,L,Mx,5,randqt,L,Mx,6,pgnplls,L,Mx,4,spotlt,L,Mx,3
modulesrt = memmen,R,Mx,2,onlnnw,R,Mx,1,memstat,R,Mx,4,shtbx,R,Mx,3,news1,R,Mx,6,mnphs,R,Mx,5
format of variables is:
module name, column, state, module position
The goal is simply to turn this into a multidimensional array and then sort if by the module position... To be displayed in the order specified, later.
The code I've come up with just seems to me to be a round a bout way of doing this.. I would think there is an easier solution, but nothing else I try is working...
Any suggestions???
// -------------------------------------------------------------
// Functions
// -------------------------------------------------------------
function array_csort(&$arr, $column=0, $order='asc') {
$order = ($order == 'asc') ? SORT_ASC : SORT_DESC;
foreach ($arr as $a) {
$keys = array_keys($a);
$sortarr[] = $a[$keys[$column]];
}
array_multisort(&$sortarr, $order, &$arr, $order);
} // array_csort
// -------------------------------------------------------------
// get strings from db
// -------------------------------------------------------------
$results=$db->get_results("Select * FROM gpn_users WHERE username like 'CDXRevVveD'");
$results1=$db->get_results("Select * FROM gpn_modules");
// -------------------------------------------------------------
// explode them
// -------------------------------------------------------------
foreach($results as $result)
{
$xltresult=explode(",", $result->moduleslt);
$xrtresult=explode(",", $result->modulesrt);
}
// -------------------------------------------------------------
// convert to a multidimensional array
// -------------------------------------------------------------
$count=0;
$modcnt=0;
foreach($xltresult as $result)
{
$modlistarrlt[$modcnt][$count]=$result;
if($count<3)
{
$count++;
}
else
{
$count=0;
$modcnt++;
}
}
$count=0;
$modcnt=0;
foreach($xrtresult as $result)
{
$modlistarrrt[$modcnt][$count]=$result;
if($count<3)
{
$count++;
}
else
{
$count=0;
$modcnt++;
}
}
// -------------------------------------------------------------
// Sort them by column 3, Module Position
// -------------------------------------------------------------
array_csort(&$modlistarrlt, $column=3, $order='asc');
array_csort(&$modlistarrrt, $column=3, $order='asc');
// -------------------------------------------------------------
// Display them in correct order
// -------------------------------------------------------------
$modcnt1=count($modlistarrlt);
echo "Displaying Left Column Modules: <BR><BR>";
for($x=0; $x<($modcnt1); $x++)
{
echo "Module Name:";
echo $modlistarrlt[$x][0];
echo "<BR>";
echo "Module Column:";
echo $modlistarrlt[$x][1];
echo "<BR>";
echo "Module Status:";
echo $modlistarrlt[$x][2];
echo "<BR>";
echo "Module Position:";
echo $modlistarrlt[$x][3];
echo "<BR><br>";
}
$modcnt1=count($modlistarrrt);
echo "<BR><hr><BR>Displaying Right Column Modules: <BR><BR>";
for($x=0; $x<($modcnt1); $x++)
{
echo "Module Name:";
echo $modlistarrrt[$x][0];
echo "<BR>";
echo "Module Column:";
echo $modlistarrrt[$x][1];
echo "<BR>";
echo "Module Status:";
echo $modlistarrrt[$x][2];
echo "<BR>";
echo "Module Position:";
echo $modlistarrrt[$x][3];
echo "<BR><br>";
}
Suggestions for condensation appreciated.... 😉