How can I add a link to a table in Smarty? - php

I have a requirement to output a table using Smarty and then have the user select a row to take them to another page.
I can display the table fine:
{html_table cols="Job Title,Salary,Sector,Location" loop=$results}
which gives:
<table border="1">
<thead>
<tr>
<th>Job Title</th>
<th>Salary</th>
<th>Sector</th>
<th>Location</th>
</tr>
</thead>
<tbody>
<tr>
<td>Dog walker</td>
<td>20000</td>
<td>None</td>
<td>London</td>
</tr>
<tr>
<td>F1 Driver</td>
<td>10000000</td>
<td>Financial Services</td>
<td>Scotland</td>
</tr>
</tbody>
</table>
but I am not sure if it is possible to add a hyperlink as an additional column to the table that links to a page using a hidden id.
So I would want something link this:
<table border="1">
<thead>
<tr>
<th>Job Title</th>
<th>Salary</th>
<th>Sector</th>
<th>Location</th>
<th>Apply</th>
</tr>
</thead>
<tbody>
<tr>
<td>Dog walker</td>
<td>20000</td>
<td>None</td>
<td>London</td>
<td>Apply</td>
</tr>
<tr>
<td>F1 Driver</td>
<td>10000000</td>
<td>Financial Services</td>
<td>Scotland</td>
<td>Apply</td>
</tr>
</tbody>
</table>
Is that possible?

Yes, but you need to modify the $results array before you pass it to Smarty so that the 4th element of each row contains the link as a string. There's no way to have {html_table} generate the link for you.

Related

Dynamic table not displaying on mobile device.. similar static data does?

I'm running into an issue where a dynamically created table in PHP, echo'd in the body of the HTML tag, is not displaying at all on my mobile device. The same information is displayed correctly on my PC.
If I take the output from PHP in text form and paste it into the HTML portion, then the table displays correctly, in both my mobile and desktop environments.
For example, the following will display correctly in both my mobile and desktop environments.
<table class="table table-striped table-sm text-nowrap">
<thead>
<tr>
<th scope="col">Class</th>
<th scope="col">Heading</th>
<th scope="col">Heading</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Default</th>
<td>Cell</td>
<td>Cell</td>
</tr>
<tr class="table-primary">
<th scope="row">Primary</th>
<td>Cell</td>
<td>Cell</td>
</tr>
<tr class="table-secondary">
<th scope="row">Secondary</th>
<td>Cell</td>
<td>Cell</td>
</tr>
</tbody>
</table>
As an example, the following will only display on my desktop correctly.
<?php
$_tble = ' <tr>
<th scope="row">Default</th>
<td>Cell</td>
<td>Cell</td>
</tr>
<tr class="table-primary">
<th scope="row">Primary</th>
<td>Cell</td>
<td>Cell</td>
</tr>
<tr class="table-secondary">
<th scope="row">Secondary</th>
<td>Cell</td>
<td>Cell</td>
</tr>';
?>
<table class="table table-striped table-sm text-nowrap">
<thead>
<tr>
<th scope="col">Class</th>
<th scope="col">Heading</th>
<th scope="col">Heading</th>
</tr>
</thead>
<tbody>
<?php echo $_tble; ?>
</tbody>
</table>
Does anyone have any suggestion or ideas as to why this might be happening??
Using - Bootstrap 4.3, php 7.2.33
This originally appeared to be an issue with the creation of the table in PHP but ultimately turned out to be an issue with the $sql used to build the table.
The $sql was handled differently in different browsers. Inadvertently a TABLE name in the query was coded in upper case which correctly ran in IE/Firefox but not in IOS/Chrome.
For example:
Select * FROM TABLE1;
should have been written
Select * FROM table1;

Datatable Column Exceeds

