How to add rowspan/colspan from phpexcel view table in html ?
I have this table.
I want to view that excel in html using PHPexcel View
but what i got is just like,
The first column was not merged with the second column.
Does anyone know how to add rowspan in phpexcel view in html ?
My code is just like this
$tmpfname = "./sampleData/member.xls";
$excelObj = $excelReader->load($tmpfname);
$worksheet = $excelObj->getActiveSheet();
$worksheet->mergeCells('A1:A3');
$cell = $worksheet->getCell('A1');
$lastRow = $worksheet->getHighestRow();
echo '<table border="1" >';
for ($row = 1; $row <= $lastRow; $row++) {
echo "<tr><td>";
echo $worksheet->getCell('A'.$row)->getValue();
echo "</td><td>";
echo $worksheet->getCell('B'.$row)->getValue();
echo "</td><td>";
echo $worksheet->getCell('C'.$row)->getValue();
echo "</td><td>";
echo $worksheet->getCell('D'.$row)->getValue();
echo "</td><td>";
echo $worksheet->getCell('E'.$row)->getValue();
echo "</td><td>";
echo $worksheet->getCell('F'.$row)->getValue();
echo "</td><td>";
echo $worksheet->getCell('G'.$row)->getValue();
echo "</td><td>";
echo $worksheet->getCell('J'.$row)->getValue();
echo "</td><td>";
echo $worksheet->getCell('K'.$row)->getValue();
echo "</td><td>";
echo $worksheet->getCell('L'.$row)->getValue();
echo "</td><td>";
echo $worksheet->getCell('M'.$row)->getValue();
echo "</td><td>";
echo $worksheet->getCell('N'.$row)->getValue();
echo "</td><td>";
echo $worksheet->getCell('O'.$row)->getValue();
echo "</td><tr>";
}
echo "</table>";
Probably you can use createWriter for creating HTML table from phpExcelObject.
$objWriter = $this->get('phpexcel')->createWriter($phpExcelObject, 'HTML');
ob_start();
$objWriter->save('php://output');
$excelOutput = ob_get_clean();
echo $excelOutput;
Related
I want to skip one record from mysql using php when that record match with a variable value.
The $row['uni_id'] is id in a row of my database table and $_SESSION['uid'] stores a id in session. When the ids match, that record should be skipped. But it's not working. Do you see the issue?
while($row = mysql_fetch_array($res,MYSQL_ASSOC )){
if ($row['uni_id'] == $_SESSION['uid']){
continue;
}
$_SESSION['new_img']=$row['pic_add'];enter code here
$image= $row['pic_add'];
echo "<tr><td>";
echo "{$row['fname']} {$row['lname']}";
echo "</td><td>";
echo $row['street'];
echo "</td><td>";
echo $row['city'];
echo "</td><td>";
}
mysql_free_result($res);
Can you try the below code ?
<?php
while($row = mysql_fetch_array($res,MYSQL_ASSOC )){
if ($row['uni_id'] != $_SESSION['uid']){
$_SESSION['new_img'] = $row['pic_add'];
$image= $row['pic_add'];
echo "<tr><td>";
echo "{$row['fname']} {$row['lname']}";
echo "</td><td>";
echo $row['street'];
echo "</td><td>";
echo $row['city'];
echo "</td><td>";
}
}
mysql_free_result($res);
?>
I think you are using condition in a wrong manner.
Below code might help you.
while($row = mysql_fetch_array($res,MYSQL_ASSOC )){
if ($row['uni_id'] == $_SESSION['uid']){
// do nothing
}
else{
$_SESSION['new_img']=$row['pic_add'];
$image= $row['pic_add'];
echo "<tr><td>";
echo "{$row['fname']} {$row['lname']}";
echo "</td><td>";
echo $row['street'];
echo "</td><td>";
echo $row['city'];
echo "</td><td>";
}
}
mysql_free_result($res);
You should adjust your MySQL query before you start processing the result in PHP.
The solution will depend on your query. If your query is something like this:
select * from table
You should update it to:
select * from table WHERE uid <> "$_SESSION['uid']"
If you cannot control the MySQL query, then you can change your PHP code:
while($row = mysql_fetch_array($res,MYSQL_ASSOC )){
if ($row['uni_id'] != $_SESSION['uid']){
$_SESSION['new_img']=$row['pic_add'];enter code here
$image= $row['pic_add'];
echo "<tr><td>";
echo "{$row['fname']} {$row['lname']}";
echo "</td><td>";
echo $row['street'];
echo "</td><td>";
echo $row['city'];
echo "</td><td>";
}
}
mysql_free_result($res);
Try this
while($row = mysql_fetch_array($res,MYSQL_ASSOC )){
if ($row['uni_id'] != $_SESSION['uid']){
$_SESSION['new_img']=$row['pic_add'];
$image= $row['pic_add'];
echo "<tr><td>";
echo "{$row['fname']} {$row['lname']}";
echo "</td><td>";
echo $row['street'];
echo "</td><td>";
echo $row['city'];
echo "</td><td>";
}
}
mysql_free_result($res);
while($row = mysql_fetch_array($res,MYSQL_ASSOC )){
if ($row['uni_id'] !== $_SESSION['uid']){
$_SESSION['new_img']=$row['pic_add'];
$image= $row['pic_add'];
echo "<tr><td>";
echo "{$row['fname']} {$row['lname']}";
echo "</td><td>";
echo $row['street'];
echo "</td><td>";
echo $row['city'];
echo "</td><td>";
}
}
mysql_free_result($res);
NOTE: Do not use mysql. Its deprecated. Use PDO.
Try this code fragment
while($row = mysql_fetch_array($res))
{
$t='';
if($row['uni_id'] != $_SESSION['uid'])
{
$_SESSION['new_img']=$row['pic_add'];//enter code here
$image= $row['pic_add'];
$t.="<tr>";
$t.="<td>{$row['fname']} {$row['lname']}</td>";
$t.="<td>".$row['street']."</td>";
$t.="<td>".$row['city']."</td>";
$t.="</tr>";
}
echo $t;
}
mysql_free_result($res);
I have a web page where I am pulling data from a mysql database and I want to be able to check a checkbox and change information within the table. The way I am displaying the information is as follows:
<?php
$get_tickets = mysql_query("SELECT * FROM assignment
JOIN technician
ON assignment.TechID = technician.TechID
JOIN employee
ON assignment.EID = employee.EID
JOIN ticket
ON assignment.TickID = ticket.TickID
WHERE assignment.TechID = '$current_id'");
echo "<table border='1' width=\"100%\" style=\"margin: 0px;\">";
echo "<tr><td>Ticket Number</td>";
echo "<td>First Name</td>";
echo "<td>Last Name</td>";
echo "<td>Phone</td>";
echo "<td>Device</td>";
echo "<td>Location</td>";
echo "<td>Problem</td>";
echo "<td>Time Stamp</td>";
echo "<td>Completed</td>";
echo '<td><form><input type="checkbox"/></form></td></tr>';
while($row2 = mysql_fetch_array($get_tickets))
{
$count = 1;
$checkbox = "checkbox" . $count;
echo "<tr><td>";
echo $row2["TickID"];
echo "</td><td>";
echo $row2["fname"];
echo "</td><td>";
echo $row2["lname"];
echo "</td><td>";
echo $row2["phone"];
echo "</td><td>";
echo $row2["device"];
echo "</td><td>";
echo $row2["location"];
echo "</td><td>";
echo $row2["problem"];
echo "</td><td>";
echo $row2["time_date"];
echo "</td><td>";
echo $row2["completed"];
echo "</td><td>";
echo '<form><input type="checkbox" name=' . $row2["TickID"] . '></form>';
echo "</td></tr>";
}
?>
There may be better ways to ouput the information, but I just want to be able to click the checkbox and take the data from the row associated with the checkbox and change part of it. Any help is greatly appreciated.
try to change this:
echo '<form><input type="checkbox" name=' . $row2["TickID"] . '></form>';
for this:
echo ''.$row2["fname"].'';
on the file process.php you will get the variable like this
<?php
echo $_GET['id'];
?>
How do I stop the results from getting displayed twice on the web page? What have I done wrong? Yes this is for a game but it helps me learn SQL and PHP. Please be genital it's my first time.
There is one database with two tables. The database is game_tittle the two tables are player_data and the second is character_data.
<?php
include('db_conn.php');
#for connecting to SQL
$sqlget = "SELECT player_data.PlayerName, Character_data.Duration, character_data.KillsZ, character_data.KillsB, character_data.KillsH, character_data.HeadshotsZ, character_data.Humanity, character_data.Generation, character_data.InstanceID FROM player_data, character_data";
$sqldata = mysqli_query($dbcon, $sqlget) or die('error getting data');
echo "<center><table>";
echo "<tr> <th>Player Name</th><th>play time</th><th>Total Kills</th><th>Bandit kills</th><th>Hero Kills</th><th>Head shots</th><th>Humanity</th><th>Alive count</th><th>Instance ID</tr>";
while ($row = mysqli_fetch_array($sqldata)) {
echo "<tr><td>";
echo $row['PlayerName'];
echo "</td><td>";
echo $row['Duration'];
echo "</td><td>";
echo $row['KillsZ'];
echo "</td><td>";
echo $row['KillsB'];
echo "</td><td>";
echo $row['KillsH'];
echo "</td><td>";
echo $row['HeadshotsZ'];
echo "</td><td>";
echo $row['Humanity'];
echo "</td><td>";
echo $row['Generation'];
echo "</td><td>";
echo $row['InstanceID'];
echo "</td></tr>";
echo "</center>";
}
echo "</table>";
#end of table
?>
Got it to work this way.
<?php
include('db_conn.php');
$sqlget = "SELECT player_data.PlayerUID, character_data.PlayerUID, player_data.PlayerName, character_data.HeadshotsZ, character_data.KillsZ, character_data.KillsH, character_data.KillsB, character_data.Alive, character_data.Generation, character_data.Humanity, character_data.InstanceID FROM player_data INNER JOIN character_data ON player_data.PlayerUID = character_data.PlayerUID";
$sqldata = mysqli_query($dbcon, $sqlget) or die('error getting data');
echo "<center><table>";
echo "<tr> <th>Player Name</th><th>Head shots</th><th>Total Kills</th><th>Hero kills</th><th>Bandit Kills</th><th>Live or dead</th><th>Lifes</th><th>Humanity</th><th>Instance ID</tr>";
while ($row = mysqli_fetch_assoc($sqldata)) {
echo "<tr><td>";
echo $row['PlayerName'];
echo "</td><td>";
echo $row['HeadshotsZ'];
echo "</td><td>";
echo $row['KillsZ'];
echo "</td><td>";
echo $row['KillsH'];
echo "</td><td>";
echo $row['KillsB'];
echo "</td><td>";
echo $row['Alive'];
echo "</td><td>";
echo $row['Generation'];
echo "</td><td>";
echo $row['Humanity'];
echo "</td><td>";
echo $row['InstanceID'];
echo "</td></tr>";
echo "</center>";
}
echo "</table>";
#end of table
?>
Bug in your SQL-query: You forgot to join the tables with a "where"-clause.
I have a table of data that includes picture and video which the files are saved in Eventpic folder in my localhost, I need the picture and video in table to show the file when user clicked on them; this code refer to the eventpic not each individual pic.
$sqlget="SELECT * FROM eventform";
$sqldata=mysqli_query($con,$sqlget)
or die("Error Getting Data");
echo "<table border=2 bordercolor=#440000 cellpadding=2 bgcolor=#DDDDDD width=100%>";
echo "<tr bgcolor=#555555 style=font-size:18px><th>Event Code</th><th>Event Name</th><th>Event Type</th><th>Event Level</th><th>Start Date</th>
<th>End Date</th><th>Point</th><th>Picture</th><th>Video</th><th>Description</th></tr>";
while($row=mysqli_fetch_array($sqldata, MYSQLI_ASSOC)){
echo "<tr align=center><td>";
echo $row['event_code'];
echo "</td><td>";
echo $row['event_name'];
echo "</td><td>";
echo $row['event_type'];
echo "</td><td>";
echo $row['event_level'];
echo "</td><td>";
echo $row['start_date'];
echo "</td><td>";
echo $row['end_date'];
echo "</td><td>";
echo $row['points'];
echo "</td><td>";
echo "<a href=http://localhost/greenstudio/eventpic/>".$row['pic']."</a>"; >>> PRoblem is here
echo "</td><td>";
echo $row['video'];
echo "</td><td>";
echo $row['description'];
echo "</td></tr>";
}
echo "</table>";
?>
======My table =====
$pic= ($_FILES['pic']);
$temp_pic=($_FILES["pic"]["tmp_name"]);
$pic_type=($_FILES["pic"]["type"]);
$pic_name=($_FILES["pic"]["name"]);
$pic_size=($_FILES["pic"]["size"]);
$pic_error=($_FILES["pic"]["error"]);
$temp_video=($_FILES["video"]["tmp_name"]);
$video_type=($_FILES["video"]["type"]);
$video_name=($_FILES["video"]["name"]);
$video_size=($_FILES["video"]["size"]);
$video_error=($_FILES["video"]["error"]);
$uploads_dir_pic = "eventpic/".$pic_name;
$uploads_dir_video="videos/".$video_name;
if($pic_size>1000000){
die ("The size of the pic is too big");
}
if($video_size>5000000){
die ("The size of the video is too big");
}
move_uploaded_file($temp_pic,$uploads_dir_pic);
$path_pic=($uploads_dir_pic);
}
move_uploaded_file($temp_video,$uploads_dir_video);
$path_video=($uploads_dir_video);
INSERT $path_pic & $path-video in database
Can you try this,
echo "<a href='http://localhost/greenstudio/eventpic/".$row['pic']."' >".$row['pic']."</a>";
OR
echo "<a href='eventpic/".$row['pic']."' >".$row['pic']."</a>";
create a separate script that loads the image from the database
Set header for image
header("Content-type: image/png");
Here's something similar How to retrieve images from MySQL database and display in an html tag
I would like to insert a new random image in a row (all by itself) after 10 rows of data have been populated.
I'm thinking I should input something like this:
if($counter % 10 == 0) {
echo 'image file';
}
But not really sure how to incorporate this in my code:
echo "<table border='1' CELLPADDING=5 STYLE='font-size:13px'>";
echo "<tr> <td><H3>No.</H3></td><td><H3>Date</H3></td>";
echo "<td><H3>First Name</H3></td> <td><H3>Last Name</H3></td>";
echo "<td><H3>City</H3></td><td><H3>Province</H3></td></tr>";
//declaring counter
$count=0;
// keeps getting the next row until there are no more to get
while ($row = mysql_fetch_array( $data, MYSQL_ASSOC )) {
//counter equals
$count=$count+1;
// Print out the contents of each row into a table
echo "</td><td>";
echo $count;
echo "</td><td>";
echo $row['DateIn'];
echo "</td><td>";
echo $row['FirstName'];
echo "</td><td>";
echo $row['LastName'];
echo "</td><td>";
echo $row['City'];
echo "</td><td>";
echo $row['Province_State'];
echo "</td></tr>";
}
echo "</table>";
echo "<table border='1' CELLPADDING=5 STYLE='font-size:13px'>";
echo "<tr> <td><H3>No.</H3></td><td><H3>Date</H3></td><td><H3>First Name</H3></td> <td> <H3>Last Name</H3></td> <td><H3>City</H3></td><td><H3>Province</H3></td></tr>";
//declaring counter
$count=0;
// keeps getting the next row until there are no more to get
while ($row = mysql_fetch_array( $data, MYSQL_ASSOC )) {
//counter equals
$count++;
//insert an image every 10 rows
if($count==10){
$count=0;
echo 'yourimage.jpg';
}
// Print out the contents of each row into a table
echo "</td><td>";
echo $count;
echo "</td><td>";
echo $row['DateIn'];
echo "</td><td>";
echo $row['FirstName'];
echo "</td><td>";
echo $row['LastName'];
echo "</td><td>";
echo $row['City'];
echo "</td><td>";
echo $row['Province_State'];
echo "</td></tr>";
}
echo "</table>";
if($counter % 10 == 0) {
echo 'image file';
}
10, not 100 :). Put this after your $count=$count+1 statement in a td colspan=however many columns you have.
Thanks to the help of Here is the completed code that works (however, I still can't get the random image to show, but I can get an image :-)
echo "<table border='1' CELLPADDING=5 STYLE='font-size:13px'>";
echo "<tr> <td><H3>No.</H3></td><td><H3>Date</H3></td><td><H3>First Name</H3></td> <td><H3>Last Name</H3></td> <td><H3>City</H3></td><td><H3>Province</H3></td></tr>";
//declaring counter for data
$count=0;
//declaring counter for random image
$counter_for_image=0;
// keeps getting the next row until there are no more to get
while ($row = mysql_fetch_array( $data, MYSQL_ASSOC )) {
//counter for actual count
$count=$count+1;
//counter for image count
//so I can reset count and
//not affect actual count
$counter_for_image++;
/* does not work
// start random image code
$images = array(
0 => '1.jpg',
1 => '2.jpg',
);
$image = $images[ rand(0,(count($images)-1)) ];
$randomimage = "<img src=\"/http://wwww.my site.com/storm/images/".$image."\" alt=\"\" border=\"0\" />";
//print($output);
// end random image code
*/
// start every 10th row image display code
if($counter_for_image==10){
$counter_for_image=0;
echo '<tr><td colspan="6"><center><img src="http://www.mysite.com/storm/images/eric.jpg"/></center></td></tr>';
/* would use this if I could get random image to work
echo '<tr><td colspan="6"><center>';
print($randomimage);
echo '</center></td></tr>';
*/
} // end every 10th row image display code
// Print out the contents of each row into a table
echo "</td><td>";
echo $count;
echo "</td><td>";
echo $row['DateIn'];
echo "</td><td>";
echo $row['FirstName'];
echo "</td><td>";
echo $row['LastName'];
echo "</td><td>";
echo $row['City'];
echo "</td><td>";
echo $row['Province_State'];
echo "</td></tr>";
}
echo "</table>";