';
if ($gState && $sID) {
// Connect to mySQL
$con = mysql_connect($dbhost, $databaseuser, $databasepass);
if (!$con) {
$text1 = 'Could not connect: '.mysql_error().'
Please enter a valid survey ID.
';
mysql_close($con);
}
// Select the correct db
$db_selected = mysql_select_db($databasename, $con);
if (!$db_selected) {
$text1 = 'Can\'t use '.$databasename.' : '.mysql_error().'
Please enter a valid survey ID.
';
mysql_close($con);
}
$query = 'SELECT * FROM lime_questions WHERE sid = '.$sID.''; // Define the query
$result = mysql_query($query); // Execute the query
if (!$result) {
$text1 = 'Something went wrong.
Please enter a valid survey ID.
';
mysql_close($con);
}
else if (mysql_num_rows($result) < 1) {
$text1 = 'No questions were found with this survey ID.
Please enter a valid survey ID.
';
mysql_close($con);
}
else {
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {// Do something with each returned row
$tempQID = $row['qid'];
$manSetting = $row['mandatory'];
switch ($gState)
{
case 'off':
if ($manSetting == 'Y')
{
$tCount++;
$sql = 'UPDATE lime_questions SET mandatory = \'M\' WHERE lime_questions.qid = '.$tempQID.' LIMIT 1;';
mysql_query($sql);
}
break;
case 'on':
if ($manSetting == 'M')
{
$tCount++;
$sql = 'UPDATE lime_questions SET mandatory = \'Y\' WHERE lime_questions.qid = '.$tempQID.' LIMIT 1;';
mysql_query($sql);
}
break;
default:
break;
}
}
switch ($gState)
{
case 'off':
$text1 = 'There were a total of '.mysql_num_rows($result).' questions found in this survey.
'.$tCount.' of them were toggled to "Off".';
break;
case 'on':
$text1 = 'There were a total of '.mysql_num_rows($result).' questions found in this survey.
'.$tCount.' of them were toggled to "On".';
break;
default:
break;
}
mysql_close($con);
}
}
?>