Jump to content

dapcigar

Members
  • Posts

    58
  • Joined

  • Last visited

dapcigar's Achievements

Member

Member (2/5)

0

Reputation

  1. am getting the questions from the DB and displaying each question with the radio button options. <?php //session_start(); include('manpower_db.php'); $sql = mysql_query("SELECT * FROM question") or die(mysql_error()); $i = '1'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="" method="post"> <H2> How Will You Rate This Service</H2> <?php while($row = mysql_fetch_array($sql)) { echo $row['question']; $comp = $row['id'][$i]; // $_SESSION['comp']= $comp; ?> <br /> <?php echo "<td> <input type='radio' name='answer[".$row['id']."]' value='1' >1"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='2' >2"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='3' >3"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='4' >4"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='5' >5"; echo "<input type='hidden' name='comp[".$row['id']."]' value=$comp >"; echo'<br/>'; $i++; } ?> <br/> <strong> NOTE:</strong> 1 - Very Poor, 2 - poor, 3 - Okay, 4 - Fair, 5 - Good <p> <input name="submit" type="submit" value="submit" /> </form> </body> </html> the other part is to save the result . <?php session_start(); if($_POST) { $answer = $_POST['answer']; $hobb = $_POST['comp']; foreach($hobb as $key=>$val) { $var1=$hobb[$key]; $var2=$answer[$key]; include('manpower_db.php'); $table = "INSERT INTO answer (question_id,answer) ". "VALUES ('$var1','$var2')"; mysql_query($table) or die(mysql_error()); $inserted_fid = mysql_insert_id(); mysql_close(); } echo'<script>alert("Inserted Successfully")</script>'; } ?>
  2. let me understand your question. you have an excel sheet and you want to upload it to a table in your DB right? if that is what you want to do, you can use this code to perform a mass upload. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title></title> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr><td height="1" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#fff"> <tr> <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr><td width="60%" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr><td align="center" valign="top"> </td></tr> <tr> <td height="40" align="center" valign="middle"><?PHP echo $msg; ?></td> </tr> <tr><td align="center" valign="top"></td></tr> <tr> <td align="center" valign="top"><form id="xlsSheet" name="xlsSheet" method="post" action="<?PHP $_SERVER['PHP_SELF']; ?>" onsubmit="return valPwd();" enctype="multipart/form-data" > <table width="497" border="0" cellspacing="0" cellpadding="0"> <tr> <td valign="top" bgcolor="#999999"><table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td height="35" bgcolor="#D9ECFF" style="padding-left:50px;font-weight:bold;"> Choose a valid csv file.</td> </tr> <tr align="center"><td bgcolor="#ffffff"><br /> <table width="100%" border="0" cellspacing="0" cellpadding="3"> <tr> <td align="left">Upload CSV File : </td> <td align="left"><input name="filename" type="file" class="button" /> </td> </tr> <tr> <td></td> </tr> <tr> <td align="right"></a></td> </tr> </table> <br /> <input name="submit" type="submit" value="Upload File" style="background-color: #A31C21; border-radius: 6px; font-weight: bold; height: 30px; width: 125px; margin-right:35px;" /> <br /> <br /> </td></tr> <tr><td height="35" bgcolor="#D9ECFF" class="text3"> </td></tr> </table></td> </tr> </table> </form></td> </tr> </table></td> </tr> </table></td> </tr> </table></td> </tr> </table> </body> </html> <?php if(isset($_POST['submit'])) { //Connect to Database $db = new PDO('mysql:host=localhost;dbname=(database name);charset=utf8', 'root', ''); //include('mysql_connect.php'); //Upload File if (is_uploaded_file($_FILES['filename']['tmp_name'])) { echo "<h2>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "</h2>"; } //Import uploaded file to Database $handle = fopen($_FILES['filename']['tmp_name'], "r"); $count =0; while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $import = $db->exec("INSERT into (your Table) (firstname, lastname, jobtitle, email, project, type, username, password) values('$data[0]','$data[1]','$data[2]','$data[3]', '$data[4]','$data[5]','$data[6]','$data[7]')"); $count++; } fclose($handle); //Print interted rows $msg="<h3 style='color:green;'>".$count. " Rows Imported !</h3>"; } ?> save this file as upload.php. locate your spreadsheet and upload. make sure you save your excel sheet in CSV format. Hope this helps..
  3. Hello all, Am trying to create a simple feedback form and also save the answers of each questions. i manage to get the system to save the answers but am not getting the id of my questions saved.. My code below <?php if($_POST) { $answer = $_POST['answer']; $hobb = $_POST['comp']; foreach($hobb as $key=>$val) { $var1=$hobb[$key]; $var2=$answer[$key]; include('manpower_db.php'); $table = "INSERT INTO answer (question_id,answer) ". "VALUES ('$var1','$var2')"; mysql_query($table) or die(mysql_error()); $inserted_fid = mysql_insert_id(); mysql_close(); } echo'<script>alert("Inserted Successfully")</script>'; } ?> <?php //session_start(); include('manpower_db.php'); $sql = mysql_query("SELECT * FROM question") or die(mysql_error()); $i = '1'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="" method="post"> <H2> How Will You Rate This Service</H2> <?php while($row = mysql_fetch_array($sql)) { echo $row['question']; $comp = $row['id'][$i]; // $_SESSION['comp']= $comp; ?> <br /> <?php echo "<td> <input type='radio' name='answer[".$row['id']."]' value='1' >1"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='2' >2"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='3' >3"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='4' >4"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='5' >5"; echo "<input type='hidden' name='comp[".$row['id']."]' value=$comp >"; echo'<br/>'; $i++; } ?> <br/> <strong> NOTE:</strong> 1 - Very Poor, 2 - poor, 3 - Okay, 4 - Fair, 5 - Good <p> <input name="submit" type="submit" value="submit" /> </form> </body> </html>
  4. Am trying to get value from a list of data and pass the value to a modal popup to display more details. i can't find where the problem is. the button <td> <button class="btn btn-primary " data-toggle="modal" data-id="<?php echo $id ?>" data-target="#myModal" id="myButton"> View Details </button></td> the modal <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title" id="myModalLabel">Requisition Details</h4> </div> <div class="modal-body"> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Save changes</button> </div> </div> <!-- /.modal-content --> </div> the script <script language="javascript" type="text/javascript"> $('#myButton').click(function() { $('#myModal').modal('show') }); $('#myModal').on('shown.bs.modal', function(e) { $.ajax({ method: "POST", url: "getData.php", data: { dataId: $('#myModal').attr('data-id') }, success: function(data) { data = jQuery.parseJSON(data); $('.modal-body', '#myModal').html(data); } }); }) </script> the getdata.php <?php //dataId comes from ajax (POST) $id = filter_input(INPUT_POST, 'dataId'); include('mysql_connect.php'); $query11 = mysql_query("select * from p_requisition where id = '$id' ") or die(mysql_error()); $rows = mysql_fetch_array($query11); //you should use json_encode, and you can parse when get back data in ajax echo json_encode($rows['details']); ?> Please, Help me out..
  5. Am trying to save the result of the the selected answer with the question id. don't know how to pass the id to the DB. here's my code <?php session_start(); include('config/manpower_db.php'); $sql = mysql_query("SELECT * FROM question") or die(mysql_error()); $i = '1'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="save_feedback2.php" method="post"> <H2> How Will You Rate This Service</H2> <?php while($row = mysql_fetch_array($sql)) { echo $row['question']; $comp = $row['id'][$i]; // $_SESSION['comp']= $comp; ?> <br /> <?php echo "<td> <input type='radio' name='answer[".$row['id']."]' value='1' >1"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='2' >2"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='3' >3"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='4' >4"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='5' >5"; echo "<input type='hidden' name='question_id' value=$comp >"; echo'<br/>'; $i++; } ?> <br/> <strong> NOTE:</strong> 1 - Very Poor, 2 - poor, 3 - Okay, 4 - Fair, 5 - Good <p> <input name="submit" type="submit" value="submit" /> </form> </body> </html> Save to DB <?php session_start(); $answer = $_POST['answer']; $hobb = $_POST['question_id']; include('config/manpower_db.php'); foreach($hobb as $key=>$val) { $var1=$hobb[$key]; $var2=$answer[$key]; //include ('connect.php'); //include ('mysql_connect.php'); $table = "INSERT INTO answer (question_id,answer) ". "VALUES ('$var2','$var2')"; mysql_query($table) or die(mysql_error()); $inserted_fid = mysql_insert_id(); mysql_close(); } echo'<script>alert("Inserted Successfully")</script>'; ?> Please HELP!! thanks in advance
  6. So sorry if that sounds like i didn't appreciate his effort. trust me i do. I should really apologize for my comment. it was harsh. i was only giving a feedback not to undermine him. i really need to fix this issue.
  7. Hello all, Am trying to retrieve a table from the DB, allow user select multiple options and also put the level . i was able to save the Data of the selected checkboxes but i cant get the level to save. my display code <form action="save_comp.php" method="post"> <?php include ('mysql_connect.php'); $sql = mysql_query("SELECT * FROM competency WHERE department = '$department'"); while($row = mysql_fetch_array($sql)) { echo "<tr>"; echo "<td>"; echo"<input type='checkbox' name='comp[]' value= ".$row['id']." /> ".$row['competency']." <br /> </td>"; echo"<td> <select name='level[]'> <option></option> <option>level 1</option> <option>level 2</option> <option>level 3</option> <option>level 4</option> <option>level 5</option> </select> </td> "; } echo "</tr>"; ?> <input name="submit" type="submit" value="submit" /> </form> <?php echo" </table>"; Code to save to DB <?php session_start(); $id = $_SESSION['user_id']; //$id = 3; $hobb = $_POST['comp']; $level = $_POST['level']; include ('mysql_connect.php'); $N = count($hobb); echo("<p>You selected $N Hobbies(s): "); for($i=0; $i < $N; $i++) { $var1=$hobb[$i]; $var2 = $level[$i]; include ('mysql_connect.php'); $table = "INSERT INTO competency_result (user_id,competency_id,level) ". "VALUES ('$id', '$var1', '$var2')"; mysql_query($table) or die(mysql_error()); $inserted_fid = mysql_insert_id(); mysql_close(); }
  8. This would make it a whole lot easier for me. my challenge now is how to save the result of a multiple check-box as a separate record.
  9. I was able to manipulate it by using explode function. the issue now is that when i try to view the reslt, it's only displaying the first one in the array. i figure my loop is not running properly. could you help me take a look at it $separate = explode(" ", $row['result']); for($i = 0; $i < count($separate); $i++){ $quest= mysql_query("SELECT * FROM competency WHERE id = '$separate[$i]'")or die(mysql_error()); while($rows = mysql_fetch_array($quest)) { echo"<tr>"; echo"<td> $rows[competency] <br /></td>"; } } thanks in advance
  10. Please, could you help me with the syntax?. what is stored in the DB is just the ID. how do i separate the Id's and display the output?
  11. Thanks.. figured it out.. i can now save the result into a database. now i have another issue. i want to display the result in a table showing the result. the problem is i only saved the id of the checkboxes. so when i try to display the result, it just shows me the id. <?php $res= mysql_query("SELECT * FROM competency_result WHERE user_id = '$user'")or die(mysql_error()); while($row = mysql_fetch_array($res)) { echo"<tr>"; echo"<td> $row[result]</td>"; ?> The output comes out as 1,5,17. Help please
  12. Thanks a lot.. followed that and i was able to display the saved data with a checkbox. the problem am having now is saving back the selected result back to the DB. here's my code below // For Display <form action="save_comp.php" method="post"> <?php include ('mysql_connect.php'); $sql = mysql_query("SELECT * FROM competency "); //$row = mysql_fetch_array($sql); while($row = mysql_fetch_array($sql)) { echo"<input type='checkbox' name='comp[]' value= ".$row['id']." /> ".$row['competency']." <br />"; } ?> <input name="submit" type="submit" value="submit" /> </form> and for saving into the DB, <?php $insStr = ''; foreach($_POST['comp'] as $val){ $insStr .=$val.","; } mysql_query("INSERT INTO competency_result (result) VALUES ( '$insStr' )"); ?> Please, result is not saving.
  13. Hello all, I have a table i created and i want the data to be displayed using check box. Also want users to be able to select multiple checkboxes and save the result back into the DB.. Am so confused right now, i don't know how to accomplish this. Anyone can help me with a syntax? thanks in advance
  14. Hello , Am trying to display the data for the current year by department. i was able to populate the spent but could not display the budget. please what am i doing wrong <?php $date = $_POST['Date']; $dept = $_POST["department"]; //$date = '25/05/2010'; $date = str_replace('/', '-', $date); $new_date = date('Y-m-d', strtotime($date)); //echo $new_date; include('mysql_connect.php'); $year = date('Y'); // Settings for the graph include "libchart/classes/libchart.php"; /* $chart = new VerticalBarChart(600, 520); $chart = new VerticalBarChart(); $dataSet = new XYDataSet(); $query1 = mysql_query ("SELECT department , SUM(amount) as amt FROM requisition WHERE date = '$new_date' GROUP BY department ") or die(mysql_error()); while($row = mysql_fetch_array($query1)) { $dataSet->addPoint(new Point($row['department'], $row['amt'])); } $chart->setDataSet($dataSet); $chart->setTitle("Report By Month"); $chart->render("generated/date.png"); */ // header("Location: view_date.php"); //header ('lcoation : '); ?> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <script src="highcharts.js"></script> <?php $q = "select sum(amount) 'amount', sum(actual) 'actual',department from transaction_log where Year(date)='$year' GROUP BY department "; $query1 = mysql_query ($q) or die(mysql_error()); // echo $q; // $values = array(); // $months = array("January","February","March","April","May","June","July","August","September","October","November","December"); while($row = mysql_fetch_assoc($query1)) { $categories[] = $row["department"]; // $budgets[$row["category"]] = $row["amount"]; $budgets[] = $row["amount"]; // $actuals[$row["category"]] = $row["actual"]; $actuals[] = $row["actual"]; //$values[] = $row; //$serie1->addPoint(new Point($row['department'], $row['amount'])); //$serie2->addPoint(new Point($row['department'], $row['actual'])); } $cats = json_encode($categories); $series = array(); $o = new stdClass(); $o->name = 'Spent'; $o->data = $actuals; $series[] = $o; $o = new stdClass(); $o->name = 'Amount'; $o->data = $amounts; $series[] = $o; $json = json_encode($series); ?> <div align="left"><img src="img/top.png" width="200" height="59" /> </div> <div id="container"></div> <script type="text/javascript"> $(function () { $('#container').highcharts({ chart: { type: 'column' }, title: { text: 'Report For Jan - Mar 2015' }, subtitle: { text: '' }, xAxis: { categories:<?php echo $cats; ?>, labels: { rotation: -25, } }, yAxis: { min: 0, title: { text: '' } }, tooltip: { headerFormat: '<span style="font-size:10px">{point.key}</span><table>', pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' + '<td style="padding:0"><b>{point.y:.1f}</b></td></tr>', footerFormat: '</table>', shared: true, useHTML: true }, plotOptions: { column: { pointPadding: 0.2, borderWidth: 0, dataLabels: { enabled: true }, } }, series:<?php echo preg_replace("/\"([0-9]*?\.[0-9]*?)\"/","$1",$json); ?> }); }); </script>
×
×
  • 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.