Drupal 7 views view template - php

in my viewv-view-fields--myView.tpl.php
i have styled how i want the output to look like
if(isset($fields['title']) && isset($fields['file'])) {
$category = $fields['field_category']->content;
$file_link = $fields['file']->raw;
$title = $fields['title']->content;
if($category == "2014"){
print '<tr><td>'.$title.' </td> </tr>';
} else if($category == "2013") {
print '<tr><td>'.$title.' </td> </tr>';
}
i can if i want output only one category white my ifs
but now to the trouble if i want to output category 2014 in one table and category 2013 i another.
in my views-view--myView.tpl.php i can only do print rows and it picks both, i tried to put the links into a array but it creates a new array of every link so im kinda stuck here
<table class="table table-hover">
<thead>
<tr><th>2014</th></tr>
</thead>
<tbody>
<?php if ($rows):
print $rows;
?>
<?php endif; ?>
</tbody>
</table>
<table class="table table-hover">
<thead>
<tr><th>2013</th></tr>
</thead>
<tbody>
<?php if ($rows):
print $rows;
?>
<?php endif; ?>
</tbody>
</table>
anyone how got a suggestion?

Related

display plain text php mysql

after having found the data in a table the function displays the information without missing, with a td tag only the first word which displays the others after the space are not displayed.
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Service </th>
<th>Prix</th>
<th >Quantite</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$reqq = "SELECT * FROM service WHERE client = '$clientId' AND dossier = '$dossier' ";
$results = $connect->query($reqq);
?>
<?php if($results->num_rows > 0){ ?>
<?php
foreach($results as $data){ ?>
<?php echo $data['nom']; ?>
<tr>
<td> <?php print $data['nom']; ?>
<td><?= $data['prix']?></td>
<td><?= $data['quantite']?></td>
<td>Supprimer</td>
</tr>
</tbody>
</table>
the result is
Inside the table the last field have Franchise Procedure the table only display the first word which is Franchise
Help me find the solution please.
Try with:
<td> <?php echo htmlspecialchars($data['nom']); ?> </td>
Often, text stored in databases can contains reserved characters in HTML like "<" or "&" which should be replaced by html entities
That's what the PHP function htmlspecialchars was invented for.

Table splitting

Here is my code to display table:
<table id="ws_table" class="ws_table">
<thead>
<tr class="bg-light">
<th>WS Code</th>
<th>WS Name</th>
</tr>
</thead>
<tbody class="reportWs_table">
<?php
if (is_array($workschedules)) {
//$i=0;
foreach ($workschedules as $workschedulesingle) {
$cnt++;
?>
<tr>
<td class="">
<?php echo $workschedulesingle['workScheduleCode']; ?>
</td>
<td class="">
<?php echo $workschedulesingle['workScheduleName']; ?>
</td>
</tr>
<?php
}
} else {
}
?>
</tbody>
</table>
My problem is its a long table. So I want to split into two. How can I split the table vertically? i.e. When the entries exceeds 20 it will goes to next table. How can I create it?
• Set Index $i=0
• Loop every row
• Check if the index start on 0
• Check if Index reach 20/limit
• If reach 20/limit reset Index to 0 again.
<?php
//INIT INDEX $i
$i = 0;
if(is_array($workschedules)){
// FOR EACH ROW
foreach($workschedules as $workschedulesingle){
//EVERY TIME THE INDEX START PRINT THE TABLE
if($i==0){
?>
<table id="ws_table" class="ws_table">
<thead>
<tr class="bg-light">
<th>WS Code</th>
<th>WS Name</th>
</tr>
</thead>
<tbody class="reportWs_table">
<?php } ?>
<tr>
<td class=""><?php echo $workschedulesingle['workScheduleCode'];?></td>
<td class=""><?php echo $workschedulesingle['workScheduleName'];?></td>
</tr>
<?php
//IF THE INDEX REACH 20/LIMIT, PRINT CLOSING TABLE TAGS
if($i==20){ ?>
</tbody>
</table>
<?php
}
//IF THE INDEX EXCEED 20/LIMIT, RESET $i TO 0 AND START AGAIN
$i++;
if($i>20){
$i=0;
}
}
}else{
}
?>

bootstrap and codeIgniter data display in table

<table class="table table-bordered table-hover">
<?php foreach ($pin_data as $pin) {
?>
<tr>
<td><?php echo $pin->location;?> <?php echo $pin->pincode;?></td>
</tr>
<?php
} ?>
</table>
Im fetching data from database.I wanted to display that data in table, but i wanted to display 5 column in a row. after that it start with new row. plz help.
you add < tr> in first value and you add "< /tr>" in fifth value. it will run.
<table class="table table-bordered table-hover">
<?php $timer=1;
foreach ($pin_data as $pin) {
if($timer%5==1)
{
?>
<tr>
<?php
}
?>
<td><?php echo $pin->location;?> <?php echo $pin->pincode;?></td>
if($timer%5==0)
{
?>
</tr>
<?php
}
<?php
$timer++;
} ?>
</table>
Hope this will help you :
Do something like this :
<table class="table table-bordered table-hover">
<?php foreach ($pin_data as $pin) { ?>
<tr>
/*change your column name as according to you*/
<td><?php echo $pin->location;?></td>
<td><?php echo $pin->pincode;?></td>
<td><?php echo $pin->location;?></td>
<td><?php echo $pin->pincode;?></td>
<td><?php echo $pin->location;?></td>
</tr>
<?php } ?>
</table>
You can use the modulus operator and a counter:
<table class="table table-bordered table-hover">
<tr> <!-- start initial row -->
<? $counter = 1;
foreach ($pin_data as $pin):?>
<td>
<?= $pin->location;?> <?= $pin->pincode;?>
</td>
<?if($counter % 5 == 0):?> //if $counter is a multiple of 5, close the current row and start an new one
</tr>
<tr>
<?endif;?>
<? $counter++;?>
<?endforeach;?>
</table>

How to list all row of sql?

Hy!
I want to list all row of my table, but it is not works :(
My function.php:
function getCharacterAdminJails($account_id) {
global $connection;
$stmt = $connection->pdo->prepare("SELECT * FROM adminjails WHERE jailed_accountID = :account_id");
$stmt->bindParam(":account_id", $account_id);
$stmt->execute();
$adminjail_data = $stmt->fetch(PDO::FETCH_ASSOC);
return $adminjail_data;
}
My example.php, where I list my rows:
<table class="table table-hover">
<tr>
<th>Admin neve:</th>
<th>Indok:</th>
<th>Perc:</th>
<th>Időpont:</th>
</tr>
<tr>
<th><?=$adminjail_data["jailed_admin"];?></th>
<th><?=$adminjail_data["jailed_reason"];?></th>
<th><?=$adminjail_data["jailed_ido"];?></th>
<th><?=$adminjail_data["jailed_idopont"];?></th>
</tr>
</table>
How can I list all rows of my table?
I would suggest you change this line of code in your php function from
$adminjail_data = $stmt->fetch(PDO::FETCH_ASSOC);
To this:
$adminjail_data = $stmt->fetchAll(PDO::FETCH_ASSOC);
As fatchAll will return an array of all the results from your query and then in your html page do this:
<table class="table table-hover">
<tr>
<th>Admin neve:</th>
<th>Indok:</th>
<th>Perc:</th>
<th>Időpont:</th>
</tr>
<?php foreach($adminjail_data as $row) :?>
<tr>
<th><?=$row["jailed_admin"];?></th>
<th><?=$row["jailed_reason"];?></th>
<th><?=$row["jailed_ido"];?></th>
<th><?=$row["jailed_idopont"];?></th>
</tr>
<?php endforeach; ?>
</table>
This is from PHP.net documentation about fetchAll:
PDOStatement::fetchAll — Returns an array containing all of the result set rows
You can refer to the full php documentation about PDOs fetchAll here: https://secure.php.net/manual/en/pdostatement.fetchall.php
Try the following code to list all the rows by iterating through the $adminjail_data array:
<table class="table table-hover">
<tr>
<th>Admin neve:</th>
<th>Indok:</th>
<th>Perc:</th>
<th>Időpont:</th>
</tr>
<?php foreach($adminjail_data as $row) :?>
<tr>
<th><?=$row["jailed_admin"];?></th>
<th><?=$row["jailed_reason"];?></th>
<th><?=$row["jailed_ido"];?></th>
<th><?=$row["jailed_idopont"];?></th>
</tr>
<?php endforeach; ?>
</table>

Bootstrap3 fixed column for table

I checked thrice in SOF, for a solution regarding Bootstrap framework 3.
Even this demo is not working in my system. http://jsfiddle.net/koala_dev/4XG7T/2/
So, I have a matrix type table that will populate 'n' number of records both horizontally and vertically.
My below code is working fine if there is 5-8 columns, but if there are more than 20 columns the table is collapsed.
In other words, I need something that will keep the header part alone fixed. i.e first row with 'n' number of columns.
How can I achieve that? Could someone redefine my below code.
<div class="container">
<form action="post.php" method="post">
<div class="table responsive">
<table class="table table-striped table-hover" cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr>
<th>S.No</th>
<?php while($row = mysql_fetch_array( $myloop )) { ?>
<th><?php echo $row['book_name']; ?></th>
<?php } ?>
</tr>
<tr>
<?php while($row1 = mysql_fetch_array( $myloop1 )) { ?>
<td><?php echo $row1['author_name']; ?></td>
<td><?php echo $row1['author_rating']; ?></td>
<?php } ?>
</tr>
</tbody>
</table>
</div>
</form>
</div>
To make it simple I want the below row to be fixed so that I can scroll horizontally and check the records.
<tr>
<th>S.No</th>
<?php while($row = mysql_fetch_array( $myloop )) { ?>
<th><?php echo $row['book_name']; ?></th>
<?php } ?>
</tr>
Any help?
Thanks,
Kimz

Categories