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
https://forums.phpfreaks.com/topic/28368-adding-to-database/#findComment-129773
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
https://forums.phpfreaks.com/topic/28368-adding-to-database/#findComment-129783
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.