Jump to content

split array up in two parts and swap part A and part B around.


jasonc

Recommended Posts

My query gets the results and orders by one of the fields.

 

Once I get the MySQL results I would like to find the first entry that has a letter as the first character of the same field that the list was ordered by, then split the results in to two parts and swap them.

 

So that the results that have a letter at the start of the same sorted field are as the begining and the results that have the numbers as the start at the end of the array.

 

But also so that the array works the same way as the original results string, so i can use say $results['mysqlfield']

Link to comment
Share on other sites

When I get the results from the following...

SELECT * FROM `products` ORDER BY `productTitle` ASC

 

it returns all results in full alphanumeric order (ascii)  but this causes the entries that start with numbers to be at the start or the results.

 

I have already asked here before to get a query that would reorder it full order numbers first then the letters after.  But this seem like it can not be done as the queries I was given only order by the 'first' letter and not the rest of the text in the row.

 

So opting for a hopefully simpler way by getting mysql to order them correctly in alphanumeric order and then splitting the results in to two parts where the rows start to contain letters and swapping them.

 

i.e.

 

0123

1234

2345

3456

abc

bcd

cde

def

 

then swap so it looks like this...

 

abc

bcd

cde

def

0123

1234

2345

3456

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.