I have a dynamic table which is filled from an Application.
My problem is that I need some way to freeze the first row and the first four columns BUT using only one table, obviously because I will be posting the table back again to the application.
My Current Table Code :
....
<form name="myform" method="post" action="test123.php" onsubmit="set_value();">
//this form is used to post back the data after user updates it.
<br />
<table align="center" id="dataTable">
<thead>
<tr class="header">
...
$arratt49 = (explode(',',$response49,-1)); //sending an array from application
$dayscounter = sizeof($arratt49);
$sizemon = strlen($month1);
if($sizemon > 0)
{
echo "<th class='text ce6'>No.</th>";
echo "<th class='text ce6'>Emp code</th>";
echo "<th class='text ce6'>Name</th>";
echo "<th class='text ce6'>Department </th>";
for($kkk=0;$kkk<$dayscounter;$kkk++)
{
echo "<th class='text ce7'>";
echo $arratt49[$kkk];
echo "</br>";
echo $arratt49[$kkk+1];
echo "</th>";
$kkk = $kkk +1;
}
}
</tr>
</thead>
<tbody>
<tr>
....//Here goes the Body
for($k=0;$k<=$arrcnt;$k++)
{
echo "<td class='text ce2'>";
echo $counter;
echo "</td>";
echo "<td class='text ce2'><INPUT type='text' name='code[]' size = '8' readonly='true 'value='";
echo $arratt[$k];
echo "'";
echo "</td>";
echo "<td class='text ce2'><INPUT type='text' name='name[]' size = '40' readonly='true' value='";
echo $arratt[$k+1];
echo "'";
echo "</td>";
echo "<td class='text ce2'><INPUT type='text' name='dept[]' size = '12' readonly='true 'value='";
echo $arratt[$k+2];
echo "'>";
echo "</td>";
Already tried :
Big Four method
and also This
Any Good Ideas?
Again I CANNOT use more than one table method.
You can use datatables plugin FixedColumns, just set parameter "iLeftColumns" to the number of columns needed to be fixed from the left side of table. Header already fixed by default.
Related
I have this foreach loop getting my table values... I now want to check if the the column pid row numbers repeats it self $events[12] and if so I want to add a class to the table column <tr> so I can replace the color of all repeating columns so they look liked group together. Here's my page : http://www.toppromomkt.com/?wallet=dezembro-2015
And the code:
//now loop over data instead of mysql_fetch_array
foreach ($data as $events) {
echo '<table id="wallet_table1" width="900px" border="0" cellspacing="2" cellpadding="0">';
?>
<tr id='<?php echo "row".$events[0] ?>' class='<?php echo $events[2] ?>' onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<?php
echo "<td class='tb1'>{$events[0]}</td></div>"; //foto
echo "<td>";
echo "<div class='w_promotora_images'>{$events[7]}</td></div>"; //foto
echo "<td>";
echo "<div class='w_promotora_images'>{$events[3]}</td></div>"; //data
echo "<td class=''>{$events[2]}</td>"; //nome
echo "<td class='sle'>{$events[12]}</td>"; // this the PID i want to check if repeats
echo "<td class=' tb1'>{$events[4]}</td>"; //evento
echo "<td class=' tb1'>{$events[5]}</td>"; //horario
echo "<td class=' tb1'>{$events[6]}</td>"; //obs
echo "<td class=' tb1'>{$events[10]}h</td>"; //horas
echo "<td class=' tb1'>{$events[9]}€</td>"; //valor hora
echo "<td class=' tb1'>{$events[1]}</td>"; //Props
echo "<td class=' tb1'><div class='{$events[2]}'> {$events[8]}</td></div>"; //t parcial ?>
<td class='tbrr'> <?php
$strSQL1 = "SELECT nome, SUM(totalparcial) as Soma FROM bruno_wallet where nome='{$events[2]}' GROUP BY nome";
$rs1 = mysql_query($strSQL1);
$sum1 = 0;
$data1 = array();
while($row2 = mysql_fetch_array($rs1)) {
echo $row2[1]."€";
};
?>
</div> </td></tr>
</table>
What you can do is something like this: Store all PIDs in an array and check every time you loop through the for loop if the current PID is in the array. For example:
$checkedPIDs = array();
foreach ($data as $events) {
$currentPID = $events[12];
if (in_array($currentPID, $checkedPIDs)) {
// Output with different colour...
} else {
array_push($checkedPIDs, $currentPID);
// Output with normal colour...
}
// The rest of your code...
}
Scenario: I have a web form where the user can manually enter data (see below). The user will submit the form and the data will be automatically added to the database.
date, order_ref, first_name, last_name, postcode, country, quantity, scott_packing, packing_price, courier_price, dispatch_type, job_status
On another page, the user will be able to only view all the jobs that are currently being (this data is taken from the database) processed and add the tracking number and edit the packing_price,courier_price and job_status and submit the new data.
http://i754.photobucket.com/albums/xx182/rache_R/Screenshot2014-04-23at104045_zps2a628d50.png
Issue: When the user clicks the 'submit all' button, the user is supposed to be redirected to the thank you page which simply notifies the user that their entry has been successful however at the moment, the user is only directed to a blank page which contains the navigation menu. I have checked the database to see if the data has been updated but nothing has changed. How do i get my update statement to work so that the user can update the existing jobs?
This is the code for the page that displays all the jobs:
<?
session_start();
if(!session_is_registered(myusername))
{
header("location:../index.php");
}
include("../template/header.php");
include("../controllers/cn.php");
$sql = "SELECT * FROM Jobs";
$qry = mysql_query($sql);
echo "<div class='content'>";
echo "<form class='form_edit' method='post' action='updatejob.php'>";
echo "<table id='job_list' cellpadding='0' cellspacing='0'>
<tr>
<th>Job No</th>
<th>Date</th>
<th>Qty</th>
<th>Postcode</th>
<th>Country</th>
<th>Packed by Scott</th>
<th>Packing Price</th>
<th>Courier Price</th>
<th>Tracking No</th>
<th>Dispatch Type</th>
<th>Job Status</th>
</tr>";
while($row = mysql_fetch_array($qry))
{
echo "<tr>";
echo "<td width='80' style='text-align: center;'>" . $row['order_ref'] . "</td>";
echo "<td width='100' style='text-align: center;'>" . $row['date'] . "</td>";
echo "<td width='100' style='text-align: center;'>" . $row['quantity'] . "</td>";
echo "<td width='100' style='text-align: center;'>" . $row['postcode'] . "</td>";
echo "<td width='100' style='text-align: center;'>" . $row['country'] . "</td>";
echo "<td width='100' style='text-align: center;'><input type='CHECKBOX' id='scott_packing' name='scott_packing' value='". $row['scott_packing'] . "'></td>";
echo "<td width='100' style='text-align: center;'><input type='text' id='packing_price' name='packing_price' value='". $row['packing_price'] . "'/></td>";
echo "<td width='100' style='text-align: center;'><input type='text' id='courier_price' name='courier_price' value='". $row['courier_price']."'/></td>";
echo "<td width='100' style='text-align: center;'><input type='text' id='tracking_number' name='tracking_number' value='". $row['tracking_number'] . "'/></td>";
echo "<td width='100' style='text-align: center;'>" . $row['dispatch_type'] . "</td>";
echo "<td width='100' style='text-align: center;'><select name='job_status' id='job_status'>
<option value='". $row['job_status'] ."'>". $row['job_status']. " <option value='dispatched'>Dispatched</td>";
//echo "<td width='100' style='text-align: center;'><a href='editjob.php'>edit</td>";
echo "</tr>";
}
echo "</table>";
echo "<input type='submit' name='submit' value='submit all'/>";
echo "</form>";
mysql_close();
?>
And here is the code that is supposed to update the data:
<?
session_start();
if(!session_is_registered(myusername)){
header("location:../index.php");
}
include("../template/header.php");
include("../controllers/cn.php");
if (isset($_POST['submit']))
{
$order_ref = $_POST['order_ref'];
$packing_price = $_POST['packing_price'];
$courier_price = $_POST['courier_price'];
$tracking_number = $_POST['tracking_number'];
$job_status = $_POST['job_status'];
$sql_qry = "UPDATE Jobs SET '$packing_price, $courier_price, $tracking_number, $job_status' WHERE order_ref = '$order_ref'";
$query = mysql_query($sql_query);
if(!$query)
{
die('Could not update data' .mysql_error());
} else
{
header("location: updatesuccess.php");
exit;
}
mysql_close();
}
?>
Your update query is wrong. The query of update should be like
UPDATE table_name SET field1=new-value1, field2=new-value2
[WHERE Clause]
In this case it will be something like
UPDATE Jobs SET packing_price='$packing_price',courier_price='$courier_price',tracking_number='$tracking_number',job_status='job_status' WHERE order_ref = '$order_ref'";
and also you missed out the name property for input fields. If you don't specify it you can't access it like $_POST['packing_price'] where packing_price is be the name of the input field.
Also add method="post" to the form like
echo "<form class='form_edit' action='updatejob.php' method='post'>";
Try with this query
$sql_qry = "UPDATE Jobs SET column1 = '$packing_price', column2 ='$courier_price', .... WHERE order_ref = '$order_ref'";
And like Roland Jansen stated you are missing the name attributes on your input tags
I am trying to make a table in PHP.
All things are fine but all the rows are printed in same line.
How to print new line after each row in table? But in html there is no need to write extra code for new line why it is showing not a new line with PHP?
Here is that part of code:
<div class="contest-table" id="contest-table">
<table class="contest-details" id="contest-details">
<tr>
<th>CODE</th>
<th>NAME</th>
<th>START</th>
<th>END</th>
</tr>
<?php
//Show contest detials -> Contest Code|Contest Name |Start Date | End Date
$con=mysqli_connect("localhost","root","chandan","judge");
$result=mysqli_query($con,"SELECT * FROM judge_contest ");
echo "<tr>";
while($row = mysqli_fetch_array($result))
{
$contest_code=$row['contest_code'];
$contest_name=$row['contest_name'];
$contest_start_date=$row['start_date'];
$contest_end_date=$row['end_date'];
echo "<td>";
echo " $contest_code ";
echo "</td>";
echo "<td>";
echo " $contest_name ";
echo "</td>";
echo "<td>";
echo $contest_start_date;
echo "</td>";
echo "<td>";
echo $contest_end_date;
echo "</td>";
}
echo "</tr>";
?>
</table>
</div>
The problem is obvious, because you have put the statement echo "<tr>" and echo "</tr>" outside the while loop. You should put these two statement into the while loop.
echo '<tr>'
and
echo '</tr>'
should be inside the wile loop
Well, I've following Php code which generate a table with radio button so that user can select only one radio button in EVERY row. But to select only one radio button in Every row it's must be a unique name in EVERY row, Right ? But I can't get any idea how do i set a unique name in while loop. Can you guys give me any idea or solutions ?
Php code:
$action = htmlspecialchars($_SERVER['PHP_SELF'])."?class=$class_from";
echo "<form method='post' action='$action' name='attendence'/>";
echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>";
echo "<tr>";
echo "<td class='tdhead' valign='top' width='200'><b>Student Name</b></td>";
echo "<td class='tdhead' valign='top' width='250'><b>Roll No</b>
</td>";
echo "<td class='tdhead' valign='top' width='250'><b>Class Name</b>
</td>";
echo "<td class='tdhead' valign='top' width='200'><b>Present / Not present</b>
</td>";
echo "<td class='tdhead' valign='top' width='200'>Check All <input type= 'checkbox'
onclick='checkAll(this)' /></td>";
echo "</tr>";
while($res2 = mysql_fetch_array($sql2))
{
$sname = inputvalid($res2['sname']);
$roll = inputvalid($res2['roll']);
$class = inputvalid($res2['class']);
echo "<tr>";
echo "<td class='tdhead2' valign='top'>$sname</td>";
echo "<td class='tdhead2' valign='top'>$roll</td>";
echo "<td class='tdhead2' valign='top'>$class</td>";
echo "<td class='tdhead2' valign='top'>
<input type='radio' name='ch[]' value='1' /> <input type='radio' name='ch[]'
value='1' />
</td>";
echo "<td class='tdhead2' valign='top'> </td>";
echo "</tr>";
}
echo "<tr>";
echo "<td class='tdhead2'> </td>";
echo "<td class='tdhead2'> </td>";
echo "<td class='tdhead2'> </td>";
echo "<td class='tdhead2'> </td>";
echo "<td class='tdhead2'><input type='submit' value='Record' name='Submit'
class='submit' /></td>";
echo "</tr>";
echo "</table>";
echo "</form>";
Thanks for your help.
Update:
echo "<td class='tdhead2' valign='top'>";
echo '<input type="radio" name="ch'.$counter++.'[]" value="1">';
echo " ";
echo '<input type="radio" name="ch'.$counter.'[]" value="0">';
echo "</td>";
you can set a variable counter:
$counter = 1;
while($res2 = mysql_fetch_array($sql2)){
echo '<input type="radio" name="ch'.$counter++.'[]" value="'.$counter++.'">';
}
Instead of making the name just ch[] you can make the name ch[SOME_UNIQUE_VALUE] for each row. Usually something like an id number is used. Perhaps $roll if that is unique to each student. That will also allow you to know which id the radio button pertains to. On form submit, you can foreach($_POST['ch'] as $id=>$value) and get the id out.
Edit:
Example code:
//start the counter variable
$counter = 1;
while($res2 = mysql_fetch_array($sql2))
{
$sname = inputvalid($res2['sname']);
$roll = inputvalid($res2['roll']);
$class = inputvalid($res2['class']);
echo "<tr>";
echo "<td class='tdhead2' valign='top'>$sname</td>";
echo "<td class='tdhead2' valign='top'>$roll</td>";
echo "<td class='tdhead2' valign='top'>$class</td>";
echo "<td class='tdhead2' valign='top'>";
//echo each radio with the counter for this row
echo "<input type='radio' name='ch_{$counter}[]' value='0' /> ";
echo "<input type='radio' name='ch_{$counter}[]' value='1' />";
echo "</td>";
echo "<td class='tdhead2' valign='top'> </td>";
echo "</tr>";
//add one to the counter
$counter++;
}
Please note, unless you do like I suggested above, you will not be able to know which student each radio group goes to. You can assume that the radio buttons on group row 1 belongs to the student in row 1, but you might not know which student is in row 1. Which is why I suggest you put a unique id that goes with each student with each radio button instead of a counter.
You can store a counter $count and increase it after each iteration. Or if you have some unique id from the database per row (for example the primary_key), you can use that instead.$id = $res['id']
Then concat that value to the name=ch".$id."...
you should use student name as an unique array and put that value in the name=""
and it will auto increment according to the name and you can only choose single option at single row.
try this :
<input type='radio' name='<?php echo $res2['sname'];?>' value='0' /> ";
<input type='radio' name='<?php echo $res2['sname'];?>' value='1' />";
this solutio will work.because it work's for me in an attendance system.
I am a few stages further in learning PHP but I have come to another annoying pit stop. I have a really simple bit of code that retrieves book items from my database. I am displaying them in an html table however because it is a loop, if I use the th tags for table header I get a header above every single data item!
Here is my code extract: (as you can see I have put my th tags as comments as that doesn't work)
<table border="0">
<br />
<?php
$count = 0;
while ($count < $numrow)
{
$row = mysql_fetch_array($results);
extract($row);
echo "<tr>";
//echo "<tr>";
//echo "<th>";
//echo "Book Title";
//echo "</th>";
//echo "<th>";
//echo "Book Author";
//echo "</th>";
//echo "<th>";
//echo "Book Publisher";
//echo "</th>";
//echo "<th>";
//echo "Book ISBN";
//echo "</th>";
//echo "</tr>";
echo "<td>";
echo "<a href='addtolist.php? bookname=".$bookname."&bookauthor=".$bookauthor."&bookpub=".$bookpub."&bookisbn=".$bookisbn."'>[+]</a>";
echo "</td>";
echo "<td>";
echo $bookname;
echo "</td>";
echo "<td>";
echo $bookauthor;
echo "</td>";
echo "<td>";
echo $bookpub;
echo "</td>";
echo "<td>";
echo $bookisbn;
echo "</td>";
echo "<td>";
echo "<a href='deletecd.php?bookname=".$bookname."'>Delete</a>";
echo "</td>";
echo "</tr>";
$count = $count + 1;
}
?>
Move those echos out of your loop. Also, you shouldn't have a <br /> directly inside of a <table> tag.
Move your table header code outside of the loop.
IDIOT! Sorry guys....
Needed to put the th tags outside of the loop.... simple I know but easy to miss when your learning!
[=
Simply take the header outside the loop, so echo before you begin your loop but after the opening<table>
You have to move the headers above the loop:
<table border="0">
<tr>
<th>Book Title</th>
<th>Book Author</th>
<th>Book Publisher</th>
<th>Book ISBN</th>
</tr>
<?php
$count = 0;
while ($count < $numrow)
{
$row = mysql_fetch_array($results);
extract($row);
echo "<tr>"
echo "<td>";
echo "<a href='addtolist.php? bookname=".$bookname."&bookauthor=".$bookauthor."&bookpub=".$bookpub."&bookisbn=".$bookisbn."'>[+]</a>";
echo "</td>";
echo "<td>";
echo $bookname;
echo "</td>";
echo "<td>";
echo $bookauthor;
echo "</td>";
echo "<td>";
echo $bookpub;
echo "</td>";
echo "<td>";
echo $bookisbn;
echo "</td>";
echo "<td>";
echo "<a href='deletecd.php?bookname=".$bookname."'>Delete</a>";
echo "</td>";
echo "</tr>";
$count = $count + 1;
}
?>
<table border="0">
<tr>
<th>Book Title</th>
<th>Book Author</th>
<th>Book Publisher</th>
<th>Book ISBN</th>
</tr>
<?php
$count = 0;
while ($count < $numrow)
{
$row = mysql_fetch_array($results);
extract($row);
echo "<tr>";
echo "<td>";
...
What is static, stays static.
Wjat is dynamic, becomes PHP