Jump to content


Photo

#ing in order on click


  • Please log in to reply
13 replies to this topic

#1 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 21 April 2006 - 12:38 AM

well i need a query that #'s a members products ion order from 1-2-3....
my tables look like this
Members:
Username      email       password
____________________________
saad           --------       -----------
darkness     --------       -----------

Products:

Product     slot      id          owner
___________________________
........        1        ..         saad
........        3        ..        saad
.........       9        ..         saad
........        1        ..        darkness

what i need to do is update the table so all the products owned by 'saad' are # 1-2-3... in numerical order in the row 'slot' i cant use auto_incretement becaue i only want to # products owned by'saad' and for the other user his products will also start from 1

i can get them to insert by using slot=slot + 1
but the problem is sometimes they get ot of place and some #'s are skipped so if any1 can help me with that id appreciate it alot

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 21 April 2006 - 03:26 AM

Well, you know that you can have a auto-increment that is part of a multi-colum index, right? This allows you to do exactly what you're trying to achieve: ordered groups.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 21 April 2006 - 07:53 PM

[!--quoteo(post=367089:date=Apr 20 2006, 11:26 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Apr 20 2006, 11:26 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Well, you know that you can have a auto-increment that is part of a multi-colum index, right? This allows you to do exactly what you're trying to achieve: ordered groups.
[/quote]

umm not sure how to set that up can you maybe detail a little bit and will it work if like the slots get mixed up the person can just click a link that executed the query and they get reset?

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 21 April 2006 - 08:08 PM

Take a look [a href=\"http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html\" target=\"_blank\"]here[/a] -- this will auto-number.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 21 April 2006 - 11:31 PM

[!--quoteo(post=367293:date=Apr 21 2006, 04:08 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Apr 21 2006, 04:08 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Take a look [a href=\"http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html\" target=\"_blank\"]here[/a] -- this will auto-number.
[/quote]

yea i saw that i know that part but what if the product is exchanged with another user and the slots stay the same how would i do it so it renumbers it self according to the users slots already used

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 22 April 2006 - 06:09 AM

Yeah, that won't happen on it's own. I must ask why you need to store this slot number -- are you actually using this as some sort of sortorder? If so, they don't have to be sequential, they just have to be larger than the previous one.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#7 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 22 April 2006 - 04:19 PM

[!--quoteo(post=367418:date=Apr 22 2006, 02:09 AM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Apr 22 2006, 02:09 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Yeah, that won't happen on it's own. I must ask why you need to store this slot number -- are you actually using this as some sort of sortorder? If so, they don't have to be sequential, they just have to be larger than the previous one.
[/quote]

umm no lol im making my own rpg which kinda uses the same concept but i need slots so they show in order and people can do stuff with them and if they exhange items/product the slot #s reoder for the person starting from one and i can't use auto_incretement because im already using it for ID and i can only have it once in a table i think

any ways i was looking for something more script wise

that counts the users items/products and than #'s the slots

you probably wont get what i mean but try checking out the website you might get what i mean

[a href=\"http://Http://tpfmail.byethost32.com\" target=\"_blank\"]Http://tpfmail.byethost32.com[/a]

login info:
username:guest
password:guest

umm and i have 1 more question but i prefere talkiing using MSN IM if you do have an account plzz. add me pakiboi44@hotmail.com

#8 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 22 April 2006 - 05:18 PM

Let's keep the discussion to the forums so other can contribute.

All I meant was that if you're generating a sequence, you can do this "on the way out" -- no need to store it and maintain it constantly in the DB. However, if this is a "sortorder", where you're showing a list that the user can sort, and you want to maintain this order across "sessions", then you will need to store it. Though if this is the case, you'd be saving it every time anyway, and you wouldn't have a problem.

Does this make sense?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#9 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 22 April 2006 - 05:43 PM

[!--quoteo(post=367489:date=Apr 22 2006, 01:18 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Apr 22 2006, 01:18 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Let's keep the discussion to the forums so other can contribute.

All I meant was that if you're generating a sequence, you can do this "on the way out" -- no need to store it and maintain it constantly in the DB. However, if this is a "sortorder", where you're showing a list that the user can sort, and you want to maintain this order across "sessions", then you will need to store it. Though if this is the case, you'd be saving it every time anyway, and you wouldn't have a problem.

Does this make sense?
[/quote]

umm makes sense but this is whats happening right now

All creatures have slots
you can carry a max of 6 at a time
the 6 you creatures with slots(1,2,3,4,5,6)
But than you can change creatures which you want to carry i have made a query for that which just switches the slots
but than there is trading you can trade your creatures for others so this is where it gets messed up when u trade the slots are not in order anymore so you're data doesnt get stored properly and cant be viewed properly

so what i was looking for is something that will
after trading
renumber all of the users creatures from 1-(total creatures)

( i am using creatures to make it sound like what im using it for)

#10 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 22 April 2006 - 06:13 PM

I understand. You can definitely issue a query that will renumber them; I guess my question is why you are numbering them to begin with. You can enforce for maximum of 6 slots in your app logic -- why have the slot number stored at all?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#11 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 22 April 2006 - 06:33 PM

[!--quoteo(post=367500:date=Apr 22 2006, 02:13 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Apr 22 2006, 02:13 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I understand. You can definitely issue a query that will renumber them; I guess my question is why you are numbering them to begin with. You can enforce for maximum of 6 slots in your app logic -- why have the slot number stored at all?
[/quote]

because users can have alot of creatures like 1000 and if they want to change the carried ones they can switch the slots and there is some other stuff they will need them for like battle i can't explain everything lol

#12 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 22 April 2006 - 10:01 PM

Still... you can use a flag to mark the ones that are currently "active", instead of playing this renumbering game.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#13 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 22 April 2006 - 10:30 PM

[!--quoteo(post=367527:date=Apr 22 2006, 06:01 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Apr 22 2006, 06:01 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Still... you can use a flag to mark the ones that are currently "active", instead of playing this renumbering game.
[/quote]

umm true but accept you dont recieve all you're creatures at signup you have to catch so it wouldnt work with marking using flags so id much rather prefere renumbering do u have any idea how i can acheieve this?

o and im having trouble with making a query that fetches a row and if the row doesnt exsist it echos "none" it's used for a picture so if the result is not found it shows a default picture named none and if it is found it shows the result

#14 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 23 April 2006 - 07:47 AM

You can do this with a few user variables and an UPDATE statement. As far as handing "missing" pictures, a proper LEFT JOIN will return nulls for missing records, and your app should be able to handle this quite easily.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users