PDA

View Full Version : Is there anyway of doing this


wolfe
05-14-2002, 08:34 AM
right first off

in mySQL

i have post id's liek this

1
2
3
4
6
8
9
12

is there anyway of making it go like this

1
2
3
4
5
6
7
8
9
10
11
12

by moving post 6 to the 5 slot and 8 to the 6 slot

1
2
3
4
6
8
9
12

in asending order

so i could add an old DB

Logician
05-14-2002, 09:21 AM
You cant do this while you get the the result with SQL. However after fetching the results, assign them into a array and then you can sort this array in any way you like..

wolfe
05-14-2002, 09:24 AM
what do u mean m8 i aint that good with mySQL

Logician
05-14-2002, 10:13 AM
I meant:

If you are searching for a SELECT SQL query that will do what you asked, no, you cant find.

Instead:

First get your SQL result in the original form with simple SELECT query, ie:

1
2
3
4
6
8
9
12

Assign this result to an array with mysql_fetch_row command..

Now you will have an array like that:
$array[0]=1
$array[1]=2
$array[2]=3
..
$array[4]=6
$array[5]=8
..
$array[7]=12

Now since you have an array, you can do anything you like with this array. Do you want to switch 6 and 8, here you go:
$a=$array[5];
$array[5]=$array[6];
$array[6]=$a;

You'll have:
$array[0]=1
$array[1]=2
$array[2]=3
..
$array[4]=8
$array[5]=6
..
$array[7]=12

See?

wolfe
05-14-2002, 03:42 PM
m8 how do i do it using phpMyAdmin

Logician
05-14-2002, 04:22 PM
wolfe, this is what I'm trying to say: You cant do it via SQL (=PhpMyAdmin). To have such a custom sorted result you need to process your SQL results in a PHP file with PHP and do the sorting there..SQL can only manage basic sortings and custom sortings like you asked.. Hope this helps..

wolfe
05-14-2002, 04:26 PM
so i need to make a php file with the above in ti

Mark Hensler
05-14-2002, 07:42 PM
I think he wants to change the ids for cetain posts so that he can import a previous DB dump.

wolfe
05-14-2002, 08:55 PM
yep thats it

also is there a way of making a import

in another DB

go like this

say the first DB ends @

1342

is there anyway of making the others go from 1342 +