Forum Moderators: coopster

Message Too Old, No Replies

Need some help with a script.

php/mysql script

         

DragonMistress

6:31 am on Dec 18, 2008 (gmt 0)

10+ Year Member



Ok, I'm having a hell of a time with this script(s)...probably just too tired to think straight but need to get it done ASAP...so perhaps someone can give me some assistance, or atleast point me in the right direction.

1. First page will be a multi-select checkbox with about 200 values saved to mysql database. User must click 30 of these.
2. Second page will display the the 30 items from the first page as new checkboxes (and directions) and they can click any number.
3. Third page will display the items checked from the second page as just text, with text boxes next to it (with directions).
4. Last and finally, the user will have a page displayed that shows all other users that match atleast 20 out of the 30 checkbox values from the first page.

Any help will be much appreciated!

[edited by: DragonMistress at 6:32 am (utc) on Dec. 18, 2008]

d40sithui

4:35 pm on Dec 18, 2008 (gmt 0)

10+ Year Member



How is your knowledge of PHP? How are the users in #4. defined? i.e will you use a login system to identify each user or will this be a random internet poll/test of some sort?
It may be difficult for a beginner, but not hard for an average php developer.
In any case, here are my suggestions.
1. To display the ~200 values in a checkbox (which is a lot by the way to display on one page) requires basic mysql select commands and basic php database functions. The important thing here is display the checkboxes with the same name so you can retrieve them easier on your action script. So you probably end up with something like this::

$sql = "SELECT myValue from myTable";
$result = mysql_query($sql);
while($content = mysql_fetch_assoc($result)){
echo "<input type=\"checkbox\" name=\"mySelect[]\" value=\"".$content['myValue']."\">".$content['myValue']."<br>";
}

2.) This page is the action script and will do several things. It will first check to see if 30 values are checked which can be accomplished with a few lines.

$mySelect = $_POST['mySelect'];
//if 30 or more are selected
if(sizeof($mySelect) >= 30){
//display new list
//save first data set to the db
else{
//sends user back to first page
}

I assume that you want to select 30 new and random items from the list one page 1 to display. Is this correct? If so, change the $sql line in #1 to:: "SELECT myValue from myTable order by rand() limit 30"; and use it here.
3.)Retrieve the new selected list and save them as a second data set in the db. Similar logic from page 2.
4.)This where it may get a bit complicated. Idealy, the first and second data set (of this user) would be saved with the same record id. In this way, you will be able to diversify your data and compare them to the other record ids. This is mainly why I asked how your "users" are defined. If your users are all random people, the simple thing to do is generate a unique id for each session and use that as the identifier for your 2 data sets. If you have logins for everyone, just use their user id.

DragonMistress

4:53 pm on Dec 18, 2008 (gmt 0)

10+ Year Member



My knowledge is basic (and for clarification this is for a Joomla extension I'm creating)

I've got the first page and field created (and yes I know 200 is alot, but this is what my clients wants for this ridiculous new request they've made for a stupid simple site).
And I'm able to retreive and display the values from the first field on the second page, just haven't determined how to display them as new checkboxes.
I've also got the third page written now, and I think its correct, but can't test until I get the second page done. haha But I think what you've given me here will help.

But I'm still struggling with that final page. The users have a userid. I want to show each user, which other users "match" 20 or more out of the 30 selected values from page 1.

d40sithui

7:13 pm on Dec 18, 2008 (gmt 0)

10+ Year Member



Showing the 20/30 match can be done. The ease of it will have to be determined by how your tables are set up. Do you have a table for the data set 1 or another for data set 2?

DragonMistress

7:23 pm on Dec 18, 2008 (gmt 0)

10+ Year Member



The data is all in one table. UserID field for each user and cb_traits for first page values.

d40sithui

9:39 pm on Dec 18, 2008 (gmt 0)

10+ Year Member



Does the cb_traits field stores a value that determines if the user has matched the 20/30? If so then you will have it easy =). This would also eliminate the need to store anything in the db prior.

DragonMistress

9:46 pm on Dec 18, 2008 (gmt 0)

10+ Year Member



No it does not.

d40sithui

4:28 pm on Dec 22, 2008 (gmt 0)

10+ Year Member



Then it would make it easier if you have a field that does. Lets call this myField.
->The first page displays the checkboxes - thats pretty basic.
->Second page saves the values checked(from the first page) into a session array or something. Call this $dataSet1[].
->Third page gets and save the data from page 2. Lets call this $dataSet2[]. This is where you would compare to see if the user matched 20 out of 30 in dataSet2 from dataSet1. So, having those arrays, just do a loop

$count = 0;
for($i = 0; $i < sizeof($dataSet2); $i++){
if(in_array($dataSet2[$i], $dataSet1)){
$count++;
}
}
//if count >=20, insert a true/false(1/0) into your field to mark the user successfuling matching 20 out of 30.

If you want to have a more detailed report, it is a bit more involved and will require you to save both arrays in the system and do a more comprehensive loop. But from your description you just want to show other people that completed this.
->Page 4 is the easiest. Just do a "SELECT userName from userTable WHERE myField = 1";