0

I have yet another question regarding the randomization of data!

$gender='';
if(isset($_GET['gender'])) {
$gender=$_GET['gender'];
}
$status_array = $_GET['status'];
foreach ($status_array as $one_status) {
$statussource .= $one_status.", ";
$status = substr($statussource, 0, -2);
}
$age_array = $_GET['age'];
foreach ($age_array as $one_age) {
$agesource .= $one_age.", ";
$age = substr($agesource, 0, -2);
}
$incidentid='';
if(isset($_GET['incidentid'])) {
$incidentid=$_GET['incidentid'];
}

mysql_connect ("$host", "$username", "$password") or die ("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="INSERT INTO $tbl_name (given_name, family_name, gender, status, age, incidentid)
select First10.$gender, Last10.family_name,
(SELECT $gender from gender) AS Gender,
(SELECT * FROM status where status = '$status') AS Status,
(SELECT * FROM age where age = '$age') AS Age,
(SELECT $incidentid from incidentid) AS Incident_ID
from ( select fn.$gender, @fns := @fns + 1 as Sequence
from ( select $gender from fnames where $gender IS NOT NULL order by rand() limit 100) fn,
(select @fns := 0 ) vars ) First10
JOIN
( select ln.family_name, @lns := @lns + 1 as Sequence
from ( select family_name from lastnames order by rand() limit 100 ) ln,
(select @lns := 0 ) vars ) Last10
ON First10.Sequence = Last10.Sequence";
$result=mysql_query($sql);
if($result){
echo "Generated Successfully";
echo "<BR>";
echo "<a href='randomdata.php'>Back to main page</a>";
}

else {
echo "ERROR";
}
mysql_free_result($result);
// close connection
mysql_close();

?>

My qualm here is that I am aiming to generate random names with randomized status and age values for the purpose of testing. The checkboxes are in proper format:

<p>
Status: <BR>
<INPUT TYPE=CHECKBOX name="status[]" value="ali">Alive and Well<BR>
<INPUT TYPE=CHECKBOX name="status[]" value="inj">Injured<BR>
<INPUT TYPE=CHECKBOX name="status[]" value="dec">Deceased<BR>
<INPUT TYPE=CHECKBOX name="status[]" value="unk">Unknown<BR>
<INPUT TYPE=CHECKBOX name="status[]" value="fnd">Found<BR>
<INPUT TYPE=CHECKBOX name="status[]" value="mis">Missing<BR>
</p>

<p>
Age: <BR>
<INPUT TYPE=CHECKBOX name="age[]" value="0-17">Youth (0-17)<BR>
<INPUT TYPE=CHECKBOX name="age[]" value="18+">Adult (18+)<BR>
<INPUT TYPE=CHECKBOX name="age[]" value="NULL">Unknown<BR>

However, I can only seem to receive a response for the status and age if only 1 value is selected from the set of checkboxes. I would like to be able to select multiple checkboxes and receive those values in a randomized format. Please advise.

If you need any clarifications on my question, just ask.

1 Answer 1

0

From what I understand, all those values are mutually exclusive. If this is the case, perhaps using a radio button would be more appropriate.

1
  • I originally had a radio button, but that would limit the generation to a single status/age. I was wondering if it is possible to generate test data with a randomized array of statuses/ages. Commented Jul 6, 2011 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.