Jump to content

dapcigar

Members
  • Posts

    58
  • Joined

  • Last visited

Posts posted by dapcigar

  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. When something "didn't work" it usually helps all concerned if the voicer of that meaningless comment provides some backup as to WTH he/she is describing. Someone who was nice enough to provide a goodly chunk of code to you deserves more of a response than this so that he/she can help possibly debug it or to further discuss with you the problem.

     

    Jeez!

    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. Here's how I'd do it.

     

    Change your form to this:

    echo"<input type='checkbox' name='comp[" . $row['id'] . "' value= '1' /> ".$row['competency']." <br /> </td>";
    echo"<td> <select name='level[" . $row['id'] . "]'>
    
            <option></option>
            <option value='1'>level 1</option>
            <option value='2'>level 2</option>
            <option value='3'>level 3</option>
            <option value='4'>level 4</option>
            <option value='5'>level 5</option>  </select>                 </td> ";
    And then process as such:

    <?php
    
    session_start();
    $id = $_SESSION['user_id'];
    include ('mysql_connect.php');
    
    $hobbies = $_POST['comp'];
    
    if (count($hobbies) !== 0) {
        echo("<p>You selected " . count($hobbies) . " Hobbies(s): ");
    
        $insert = array();
        foreach (array_keys($hobbies) as $hobbyId) {
            $level = $_POST['level'][$hobbyId];
            
            $insert[] = "(" . intval($id) . ", " . intval($hobbyId) . ", '" . mysql_real_escape_string($level) . "')";
        }
        
        if (!empty($insert)) {
            $query = "INSERT INTO  competency_result (user_id, competency_id, level) VALUES " . implode(',', $insert);
            mysql_query($query) or die (mysql_error());
            $insertedId = mysql_insert_id();
        }
    }

    Didn't work..

  8. 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();  
            }
    
    
  9.  

    Here's how you should be doing it, storing the competency ids in a separate table, one per row.

    +----------------+                                +-----------------+  
    |    user        |                                |  competency     |
    +----------------+                                +-----------------+
    |   user_id   PK |--+                         +---|  comp_id     PK |
    |   username     |  |                         |   |  comp_name      |
    +----------------+  |                         |   +-----------------+
                        |                         |
                        |    +-----------------+  |
                        |    | user_competency |  |
                        |    +-----------------+  |
                        +---<|  user_id   PK   |  |
                             |  comp_id   PK   |>-+
                             +-----------------+     
                
    

    Then, to list the competencies for a user ($user)

    SELECT c.compname
    FROM user_competency uc
      INNER JOIN competency c USING (comp_id)
    WHERE uc.user_id = $user
    

    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.

  10. 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

  11. For the output simply do a new query that retrieves the user's data and build your table from that. This avoids being concerned about capturing other data from the input and ensures that you get the absolute current correct data from the db.

    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?

  12. 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

  13. What specifically are you stuck with?

     

    When you get the data from the database you loop through results and generate a checkbox, assigning each value returned by the query to each checkbox as you go

     

    When submitting multiple checkboxes, make sure you append the name of the checkbox with square brackets []. When the form is submitted the values for the selected checkboxes will be submitted as an array. To insert these values into the database you loop over the values in the array.

    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.

  14. 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

  15. 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>
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
  16. Dear all, Please i need help with something.

    I have some data in a particular table called "Requisitions" now i want to sum up all the values in the table by categories and then save it in a table called "transaction log. is there anyway i could achieve this by writing a script that does that automatically for me?

     

    thanks in advance

     

  17. Am trying to save into the DB. after running the query, i keep getting this error.

    "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'leave, meal, gross, tax, pension, dha, hmo, loan, surcharge, corporative, sa, ov' at line 1"

     

    have tried looking for the problem but i can't find it.. here's the code below

    	$que = mysql_query("INSERT INTO salary(id, firstname, lastname, basic, housing, transport, ultility, entertainment, leave, meal, gross, tax, pension, dha, hmo, loan, surcharge, corporative, sa, overtime, netpay, date, status) 
    VALUES (NULL, '$firstname', '$lastname', ' $basic', '$housing', '$transport', '$ultility', '$entertainment', '$leave', '$meal', '$gross', '$tax', '$pension', '$dha', '$hmo', '$loan', '$surcharge', '$corporative', '$sa', '$overtime', '$netpay', '$date', '$status')") or die(mysql_error());	
    		
    

    Thanks in advance

  18. Hello all,

     

    Am trying to use multiple if statement to check for data in the DB. everything seems fine till the last statement which is to insert the data in the DB if all the conditions are false. please, what am i doing wrong?

    $tool = mysql_query("SELECT *  FROM leave_member WHERE firstname = '$firstname' AND lastname = '$lastname' ");
    		$fest = mysql_fetch_array($tool);
    		
    		if ($type == 'Annual Leave'){
    			
    			
    			$annual = $fest['annual'];
    			if ($annual == '0')
    			{
    				echo "Sorry, you don't have any $type leave days available.";
    				exit;
    			}
    			else if ($workingDays > $annual){
    			
    			echo "Sorry, the number of days you are requesting is more than the number of days you have left. ";
    			
    			
    			exit;
    		}
    			
    		 exit;	
    		}
    				
    	else if ($type == 'Sick Leave'){
    		
    		$sick = $fest['sick'];
    			if ($sick == '0')
    			{
    				echo "Sorry, you don't have any $type leave days available.";
    				exit;
    			}
    			else if ($workingDays > $sick){
    			
    			echo "Sorry, the number of days you are requesting is more than the number of days you have left. ";
    			
    			
    			exit;
    		}
    			
    			exit;
    		
    	}
    	
    		else if ($type == 'Compassionate Leave'){
    		
    		$com = $fest['compassionate'];
    				if ($com == '0')
    			{
    				echo "Sorry, you don't have any leave days available.";
    				exit;
    			}
    			else if ($workingDays > $com){
    			
    			echo "Sorry, the number of days you are requesting is more than the number of days you have left. ";
    			
    			
    			exit;
    		}
    			exit;
    		
    	}
    	
    			else if ($type == 'Study Leave'){
    		
    		$study = $fest['study'];
    			//$result = $study - $days;
    			//$com = $fest['study'];
    				if ($study == '0')
    			{
    				echo "Sorry, you don't have any leave days available.";
    				exit;
    			}
    			else if ($workingDays > $study){
    			
    			echo "Sorry, the number of days you are requesting is more than the number of days you have left. ";
    			
    			
    			exit;
    		}
    			exit;
    		
    	}
    	
    				else if ($type == 'Mertanity Leave'){
    		
    		$maternity = $fest['maternity'];
    			
    				if ($maternity == '0')
    			{
    				echo "Sorry, you don't have any leave days available.";
    				exit;
    			}
    			else if ($workingDays > $maternity){
    			
    			echo "Sorry, the number of days you are requesting is more than the number of days you have left. ";
    			
    			
    			exit;
    		}
    			exit;
    		
    	}
    	
    	
    		
    	$sql = mysql_query("INSERT INTO leave_request ( id, firstname, lastname, department,  type, days, startdate, enddate, details, status) VALUES ( NULL, '$firstname', '$lastname', '$department', '$type','$workingDays', '$startDate', '$enddate','$details', '$status' )") or die(mysql_error());
    

     

     

     

     

     

     

     

    thanks in advance

  19. else if ($answer == 'Sometimes')
    		{
    			array_push($sometimes,'1');	
    				
    		}
    

    This the only one working. and the rest are not displaying the values. it was suppose to calculate the total number of people that answer a particular question and show the percentages..

  20. Hello all, 

     

    Am trying to get the answers of a survey from my DB and display the percentage.. Everything am trying seems not to be working. please what am i doing wrong.

    <?
    	$question_query = "SELECT * FROM ".$tblprefix."question WHERE category = 'Service Availability' and section = 'Information Technology Services'";
    	$rs = $db->Execute($question_query);
    		$all_the_time		=	array();
    		$most_of_the_time	=	array();
    		$sometimes			=	array();
    		$never				=	array();	
    	while (!$rs->EOF)
    	{
    		
    		$question_id = $rs->fields['question_id'];
    		
    		$question_query1 = "SELECT * FROM ".$tblprefix."user_answer, ".$tblprefix."question WHERE ".$tblprefix."user_answer.question_id = ".$tblprefix."question.question_id";
    		$rs1 = $db->Execute($question_query1);
    		
    		$answer_id = $rs1->fields['user_answer_id'];
    		
    		$question_query2 = "SELECT * FROM ".$tblprefix."answer WHERE answer_id = '$answer_id'";
    		$rs2 = $db->Execute($question_query2);
    		
    		$answer = $rs2->fields['answer'];
    		
    
    		
    		if($answer == 'All the time')
    		{
    			
    			array_push($all_the_time,'1');
    			
    			
    		}
    		else if ($answer == 'Most of the time')
    		{
    			array_push($most_of_the_time,'1');
    			
    			
    		}
    		else if ($answer == 'Sometimes')
    		{
    			array_push($sometimes,'1');	
    				
    		}
    		else if($answer == 'Never')
    		{
    			array_push($never,'1');
    			
    		}
    		
    		
    		$rs->MoveNext();	
    	}
    
    	
    
    		$count_all_of_time	=	count($all_the_time);
    		$count_most_of_time=	count($most_of_the_time);
    		$count_sometimes	=	count($sometimes);
    		$count_never		=	count($never);
    
    
    
    
    ?>
    
    <table border="0" class="question_answer_table">
        <tr>
        	<td><strong>Service Availability</strong></td>
        </tr>
    </table>
    <table border="0" class="question_answer_table">
        <tr>
        	<td style="width:120px;">All of Time</td>
            <td style="width:70px;"><?=round($count_all_of_time/$totaluser*100,2) .'%'?></td>
        </tr>
        <tr>
        	<td>Most of Time</td>
            <td><?=round($count_most_of_time/$totaluser*100,2) .'%'?></td>
        </tr>
        <tr>
        	<td>Sometimes</td>
            <td><?=round($count_sometimes/$totaluser*100,2) .'%'?></td>
        </tr>
        <tr>
        	<td>Never</td>
            <td><?=round($count_never/$totaluser*100,2) .'%'?></td>
        </tr>
         
    </table>
    
    

    Only one of the field is displaying an output. the rest are not.

     

     

    thanks in advance

     

     

     

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