save data in certain order: NEED ASSISTANCE PLEASE!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

save data in certain order: NEED ASSISTANCE PLEASE!

Post by phphelpme »

Hi, Jason here,

I have my coding below which basically takes id strings from a site that sells products, this data is then saved to a .php file in the following order:

sid, nam, sid, nam, sid, nam, sid, nam etc

This is great because I then load this saved file on another section of my site and explode the data to use in a form. They only issue is I can not figure out how I would give the user an option to select in which order these id's are saved. At the moment they are just save in the way they come from the site. I need to be able to give an option to change the order in which they are save to the file in the way of a form or something.

Maybe, a list of all the ids in a dropdown box, then replicate this dropdown box for the amount of ids there are, then get the user to select the order in which they want them to display. But it would have to take away from the next dropdown list the one that has been selected in the dropdown box before it.

Code: Select all



Any ideas, suggestions of coding or the actual coding to accomplish this would be great, as I know I will prob have to use mySQL to achieve this somehow. Just need some help in getting it to complete this action.

Best wishes,

Jason
Last edited by phphelpme on Tue Nov 23, 2010 8:02 am, edited 1 time in total.
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: save data in certain order: NEED ASSISTANCE PLEASE!

Post by Neilos »

1) Do you know how to access, read and write to a mysql db with php yeah?

2) So you have variables and you just want the user to specify an order for them?

there may well be 1001 ways to do this lol. I don't know which is the best but how do you want it to look like? I'll get thinking about a solution for the list.
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: save data in certain order: NEED ASSISTANCE PLEASE!

Post by Neilos »

Code: Select all

<form name="choices" action="choices.php" method="post">
<select name="choiceOne">
<option value="1">1
<option value="2">2
<option value="3">3
</select>
<select name="choiceTwo">
<option value="1">1
<option value="2">2
<option value="3">3
</select>
<select name="choiceThree">
<option value="1">1
<option value="2">2
<option value="3">3
</select>
<input type="submit" value="Submit" />
</form>
The form might look like
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: save data in certain order: NEED ASSISTANCE PLEASE!

Post by Neilos »

choices.php might look like;

Code: Select all

$choiceOne = $_POST['choiceOne'];
$choiceTwo = $_POST['choiceTwo'];
$choiceThree = $_POST['choiceThree'];

if(($choiceOne == $choiceTwo) || $choiceOne == $choiceThree) || $choiceTwo == $choiceThree)) {
    echo "some choices matched";
} else {
    echo "Order is: " . $choiceOne . " " . $choiceTwo . " " . $choiceThree;

    // You could use the values of $choiceOne etc to assign indexes in an array, remember though 0 = 1 in an array

}
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: save data in certain order: NEED ASSISTANCE PLEASE!

Post by phphelpme »

Hi again, thanks for the info, it looks promising.

The values are stored in the $savedata. The coding takes the values from a website and saves them as $sid and $nam then I use an array to save them to a file.

I agree with what you are saying but the number of values will change everytime, so I can not just say choiceone, choicetwo because I do not know how many there will be. it can vary from say 20 to maybe 200 values for each string.

In other words, each $sid has a $nam value and the total values can mount to say 200 x ($sid $nam)

So not sure how to code it really. I have connected to a database but only know simple queries thats all. SO this is why I am a little taken back by this.

The coding itself grabs the sid and nam then can display them in one long line like; sid, nam, sid, nam, sid, nam and I need them saving like this when the selection process is complete.

I thought about a form but not sure how to setup the database to do it and the coding to perform all the selection options. I am actually a junior programmer who has had to step up the mark because my senior has retired early... SO the pressure is really on... lol
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: save data in certain order: NEED ASSISTANCE PLEASE!

Post by Neilos »

You want users to specify the order of up to 200 separate variables?! Will your users want to do that? Specifying a drop down for each variable is easy even if the number changes. You can use the count function to work out the number of iterations http://php.net/manual/en/function.count.php and a foreach loop for building the form http://php.net/manual/en/control-structures.foreach.php but for 200 variables your users will have a hell of a time, also you would have a tough time for them picking the order and not uing the same number twice, for this you will need some javascript to remove used numbers from the drop down lists.

Why does the order matter? Maybe there is a better solution we're not thinking of.
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: save data in certain order: NEED ASSISTANCE PLEASE!

Post by phphelpme »

Hi again,

Well, I have been thinking long and hard about this situation that has been presented to me. It was a request from other users but now I think after having discussions with yourself that this really is not the best option.

I grab the sid and nam values from a website and they appear in a list exactly how the website displays them. This website can be used to organise them in to groups of five etc. So I am going to suggest they use this account to try organise these products in a certain way so that when my coding grabs the ideas they will apear in the way they have selected on the account.

This way they only have to change the order once, and are not faced with the mammoth task of assigning a position value to each and every sid, nam variable. lol

I agree with your statement that users will eventually get fustrated with this process even though they are the onces that have requested this. It is part of my job to make sure any system I build is user friendly and reduces time required to set things up. So I believe that this request is not in the best interest of the users.

So right now I am changing an account where the ids come from into a set number of groups (although it is very limited), then extracting these values with my coding and it seems to be fine really. Not much work involved for the user which is the most important aspect surely.

Thank you for your advice on this issue I was having. lol I have made you a friend on this forum and I will certainly be keeping in contact with you neilos.

Best wishes,

Jason
Post Reply