Jump to content

need some asstaince with table display


webguync

Recommended Posts

I have a table that I am creating with php code pulling information from a MySQL database. everything works great so far but there are some adjustments I need to make and need some assistance getting there. I need to add a column prior to the database extraction which is just straight HTML. I can't seem to find where to add this so that it doesn't become part of the mysql fetch results.

 

Also, currently there are for results per row, because that is what I have it set to, but actually what I need is varying, 5 results in the first row, 4 in the next three rows and 3 in the last row. How can I accomplish this?

 

 

thanks in advance. Current code below.

 


<?php
/*--------- DATABASE CONNECTION INFO---------*/
//set up table and database names
$db_name ="DBName";
$grid_name ="grid";
$employee_table="employees";
//connect to server and select database
$connection = @mysql_connect( "localhost" , "UserName" , "PassWord" )
or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error() );

//gather data from employee list
$sql = "SELECT ID,Employee_Name FROM $employee_table ORDER BY ID ASC";
$result = mysql_query($sql) or die(mysql_error());

//begin building HTML table

echo '<table id="main"><tr><td align="right"><img src="NN_Logo.png" alt="NN" /></td></tr><tr><td>';

echo '<table id="employees"><tr><td><select>';
while(list($id,$name) = mysql_fetch_row($result)){
    echo '<option value="'.$id.'" />'.$name.'</option>'."\n";
}
echo '</select></td></tr></table>';



//Build and issue query
$sql="SELECT * from $grid_name";
$result = @mysql_query($sql,$connection)or die(mysql_error());

$fields_per_row = 4;
echo '<form action="" method="post">
<table id="matrix"><tr><th colspan="8"> Selling Skills Recommended Follow-up</th></tr>
';
//for ($i = 1; $i <= $fields; $i++) {
for($i = 0;$row = mysql_fetch_assoc($result);$i++){
  if (!($i % $fields_per_row)) {
    echo '</tr><tr>';
  }
  
  echo '<td><input type="checkbox" name="grid[]" value="'.$row['Id'].'" class="inactive" onclick="changeState(this);"></td><td>'.$row['Text'].'</td>';
}
echo '</tr></table>

<div id="submit"><input type="image" src="Submit.png" value="submit" /></div></table></td></table>';
//end of HTML table
echo '</td></tr></table></form>';
?>

Link to comment
Share on other sites

  • Replies 80
  • Created
  • Last Reply

Top Posters In This Topic

Well here's my take.  I'm sure there is a more elegant way of doing it, but...yeah.  What I did was break it down into 3 separate loops.  I tested it with a test table on my own db so you're gonna have to plug in your own vars and names, obviously.

 

<?php

$sql = "select tutorial_title from tutorial";
$result = mysql_query($sql);

$x = 0;                                                   // keep track of what col we're on
echo "<table border = '1'><tr>";                  // start of table
while ($list = mysql_fetch_assoc($result)) {  // start of loop
   if ($x == 5) break;                                 // break the loop when we have 5
   echo "<td>{$list['tutorial_title']}</td>";    // echo info out
   $x++;                                                 // inc to next col pos
}                                                          // end loop       
echo "</tr><tr>";                                    // end and start next row

// this loop is a little more complicated, since
// there will be several rows with 4 columns
$x = 0;                                                  // keep track of which col we're on
$y = 0;                                                  // keep track of which row we're on
while ($list = mysql_fetch_assoc($result)) {  // start the loop
   if ($x == 4) {                                        // if we have 4 cols displayed...
      echo "</tr><tr>";                               // end and start a new row
      $y++;                                              // move row counter to next pos
      if ($y == 4) break;                             // if we reach 4 rows, we end the loop
      $x = 0;                                            // otherwise, we reset col counter and keep going
   }                                                       // end if
   echo "<td>{$list['tutorial_title']}</td>";   // echo data out
   $x++;                                                 // move to next col
}                                                          // end loop 