I got a huge dataset with around 39 columns. Now the datatable exceeds the display area of the browser.
No problem with rows is they are listed based on pagination. Is there any wrapping property to datatables? I want to display all columns in the same browser space
My datatable columns are
<table id='datatable' class="ui celled table" style='width:100%'>
<thead>
<tr>
<th>DeviceID</th>
<th>AppID</th>
<th>IsFingerprint</th>
<th>CurrentDate</th>
<th>IsSDCard</th>
<th>NetworkType</th>
<th>TotalRAM</th>
<th>AvailInternal</th>
<th>AvailExternal</th>
<th>TotalInternal</th>
<th>TotalExternal</th>
<th>Activity</th>
<th>Package</th>
<th>AppStore</th>
<th>AppName</th>
<th>AppVersion</th>
<th>AppVersionCode</th>
<th>BatteryCharge</th>
<th>IsCharging</th>
<th>Manufacturer</th>
<th>Model</th>
<th>OSCodename</th>
<th>OSVersion</th>
<th>Product</th>
<th>Device</th>
<th>Board</th>
<th>Hardware</th>
<th>Rooted</th>
<th>Brand</th>
<th>Host</th>
<th>Time</th>
<th>User</th>
<th>ScreenResolution</th>
<th>ScreenDensity</th>
<th>ScreenSize</th>
<th>Country</th>
<th>Carrier</th>
<th>ActiveTraffic</th>
<th>AppUsage</th>
<th>Image</th>
</tr>
</thead>
<tfoot>
<tr>
<th>DeviceID</th>
<th>AppID</th>
<th>IsFingerprint</th>
<th>CurrentDate</th>
<th>IsSDCard</th>
<th>NetworkType</th>
<th>TotalRAM</th>
<th>AvailInternal</th>
<th>AvailExternal</th>
<th>TotalInternal</th>
<th>TotalExternal</th>
<th>Activity</th>
<th>Package</th>
<th>AppStore</th>
<th>AppName</th>
<th>AppVersion</th>
<th>AppVersionCode</th>
<th>BatteryCharge</th>
<th>IsCharging</th>
<th>Manufacturer</th>
<th>Model</th>
<th>OSCodename</th>
<th>OSVersion</th>
<th>Product</th>
<th>Device</th>
<th>Board</th>
<th>Hardware</th>
<th>Rooted</th>
<th>Brand</th>
<th>Host</th>
<th>Time</th>
<th>User</th>
<th>ScreenResolution</th>
<th>ScreenDensity</th>
<th>ScreenSize</th>
<th>Country</th>
<th>Carrier</th>
<th>ActiveTraffic</th>
<th>AppUsage</th>
<th>Image</th>
</tr>
</tfoot>
</table>
I use AJAX to load data from my PHP API endpoint and it works fine.
Is there any way to merge cells like AppName, AppPackage, AppVersion, AppVersionCode comes under App cell

laravel 5.4 table guidance needed

Hello i am a laravel beginner , when i do foreach its shows double of all single items what should i do with it code and ss are below
Brower image
code
<div >
<h1 style="text-align: center">Lists of Outlets</h1>
#foreach($outlets as $outlet)
<table class="table table-striped">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john#example.com</td>
</tr>
</tbody>
</table>
#endforeach
</div>
The issue is, you have put the entire table inside the loop, which is wrong. You have to only put the tr inside the loop.
Try this:
#foreach($outlets as $outlet)
<tr>
<td>John</td>
<td>Doe</td>
<td>john#example.com</td>
</tr>
#endforeach
and one more thing, you are also using the static content inside the loop instead of using the loop variable value. So instead of:
<td>john#example.com</td>
it is something like:
<td>{{ $outlet['name'] }}</td> <!-- where name is the index in outlet array -->
#foreach should be inside <tbody> and instead of hard-coded content, you should be using $outlet variable to get firstname, lastname and Email:
<div>
<h1 style="text-align: center">Lists of Outlets</h1>
<table class="table table-striped">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
#foreach($outlets as $outlet)
<tr>
<td>John</td>
<td>Doe</td>
<td>john#example.com</td>
</tr>
#endforeach
</tbody>
</table>
</div>

How we can create a table in excel as the below html?

Suppose I want to create a table with php-excel or laravel-excel that should has the following structure:
<table>
<thead>
<th>Column A</th>
<th>Column B</th>
</thead>
<tbody>
<tr>
<td>value 1</td>
<td>
<table>
<thead>
<th>neste column 1</th>
<th>nest column 2</th>
</thead>
<tbody>
<tr>
<td>nested value 1</td>
<td>nested value 2</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
I searched a lot and it seems that excel doesn't support nested table.
If it is possible, how we can do that?

Tablesorter plugin not sorting my tables when data comes from database

I have the following code:
<table id="box-table-a" class="tablesorter">
<thead>
<tr>
<th scope="col">B-House/Dorm Name</th>
<th scope="col">Address</th>
<th scope="col">Price Range</th>
<th scope="col">Date Added</th>
<th scope="col">Status</th>
</tr>
</thead>
<?php
$q=mysql_query("select * from property");
while( $f=mysql_fetch_array($q, MYSQL_ASSOC))
{ $p_id=$f["p_id"];
echo"
<tbody>
<tr>
<td onblurr='hover2()' onmouseover='hover(".$p_id.")' onclick='showUser(".$p_id.")'>
<span style='cursor:pointer'>".$f['p_name']."</span></td>
<td id='pretty'>".$f['address']."</td>
<td>".$f['p_name']."</td> <td>".$f['payment_type']."</td> <td>".$status."</td> </tr>
</tbody>
";
}
?>
</table>
Any idea what may be wrong here?
Don't add <tbody></tbody> to every loop in the while! Tablesorter is very sensitive.
You did'nt sort your DB :
$q=mysql_query("select * from property ORDER BY p_name");

Categories