Jump to content

adding to database


masgas

Recommended Posts

thanks for that one!

You see, I have an "if" working that prints a different subject in that <td> once you answered the question...

if (!isset($answer)){
print question...
}
else {
insertAnswer (); // this is a function that inserts into the DB
and then print the results so far from the survey
}

So if I send it to the index.php the results wont show :(
Link to comment
Share on other sites

if (!isset($respondido)){
AconnectDBB ();
$sql="SELECT * FROM $tbl_name ORDER BY `id` DESC LIMIT 1 ";
$result=mysql_query($sql);
//mysql_close ($conQuest);
while ($row=mysql_fetch_array($result)){
$Quest = $row["Quest"];}

//Here I echo a standard html table with the question itself, a background and plain images...
}
else { 
//first insert the value:

insAnswer ();

//then echo a different table, with the results coming from the DB and a php image:
//
$sqlSi="SELECT * FROM datos WHERE R = 's'";
$sqlNo="SELECT * FROM datos WHERE R = 'n'";
$sqlNS="SELECT * FROM datos WHERE R = 'ns'";
//$sqlNS="SELECT * FROM datos WHERE NS = 'ns'";
$sqlT="SELECT * FROM datos";
$resultadoSi = mysql_query($sqlSi);
$totalSi=mysql_num_rows($resultadoSi);
//echo "Sí ".$totalSi."<br>";

$resultadoNo = mysql_query($sqlNo);
$totalNo=mysql_num_rows($resultadoNo);
//echo "No ".$totalNo."<br>";

$resultadoNS = mysql_query($sqlNS);
$totalNS=mysql_num_rows($resultadoNS);
//echo "NS ".$totalNS."<br>";

$resultadoT = mysql_query($sqlT);
$totalT=mysql_num_rows($resultadoT);
//echo "T ".$totalT."<br>";

//redondeo Sí
$redS = (($totalSi/$totalT))*100;
$xS = round($redS);
//echo "xS ".$xS."<br>";

//redondeo No
$redN = (($totalNo/$totalT))*100;
$xN = round($redN);
//echo "xN ".$xN."<br>";

//redondeo NS
$redNS = (($totalNS/$totalT))*100;
$xNS = round($redNS);
//echo "xNS ".$xNS."<br>";
mysql_close($con);
//$xS =40;
$yS =10;
//$xN =60;
$yN =25;
//$xNS =45;
$yNS =40;
$pic = imagecreate(100, 70);
$miAzul = imagecolorallocate($pic,128,149,206);
$miAmarillo = imagecolorallocate($pic,255,249,204);
$miGris = imagecolorallocate($pic,204,204,204);
$miRojo = imagecolorallocate($pic,242,204,204);
imagefilledrectangle($pic, 0, 20, $xS, $yS, $miRojo);
imagefilledrectangle($pic, 0, 35, $xN, $yN, $miAmarillo);
imagefilledrectangle($pic, 0, 50, $xNS, $yNS, $miGris);
imageColorTransparent($pic, $miAzul);
Imagepng($pic,"pic.png");
ImageDestroy($pic);
echo "<img src='pic.png'>";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.