$x = 0;                                                  // start col counter over for last loop
echo "</tr><tr>";                                     // end last row of last loop and start new row
while ($list = mysql_fetch_assoc($result)) {  // start last loop
   if ($x == 3) break;                                 // if we have 3 cols, end loop
   echo "<td>{$list['tutorial_title']}</td>";     // echo out info
   $x++;                                                  // move to next col count
}                                                           // end last loop
echo "</tr></table>";                                // close the last row and the table

?>

 

Link to comment
Share on other sites

sure, here is the SQL for table employees

 


CREATE TABLE `employees` (
  `ID` smallint(11) NOT NULL auto_increment,
  `employee_name` varchar(155) NOT NULL default '',
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;

-- 
-- Dumping data for table `employees`
-- 

INSERT INTO `employees` (`ID`, `employee_name`) VALUES (1, 'Buck Wheat'),
(2, 'Alfalfa'),
(3, 'Porky'),
(4, 'Stymie');

 

and here for the table 'grid'

 

-- 
-- Table structure for table `grid`
-- 

CREATE TABLE `grid` (
  `ID` tinyint(4) NOT NULL auto_increment,
  `Text` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=25 ;

-- 
-- Dumping data for table `grid`
-- 

INSERT INTO `grid` (`ID`, `Text`) VALUES (1, 'Utilize a patient profile to clearly define a patient type to focus call.'),
(2, 'Create a smooth transition from rapport building to a business discussion.'),
(3, 'Clearly state call purpose, benefit and follow with a check-in to insure on customer agenda.'),
(4, 'Gain customer interest by utilizing visual aids.'),
(5, 'Establish clear call continuity through focused opener that engages the customer in a dialogue.'),
(6, 'Ask questions before presenting data to validate you are on customer''s agenda.'),
(7, 'Ask close and opened ended questions to uncover relevant customer action need beyond the surface need.'),
(8, 'Ask open ended and high value questions to create dialogue and show customer focus.'),
(9, 'Demonstrate active listening through asking appropriate clarifying questions to address and expand customer needs.'),
(10, 'Utilize appropriate NNI resource to address customer''s action need.'),
(11, 'Utilize appropriate clinical reprint(s) to support core messages.'),
(12, 'Consistently ties relevant product features and benefits to customer needs.'),
(13, 'Consistently ties relevant product features and benefits to patient profile identified in opening.'),
(14, 'Acknowledge customer objection.'),
(15, 'Create customer dialogue by utilizing appropriate clarifying questions.'),
(16, 'Incorporate appropriate resource to take action and resolve customer objection.'),
(17, 'Differentiate between customer questions and objections.'),
(18, 'Recognize verbal and non verbal customer buying signals.'),
(19, 'Utilize trial closes to check for agreement through out sales call.'),
(20, 'Gain commitment on a SMART objective.'),
(21, 'Clearly describe the appropriate patient type and NNI product.'),
(22, 'Transition from one product to another by stating a common theme or linking back to the patient type.'),
(23, 'Set up product transition in opening.'),
(24, 'Demonstrate flexibility by tranitionsing from one product to another per customer agenda.');

 

eventually what I want is to be able to choose an employee from the drop down and click on the checkbixes and have that information be stored into a database as to which employee had which checkboxes clciked. Right now I was just trying to get my HTML display to be correct. as looking like the example I linked to previously.

 

thanks for all the help, and let me know what other information you may need.

Link to comment
Share on other sites

To be honest i think the easiest thing to do would be to add another field to the grid table and give it a block name. that way you can order your results by the block name and won't have to worry about it if you add more entries at some point.  will post my code in a moment. will give you an example of submitting the check boxes also. Do you want to store the check boxes in the same table and the employee or in a separate table??

 

Ray

 

Link to comment
Share on other sites

thanks, I will work on your suggestion as to adding this into the grid field.

 

I would need the results if the check box to be entered into a separate table, I believe. Basically if someone chooses 'Buckwheat' from the dropdown menu and clicks a particular checkbox and submits that will need to be stored in the MySQL DB table.

 

eg:

EmployeeName      Grid ID checked

 

Buckwheat          1,3,4,6,7,8,9,11

 

thanks!

Link to comment
Share on other sites

also ray, could you give an example of ordering results for the display of the table data from MySQL as you mentioned previously? Say for instance I created a new column in the MySQL table called 'grid'. That column was 'RowHeader', and had different text for each record. 'header1','header2','header3','header4','header5','header6'.

 

thanks for all the help!

 

 

Link to comment
Share on other sites

OK here is what I did. I used just about all of your code. Just a little constructive critisisum, but you can make it alot neater. :) but here is what I used.

as far as tables go:

Employee table stays the same

grid table

CREATE TABLE `grid` (
  `ID` tinyint(4) NOT NULL auto_increment,
  `Text` varchar(255) NOT NULL default '',
  `Block` varchar(25) NOT NULL,
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM AUTO_INCREMENT=25 DEFAULT CHARSET=utf8 AUTO_INCREMENT=25 ;

-- 
-- Dumping data for table `grid`
-- 

INSERT INTO `grid` VALUES (1, 'Utilize a patient profile to clearly define a patient type to focus call.', 'Block 1');
INSERT INTO `grid` VALUES (2, 'Create a smooth transition from rapport building to a business discussion.', 'Block 1');
INSERT INTO `grid` VALUES (3, 'Clearly state call purpose, benefit and follow with a check-in to insure on customer agenda.', 'Block 1');
INSERT INTO `grid` VALUES (4, 'Gain customer interest by utilizing visual aids.', 'Block 1');
INSERT INTO `grid` VALUES (5, 'Establish clear call continuity through focused opener that engages the customer in a dialogue.', 'Block 1');
INSERT INTO `grid` VALUES (6, 'Ask questions before presenting data to validate you are on customer''s agenda.', 'Block 2');
INSERT INTO `grid` VALUES (7, 'Ask close and opened ended questions to uncover relevant customer action need beyond the surface need.', 'Block 2');
INSERT INTO `grid` VALUES (8, 'Ask open ended and high value questions to create dialogue and show customer focus.', 'Block 2');
INSERT INTO `grid` VALUES (9, 'Demonstrate active listening through asking appropriate clarifying questions to address and expand customer needs.', 'Block 2');
INSERT INTO `grid` VALUES (10, 'Utilize appropriate NNI resource to address customer''s action need.', 'Block 3');
INSERT INTO `grid` VALUES (11, 'Utilize appropriate clinical reprint(s) to support core messages.', 'Block 3');
INSERT INTO `grid` VALUES (12, 'Consistently ties relevant product features and benefits to customer needs.', 'Block 3');
INSERT INTO `grid` VALUES (13, 'Consistently ties relevant product features and benefits to patient profile identified in opening.', 'Block 3');
INSERT INTO `grid` VALUES (14, 'Acknowledge customer objection.', 'Block 4');
INSERT INTO `grid` VALUES (15, 'Create customer dialogue by utilizing appropriate clarifying questions.', 'Block 4');
INSERT INTO `grid` VALUES (16, 'Incorporate appropriate resource to take action and resolve customer objection.', 'Block 4');
INSERT INTO `grid` VALUES (17, 'Differentiate between customer questions and objections.', 'Block 4');
INSERT INTO `grid` VALUES (18, 'Recognize verbal and non verbal customer buying signals.', 'Block 5');
INSERT INTO `grid` VALUES (19, 'Utilize trial closes to check for agreement through out sales call.', 'Block 5');
INSERT INTO `grid` VALUES (20, 'Gain commitment on a SMART objective.', 'Block 5');
INSERT INTO `grid` VALUES (21, 'Clearly describe the appropriate patient type and NNI product.', 'Block 5');
INSERT INTO `grid` VALUES (22, 'Transition from one product to another by stating a common theme or linking back to the patient type.', 'Block 6');
INSERT INTO `grid` VALUES (23, 'Set up product transition in opening.', 'Block 6');
INSERT INTO `grid` VALUES (24, 'Demonstrate flexibility by tranitionsing from one product to another per customer agenda.', 'Block 6');

 

emp_checks  this stores the checkboxes

CREATE TABLE `emp_checks` (
  `CheckID` int(11) unsigned NOT NULL auto_increment,
  `EmpID` int(11) NOT NULL,
  `Blocks` varchar(100) NOT NULL,
  PRIMARY KEY  (`CheckID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

-- 
-- Dumping data for table `emp_checks`
-- 

INSERT INTO `emp_checks` VALUES (1, 3, '1,8,7,6,12,11,10,14,21,22');
INSERT INTO `emp_checks` VALUES (2, 2, '2,8,12,15,20,23');

 

Now for the page

<?php
/*--------- DATABASE CONNECTION INFO--------- */
//set up table and database names
$db_name ="DBName";
$grid_name ="grid";
$employee_table="employees";
$check_table = "emp_checks";
//connect to server and select database
$connection = @mysql_connect( "localhost" , "UserName" , "PassWord" )
or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error() );

// this sets the employee id. 1 if no employee is set
$emp_id = isset($_GET['emp_id']) ? $_GET['emp_id'] : "1";
// check to see if the submit button was pressed
if(isset($_POST['submit'])){
// set the employee id
$id = $_POST['emp_id'];
// change the array to a comma seperated string for storage
$blocks = implode(",", $_POST['grid']);
// check if employee has an entry in the emp_checks table
$check = "SELECT CheckID FROM $check_table WHERE EmpID = '$id'";
$cres = mysql_query($check) or die(mysql_error());
$found = mysql_num_rows($cres);
  if($found > 0){
  // if an employee was found  we update the check boxes
  $update = "UPDATE $check_table SET Blocks = '$blocks' WHERE `EmpID` = '$id'";
  mysql_query($update) or die(mysql_error());
  echo $update;
  } else {
  // If employee was not found we insert the checkboxes
  $insert = "INSERT INTO $check_table (`EmpID`, `Blocks`) VALUES ('$id', '$blocks')";
  mysql_query($insert) or die(mysql_error());
  echo $insert;

  }
} else {
//gather data from employee list
$sql = "SELECT ID, Employee_Name, Blocks FROM $employee_table LEFT JOIN $check_table ON `ID` = `EmpID` ORDER BY ID ASC";
$result = mysql_query($sql) or die(mysql_error());

//begin building HTML table
echo '<form action="" method="get">';
echo '<table id="main">
  <tr>
    <td align="right"><img src="NN_Logo.png" alt="NN" /></td>
  </tr>
  <tr>
    <td>';

echo '<table id="employees">
  <tr>
    <td>
    <select name="emp_id" onchange="this.form.submit()" />
    ';
while(list($id,$name) = mysql_fetch_row($result)){
// this will select the current employee int he dropdown box
$selected = $id == $emp_id ? "selected" : "";
    echo '<option value="'.$id.'" '.$selected.' />'.$name.'</option>'."\n";
}
echo '</select>
    </td>
  </tr>
</form>
</table>';
// Get checkboxes from emp_checks table
$ch = "SELECT Blocks FROM $check_table WHERE `EmpID` = '$emp_id'";
$cres = mysql_query($ch) or die(mysql_error());
$c = mysql_fetch_assoc($cres);
// put the comma seperated values in an array
$checks = explode(",", $c['Blocks']);

//Build and issue query
$sql="SELECT * from $grid_name ORDER BY Block";
$result = mysql_query($sql)or die(mysql_error());
// set the block groups
$lastblock = '';
echo '<form action="" method="POST">
<input type="hidden" name="emp_id" value="'.$emp_id.'" />
<table id="matrix" border=1>
  <tr>
    <th colspan="11"> Selling Skills Recommended Follow-up</th>
  </tr>';
while($row = mysql_fetch_assoc($result)){
// if the checkbox is in the array, check off the checkbox
$chk = in_array($row['ID'], $checks) ? "checked" : "";
  // checks to see if the block name has changed, if it has start a new row
  if($row['Block'] != $lastblock){
  echo "<tr><td>{$row['Block']}</td>";
  }
  echo '<td><input type="checkbox" name="grid[]" value="'.$row['ID'].'" class="inactive" onclick="changeState(this);" '.$chk.' /></td><td>'.$row['Text'].'</td>';
// set the lastblock to the current block in the loop
$lastblock = $row['Block'];
}
echo '</tr></table>
<div id="submit"><input type="image" src="Submit.png" name="submit" value="submit" alt="submit" /></div></table></td></table>';
//end of HTML table
echo '</td>
  </tr>
</table>
</form>';
}
?>

 

By adding the block name to the grids table you can easily go to the next group instead of trying to divide up the rows by 5,4,4,4,3 It will do it for you with one simple check.

 

Just add the header name in the Blocks column and name the ones you would like in the same row the same thing.

 

Let me know how that works out

 

Ray

Link to comment
Share on other sites

It's definitely working so thanks for the assistance to this point. A couple of glitches I need to resolve are:

 

1) The display isn't exactly how I want it. For instance right now in the MySQL DB the first 5 ID's aren't the top row being displayed

 

2) When you choose an employee from the dropdown menu, some of the checkboxes are already checked.

 

3) After you hit submit, the SQL results appear on the subsequent page. What I would ideally like to have is a page to verify the results for the employee (the actual text that corresponds to the ID's) and then give them the option to go back and use the tool again for another employee. Would this just involve creating a separate page to go into action=""? I would probably need some assistance on thow that display would work.

 

4) I know this isn't a Javascript forum but for some reason my onclick event no longer works. It uses CSS to highlight the table cell when you select one of them. I had this working for a while, but now it does not I also posted this problem in the JavaScript section.

 

I am posting links below so you can see what I am referring to,

 

test application is at:http://etsi-dataservices.com/test/index_test.php

javascript: http://etsi-dataservices.com/test/ChangeState.js

CSS:  http://etsi-dataservices.com/test/Global.css

 

 

THANKS!!!

Link to comment
Share on other sites

1.) Since the block field in the grids table is a string it may be tough to sort it. If you want change it to an Int field and just mark the rows you want to show first with a 1, then the second with a 2 and so on. it will sort correctly this way. if you want it to show the block headers to the left then add another field with the block header name. or even another table with the header name which would link to the number you use for the block.

 

2.) They are already checked because they have entries in the emp_checks table. This way it shows you which ones they currently have.

 

3.) you can make a separate page, that way the display page does not become so cluttered, to process your results. Just tell the form to submit to a new page and put the update/insert code on the new page.

 

4.) You might have a problem with this because I added another form for the drop down list, so your java may not know which form to update. Just name each form and adjust your javascript to update the correct form.

 

 

Let me know which way you want to go with the first and I can give you some more code.

 

Ray

Link to comment
Share on other sites

thanks, I would need to block column to remain varchar so that it would be text inserted unless there is another way to do that.

 

for the forms I named each one such as form name="text", but not sure how to call the form in the JS I am currently using :

 


// JavaScript Document

function changeState(fieldObj) {

  if (fieldObj.className=='active') {
    newClass = 'inactive';
  } else {
    newClass = 'active';
  }

  fieldObj.className = newClass;
  return;
}

Link to comment
Share on other sites

well you can always add a number to the front of it and just substr the field, it would get scary after the number 10 though

 

block names =

1OPEN PURPOSEFULLY

2GAINING COMMITMENT

3PROVIDE SOLUTIONS AND DEL

4RESOLVE OBJECTIONS

5UNCOVER NEEDS

6TRANSITIONING

 

now they will sort correctly. and you can get the name to show

  if($row['Block'] != $lastblock){
  echo "<tr><td>'.substr($row['Block'], 1).'</td>";
  }

 

Ray

Link to comment
Share on other sites

fraid I might need some help with the results page as well.

 

would I need to use all of this code and then display the results in the HTML?

 

<?php
/*--------- DATABASE CONNECTION INFO--------- */
//set up table and database names
$db_name ="NN_FollowUp";
$grid_name ="grid";
$employee_table="employees";
$check_table = "emp_checks";
//connect to server and select database
$connection = @mysql_connect( "localhost" , "NNFollowUp" , "Novo1" )
or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error() );

// this sets the employee id. 1 if no employee is set
$emp_id = isset($_GET['emp_id']) ? $_GET['emp_id'] : "1";
// check to see if the submit button was pressed
if(isset($_POST['submit'])){
// set the employee id
$id = $_POST['emp_id'];
// change the array to a comma seperated string for storage
$blocks = implode(",", $_POST['grid']);
// check if employee has an entry in the emp_checks table
$check = "SELECT CheckID FROM $check_table WHERE EmpID = '$id'";
$cres = mysql_query($check) or die(mysql_error());
$found = mysql_num_rows($cres);
  if($found > 0){
  // if an employee was found  we update the check boxes
  $update = "UPDATE $check_table SET Blocks = '$blocks' WHERE `EmpID` = '$id'";
  mysql_query($update) or die(mysql_error());
  echo $update;
  } else {
  // If employee was not found we insert the checkboxes
  $insert = "INSERT INTO $check_table (`EmpID`, `Blocks`) VALUES ('$id', '$blocks')";
  mysql_query($insert) or die(mysql_error());
  echo $insert;

  }
} else {
//gather data from employee list
$sql = "SELECT ID, Employee_Name, Blocks FROM $employee_table LEFT JOIN $check_table ON `ID` = `EmpID` ORDER BY ID ASC";
$result = mysql_query($sql) or die(mysql_error());

//begin building HTML table
echo "<table><tr>";
echo "<td>Test</td>";
echo "</td></tr></table>";
}
?>

 

 

where I have 'test', is where I want to start inserting the data that has been chosen. Ideally it would need to display the employees name and all of their results in text, not just the ID's that were selected. Simply a verification to the user what they have selected and submitted.

 

THANKS!!!

 

 

Link to comment
Share on other sites

When My form is submitted, I also want to record when the upload (or submit) occurred. I added a column into the table emp_checks set to type 'datetime', and named the new column date_uploaded. Now which SQL statement would I need to add this field to? Would it be the here?

 

  $insert = "INSERT INTO $check_table (`EmpID`, `Blocks`,`date_uploaded`) VALUES ('$id', '$blocks')";

Link to comment
Share on other sites

Well if you want to keep track of inserts and changes you would put it in both statements.

 

$now = date("Y-m-d H:i:s");
$insert = "INSERT INTO $check_table (`EmpID`, `Blocks`,`date_uploaded`) VALUES ('$id', '$blocks', '$now')";

 

Ray

Link to comment
Share on other sites

thanks again Ray,

 

another problem I have that I haven't been able to resolve is this:

 

I have a login form that when submitted should go to the form page that we have been working on though-out this post. The code I have is as follows:

 

<form action="index_test.php" method="post" >
<table id="login">
<tr id="LoginHeader"><td>Welcome to the Novo Nordisk Follow-Up Assessment Application<br />Please enter your first and last name below and hit the submit button</td><td><img src="novo-logo.png" alt="Norvo Nordisk" /></td></tr>

<tr>
<td>
<table id="login2">
<tr>
<td>
<label for="FirstName">First and Last Name:</label>
<input type="text" size="45" name="Accessor" id="accessor" />
</td>
<td><input type="image" src="Submit.png" name="submit" value="submit" alt="submit" id="submit" /></td>

</tr>
</table>
</td>
</tr>
</table>
</form>

 

on the page with the form block I now have:

 

<?php
/*--------- DATABASE CONNECTION INFO--------- */
//set up table and database names
$db_name ="DBName";
$grid_name ="grid";
$employee_table="employees";
$check_table = "emp_checks";
//connect to server and select database
$connection = @mysql_connect( "localhost" , "UserName" , "Password" )
or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error() );

//set the username post from login page
$Accessor=$_POST['Accessor'];

// this sets the employee id. 1 if no employee is set
$emp_id = isset($_GET['emp_id']) ? $_GET['emp_id'] : "1";
// check to see if the submit button was pressed
if(isset($_POST['submit'])){
// set the employee id
$id = $_POST['emp_id'];
// change the array to a comma seperated string for storage
$blocks = implode(",", $_POST['grid']);
// check if employee has an entry in the emp_checks table
$check = "SELECT CheckID FROM $check_table WHERE EmpID = '$id'";
$cres = mysql_query($check) or die(mysql_error());
$found = mysql_num_rows($cres);
  if($found > 0){
  // if an employee was found  we update the check boxes
  $update = "UPDATE $check_table SET Blocks = '$blocks' WHERE `EmpID` = '$id'";
  mysql_query($update) or die(mysql_error());
  echo $update;
  } else {
  // If employee was not found we insert the checkboxes
  $insert = "INSERT INTO $check_table (`EmpID`, `Blocks`, `Accessor`) VALUES ('$id', '$blocks', '$Accessor')";
  mysql_query($insert) or die(mysql_error());
  echo $insert;

  }
} else {
//gather data from employee list
$sql = "SELECT ID, Employee_Name, Blocks FROM $employee_table LEFT JOIN $check_table ON `ID` = `EmpID` ORDER BY ID ASC";
$result = mysql_query($sql) or die(mysql_error());

//begin building HTML table
echo '<form action="" method="get">';
echo '<table id="main">';
echo '<tr><td>';
echo '</td></tr>';
<tr id="header"><td></td><td> Welcome $Accessor
</td></tr>
  
  <tr>
    <td>

echo '<table id="employees">
  <tr><th id="employee_header">Select an employee from the current class below</th>
  </tr>
  <tr>
    <td>
    <select name="emp_id" onchange="this.form.submit()" />
    ';
while(list($id,$name) = mysql_fetch_row($result)){
// this will select the current employee in the dropdown box
$selected = $id == $emp_id ? "selected" : "";
    echo '<option value="'.$id.'" '.$selected.' />'.$name.'</option>'."\n";
}
echo '</select>
    </td>
  </tr>
</form>
</table>';
// Get checkboxes from emp_checks table
$ch = "SELECT Blocks FROM $check_table WHERE `EmpID` = '$emp_id'";
$cres = mysql_query($ch) or die(mysql_error());
$c = mysql_fetch_assoc($cres);
// put the comma seperated values in an array
$checks = explode(",", $c['Blocks']);

//Build and issue query
$sql="SELECT * from $grid_name ORDER BY Block";
$result = mysql_query($sql)or die(mysql_error());
// set the block groups
$lastblock = '';
echo '<form action="FU_Results.php" method="POST" name="Grid">
<input type="hidden" name="emp_id" value="'.$emp_id.'" />
<table id="matrix">
  <tr>
    <th colspan="11"> Selling Skills Recommended Follow-up</th>
  </tr>';
while($row = mysql_fetch_assoc($result)){
// if the checkbox is in the array, check off the checkbox
$chk = in_array($row['ID'], $checks) ? "checked" : "";
  // checks to see if the block name has changed, if it has start a new row
    if($row['Block'] != $lastblock){
   echo "<tr><td id='title'>".substr($row['Block'], 1)."</td>";
  }
  echo '<td><input type="checkbox" name="grid[]" value="'.$row['ID'].'" class="inactive" '.$chk.' /></td><td>'.$row['Text'].'</td>';
// set the lastblock to the current block in the loop
$lastblock = $row['Block'];
}
echo '</tr></table>
<div id="submit"><input type="image" src="Submit.png" name="submit" value="submit" alt="submit" /></div></table></td></table>';
//end of HTML table
echo '</td>
  </tr>
</table>
</form>';
}
?>

 

the initial form is for an individual to login, and then when they hit the submit button they should be sent to the assessment page which the code I have above, and welcome, Joe Smith or whatever should be posted at the top of the page. When they click the various text boxes and submit from this page, I was wanting the $Accessor value to be inserted into a field I have set up in the emp_checks table with the name of 'Accessor'. Again this value is originally entered in the login page and carries through to the assessment page and after submittal from the second page is entered into the database.

 

Now my problem is once a name is entered on the login in screen and the submit button is pressed this information is inserted or updated into the emp_blocks table in the database and your not directed to the main page, so obviously something is wrong here!

 

hopefully my explanation makes since and someone can tell me what I am doing worng and why this is happening

 

 

Link to comment
Share on other sites

ok, never mind on the submit button issue with the login page. It was just a matter of changing the name of the submit button to something different on the login page.

 

I still could use some assistance with a page to display after submitting that would display the accessor name and employee name, followed by the results of their submission values.

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.