Re: sorting database search results



Hello Soweezy.

Why not you try the *asort()*, which is used to sort an array in
ascending order.
http://in2.php.net/manual/en/function.asort.php
OR
You can also do that, without any function.
in your query...while getting details from database.
Use the ORDER BY clause.
$query = 'SELECT .............. ORDER BY town ASC';

Hope, your problem will be solved.
: )

On Oct 28, 11:45 pm, Soweezy <sowe...@xxxxxxxxx> wrote:
hi

can anyone please help with a sort string ?

I want the results of a search to be sorted by "town" (CF4, CF38, CF39
etc.) but can't figure it out
I've tried using array_multisort() but keep getting inconsistant
length and other error messages
can some kind sole take a look and maybe give me some pointers ?

this is the database...

id|myname|name|contact|town|alttown|fulltime|parttime|raparound|
schoolhours|schoolholidays|weekends|ov ernight|hours|flyingstart|
education|ncma|qan|schools|
2|Jane|Bloggs|www.mywebsiteaddress.co.uk|CF39|Newtown|1|1|1|1|1|1|1|1|
1||1|1|your Primary School|
3|Joe|Schmo|www.anotherwebsiteaddy.co.uk|CF27|Anothertown|1|1|1|1|1|1|
1|1|1|1|1|1|my Primary school|

this is the code...

<table border="0" cellspacing="0" cellpadding="1" align=center
class=black12 width=520>

            <?PHP

// not sure if this bit is relevent or neccessary

$town = ($_GET['town']);
$fulltime = ($_GET['fulltime']);
$parttime = ($_GET['parttime']);
$raparound = ($_GET['raparound']);
$schoolhours = ($_GET['schoolhours']);
$schoolholidays = ($_GET['schoolholidays']);
$weekends = ($_GET['weekends']);
$overnight = ($_GET['overnight']);
$hours = ($_GET['hours']);
$flyingstart = ($_GET['flyingstart']);
$education = ($_GET['education']);
$qan = ($_GET['qan']);
$ncma = ($_GET['ncma']);
$schools = ($_GET['schools']);

$lines = file("/home/rctchi1/data/insomnea");
$i = 0; //create a counter @ 0;
$column = array();
    foreach($lines as $line){
    $fields = explode("|",$line);
    // set this first line as the columns
    if($i == 0){
        foreach($fields as $field){
        $column[] = $field;
        }
    }
    //otherwise set a contact array
    else{
        foreach($fields as $field => $value){
        $contact[$i][$column[$field]] = $value;
        }
    }
    $i++;
    }

$results = array();

$rescount = 0;

// get the results
        foreach($contact as $contact){

//  changed this to if town AND any of the other fields match the
querystring
                if (
                                (($contact['town'] == $town) || $town == 'all')
                                 &&
                                (($contact['fulltime'] & $fulltime) == '1' ||
                                ($contact['parttime'] & $parttime) == '1' ||
                                ($contact['raparound']  & $raparound) == '1' ||
                                ($contact['schoolhours']  & $schoolhours) == '1' ||
                                ($contact['schoolholidays'] & $schoolholidays) == '1' ||
                                ($contact['weekends'] & $weekends) == '1' ||
                                ($contact['overnight'] & $overnight) == '1' ||
                                ($contact['hours'] & $hours) == '1' ||
                                ($contact['flyingstart'] & $flyingstart) == '1' ||
                                ($contact['education'] & $education) == '1' ||
                                ($contact['ncma'] & $ncma) == '1' ||
                                ($contact['qan'] & $qan) == '1'))

// set the array identifier as the contact ID to stop duplicate
records if it finds 2 matches in 1 record

                $results[$contact['id']] = $contact;

                        }

/* not important to the code...

// we now have an array or results that match our query
// Lets see what we have shall we?

        if (($found != '0' && $town != '') &&
                                (
                                $fulltime == '1'
                                ||  $parttime  == '1'
                                ||  $raparound == '1'
                                ||  $schoolhours == '1'
                                ||  $schoolholidays == '1'
                                ||  $weekends == '1'
                                ||  $overnight == '1'
                                ||  $hours == '1'
                                ||  $flyingstart == '1'
                                ||  $education == '1'
                                ||  $ncma == '1'
                                ||  $qan == '1' ))
{

 if ($town != 'all' && $results == '') $newtown  = $town;

 if ($town != 'all' && $results != '') $newtown  = $town;

if ($town == 'all') $newtown  = ' Rhondda Cynon Taff';

echo '<tr><td align=center colspan=4 height=36 valign=middle
bgcolor=#f6f6f6>Childminders in '; echo $newtown; echo ' who
<br>provide some or all of the selected services...</td></tr><tr><td
bgcolor=#f0f0f0 colspan=4 height=2 class=white6></td></tr>';

}

*/

foreach($results as $result)
{

// show results formated in tables...

$isin = 'in ' .$result['alttown'].', '.$result['town'];

// changed this to the format it would be once it's working fully

 echo '
 <tr><td align=left colspan=3 bgcolor=#fafafa width=90%><strong>'.
$result['name'].'</strong> '.$isin.'</td><td bgcolor=#fafafa
align=right>';

$con = $result['contact'];

// =======================================================

// a href link to info page

echo '(<a href="javascript:popUp(\'info.php?name='.
$result['name'].'&contact='; echo $con; echo '&alttown='.
$result['alttown'].'&fulltime='.$result['fulltime'].'&parttime='.
$result['parttime'].'&raparound='.$result['raparound'].'&schoolhours='.
$result['schoolhours'].'&schoolholidays='.
$result['schoolholidays'].'&weekends='.
$result['weekends'].'&overnight='.$result['overnight'].'&hours='.
$result['hours'].'&flyingstart='.$result['flyingstart'].'&education='..
$result['education'].'&ncma='.$result['ncma'].'&qan='.
$result['qan'].'&schools='.$result['schools'].'\')">info</a>)';

//========================================================

echo '</td></tr><tr><td bgcolor=#f0f0f0 colspan=4 height=2
class=white6></td></tr>';

}

//  code if no results...

                                if (($town != '') &&
                                (
                                $fulltime == ''
                                &&  $parttime  == ''
                                &&  $raparound == ''
                                &&  $schoolhours == ''
                                &&  $schoolholidays == ''
                                &&  $weekends == ''
                                &&  $overnight == ''
                                &&  $hours == ''
                                &&  $flyingstart == ''
                                &&  $education == ''
                                &&  $ncma == ''
                                &&  $qan == '' ))

                                                                {
                                echo "<tr><td align=center colspan=3><p>You must select at least 1
service.</p></td></tr>";
                                }

                                if (($result == '' && $town != '')  &&
                                (
                                $fulltime == '1'
                                ||  $parttime  == '1'
                                ||  $raparound == '1'
                                ||  $schoolhours == '1'
                                ||  $schoolholidays == '1'
                                ||  $weekends == '1'
                                ||  $overnight == '1'
                                ||  $hours == '1'
                                ||  $flyingstart == '1'
                                ||  $education == '1'
                                ||  $ncma == '1'
                                ||  $qan == '1' ))
                                {
                                echo "<tr><td align=left colspan=3><p class=red12>We do not have a
childminder listed, in $town, who offer those services. <br>
                                                                                                                Please try a different post code near to you or select
\"All Post Codes\"</p></td></tr><tr><td bgcolor=#f0f0f0 colspan=3
height=2 class=white6></td></tr>";
                                }

?>

 </table>

thanks for any help

.



Relevant Pages