Displaying db records using pre-defined order

I have programmatically defined an order to display records from the db which I have in an array:

Array
(
[repair_id] => Array
(
[0] => 26
[1] => 21
)
)

Of course, when the records are retrieved, they appear in order (21,26):

stdClass Object
(
[repair_id] => 21
[db_date] => 0000-00-00
[location] => IN-HOUSE
[repair_name] => PRESSURE TEST
[part_nomenclature] => INLET CASE
[description] => Pressure test internal tubing per Engine Manual 72-72-72
Ok
)

stdClass Object
(
[repair_id] => 26
[db_date] => 0000-00-00
[location] => IN-HOUSE
[repair_name] => PRESSURE TEST
[part_nomenclature] => INLET CASE
[description] => Pressure test IAW 72-72-72
)
How do I couple the two arrays so that the records are displayed using the defined order (26,21) after being retrieved from the db? I’ve been beating my head against the wall for days, any help is greatly appreciated.

What you are showing are Objects not Arrays. Though it is easy to go back and forth from arrays to objects (or vise verse). Show the code that you have and I am sure someone will be able to help you out. We don’t know if you pulling from the database objects or arrays then converting to objects (Records) though my guess is you’re pulling in records.

Here is the form. I’m pulling all of the records and displaying each with an additional field (sel_id) so that the user can select the order in which they apear.

[php]$STH = DB::getInstance()->query(“SELECT * FROM repairs WHERE part_nomenclature LIKE ‘%$_POST[part_name]%’” );

foreach($STH->results() as $STH){
    $des = nl2br($STH->description); 
    $des =  htmlspecialchars_decode($STH->description,ENT_HTML5 | ENT_QUOTES);

echo “”;
echo "


Select Sequence
Repair ID:$STH->repair_id
Part Nomenclature:
Repair Name:

Location:
Description: $des
"; } echo " [/php]

Im using this to rearrange the order of the array:
[php]array_multisort($_POST[‘sel_id’], $_POST[‘repair_id’], $_POST[‘part_nomenclature’], $_POST[‘repair_name’],
$_POST[‘location’], $_POST[‘description’]);
[/php]
The sorted data appears as so:

[php]
Array
(
[sel_id] => Array
(
[0] => 1
[1] => 2
)

[repair_id] => Array
    (
        [0] => 26
        [1] => 21
    )

[part_nomenclature] => Array
    (
        [0] => INLET CASE
        [1] => INLET CASE
    )

[repair_name] => Array
    (
        [0] => PRESSURE TEST
        [1] => PRESSURE TEST
    )

[location] => Array
    (
        [0] => IN-HOUSE
        [1] => IN-HOUSE
    )

[description] => Array
    (
        [0] => Pressure test IAW 72-72-72
        [1] => Pressure test internal tubing per Engine Manual 72-72-72

Ok
)

)
[/php]

I need to display the above data sequenced by sel_id (1 , 2). Note the repair_id sequence is (26 , 21).

Something like
[php]
array( array(
[sel_id] => 1,
[repair_id] => 26,
[part_nomenclature] => INLET CASE,
[repair_name] => PRESSURE TEST,
[location] => IN HOUSE,
[description] => Pressure test IAW 72-72-72
)
array(
[sel_id] => 2,
[repair_id] => 21,
[part_nomenclature] => INLET CASE,
[repair_name] => PRESSURE TEST,
[location] => IN HOUSE,
[description] => Pressure test internal tubing per Engine Manual 72-72-72
)
)
[/php]

Lets back up a second… ???

Is it possible to represent an array inline like:

[php]

Array
(
[sel_id] => Array
(
[0] => 1
[1] => 2
)

 [repair_id] => Array
     (
         [0] => 26
         [1] => 21
     )

 [part_nomenclature] => Array
     (
         [0] => INLET CASE
         [1] => INLET CASE
     )

 [repair_name] => Array
     (
         [0] => PRESSURE TEST
         [1] => PRESSURE TEST
     )

 [location] => Array
     (
         [0] => IN-HOUSE
         [1] => IN-HOUSE
     )

 [description] => Array
     (
         [0] => Pressure test IAW 72-72-72
         [1] => Pressure test internal tubing per Engine Manual 72-72-72

Ok
)

)

[/php]
Is this possible: $_POST[‘sel_id’][how to represent array / key?][how to represent next ]; ?

I can dig into it with foreach loops easy enough but I’m having a rough time figuring out if I can get it to look like this programmatically.

Sponsor our Newsletter | Privacy Policy | Terms of Service