Hi all I have searching for method but not luck. Help me I want to make numbering navigation. Here is my code:
<ul>
<?php
$kw = file_get_contents('keywords.txt');
$kw = explode("\n", $kw);
asort($kw);
$i = 0;
foreach($kw as $k) {
if($i==30) { break; }
?>
<li>
<?php echo ucwords($k);?>
</li>
<?php $i++; } ?>
</ul>
The above code just displayed 30 result from 1500 keyword I have. I want to make Page Numbering navigation also shorting A-Z. So user can Short Keyword by Alphabetic above it and page numbering after it.
Use Datatables.
Table
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>KeyWord</th>
</tr>
</thead>
<tbody>
<?php foreach($kw as $k) { ?>
<tr>
<td><?php echo ucwords($k);?></td>
</tr>
<?php } ?>
</tbody>
</table>
Javascript
$(document).ready(function() {
$('#example').DataTable();
} );
Do include the proper plugin files for js & css. from - Datatables
Related
Currently I have a table and is currently coded as:
$min_hor = $min_ver = 1;
$max_hor = $max_ver = 3;
?>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<style>
.table{
margin: 0 auto;
}
</style>
<div class="text-center">
<table class="table" style="width:70%">
<thead>
<tr>
<th></th>
<?php for($j=$min_hor; $j<=$max_hor; $j++){ ?>
<th><?php echo str_pad($j, 2, "0", STR_PAD_LEFT); ?></th>
<?php } ?>
</tr>
</thead>
<tbody>
<?php for($i=$min_ver;$i<=$max_ver;$i++){ ?>
<tr>
<th><?php echo $i; ?></th>
<?php for($j=$min_hor; $j<=$max_hor; $j++){ ?>
<td><?php echo $i.'-'.str_pad($j, 2, "0", STR_PAD_LEFT) ?></td>
<?php } ?>
</tr>
<?php } ?>
</tbody>
</table>
</div>
This display table as shown in attached screenshot.
Now, I have one additional array as $letter_array = array('A','B'); This array is could be bigger than this one and could be upto D,E,F,...
Now, I need to include this A,B into the table header something like as shown in screenshot.
This is where I became helpless. I couldn't find how could I loop this. Although, to make things easier, I have included codepen link of html code.
Codepen
How about we keep headers in 2 different Arrays and then perform a loop.following is the pseudocode which i think will work.
string a[16]={'01','02','03',......,'B'};
string b[17]={'1','2','3',....,'B'};
<table class="table" style="width:70%">
<thead>
<tr>
<th></th>
foreach(var item in a)
{
<th>{{item}}</th>
}
</tr>
</thead>
<tbody>
foreach(var item2 in b)
{
<tr>
<td>{{item2}}</td>
foreach(var item in a)
{
<td>{{item2}}_{{item}}</td>
}
</tr>
}
</tbody>
</table>
Now, before generating table we need elements at array A and B. to generate the array i.e a and b we can do following :
int min_hor=1;
int max_hor=3;
var a_output=[];
var a_inputLetter=['A','B'];
//first for number only.here let us create a string and push to a_output.
for(int i=min_hor,i<=max_hor;i++)
{
a_output.Add('0'+i);
}
//second let us use Number Letter Combination
foreach(var item in a_inputLetter)
{
for(int i=min_hor;i<=max_hor;i++)
{
a_output.Add('0'+{{i}}_{{item}});
}
}
//third for letter number combination
foreach(var item in a_inputLetter)
{
for(int i=min_hor;i<=max_hor;i++)
{
a_output.Add({{item}}_{{i}});
}
}
//and finally for letter_only
foreach(var item in a_inputLetter)
{
a_output.Add({{item}});
}
//similarly do for Array B as well to generate the second array.
I am using the below table for 3 conditions, by passing values through variables.
In one of my conditions I have only 3 colums, i.e $h2 will be empty for one condition. if($h2=="") I want to hide that entire column.
How can I do that?
This is my code:
<table id="usertracking" >
<thead>
<tr>
<?php
echo'<td><h3>'.$h1.'<h3></td>';
echo'<td><h3>'.$h2.'<h3></td>';
echo'<td><h3>'.$h3.'<h3></td>';
echo'<td><h3>'.$h4.'<h3></td>';
?>
</tr>
</thead>
<tbody>
<?php
for($i=$start;$i<$end;$i++)
{
echo'<tr>';
echo'<td>'.$ARRAY[$i]['MpwName'].'</td>';
echo'<td>'.$ARRAY[$i]['PatientName'].'</td>';
echo'<td>'.$ARRAY[$i]['PatientAddress'].'</td>';
echo'<td>'.$ARRAY[$i]['New'].'</td>';
echo'<tr>';
}
?>
</tbody>
</table>
You can do something like :
$display_column1=$display_column2=$display_column3=$display_column4=true;
if($h1=="")$display_column1=false;
if($h2=="")$display_column2=false;
...
echo'<tr>';
if($display_column1)echo'<td>'.$ARRAY[$i]['MpwName'].'</td>';
if($display_column2)echo'<td>'.$ARRAY[$i]['PatientName'].'</td>';
...
And better, make this in loop.
You can check if $h2 is empty. If not, print:
<table id="usertracking" >
<thead>
<tr>
<?php
echo'<td><h3>'.$h1.'<h3></td>';
if (!empty($h2)) // check
echo'<td><h3>'.$h2.'<h3></td>'; // print
echo'<td><h3>'.$h3.'<h3></td>';
echo'<td><h3>'.$h4.'<h3></td>';
?>
</tr>
</thead>
<tbody>
<?php
for($i=$start;$i<$end;$i++)
{
echo'<tr>';
echo'<td>'.$ARRAY[$i]['MpwName'].'</td>';
if (!empty($h2)) // check
echo'<td>'.$ARRAY[$i]['PatientName'].'</td>'; // print
echo'<td>'.$ARRAY[$i]['PatientAddress'].'</td>';
echo'<td>'.$ARRAY[$i]['New'].'</td>';
echo'<tr>';
}
?>
</tbody>
</table>
Just put your if condition before each echo that you need:
//in the Head
if ($h2) echo'<td><h3>'.$h2.'<h3></td>';
And in the body, at the column data:
if ($h2) echo'<td>'.$ARRAY[$i]['PatientName'].'</td>';
Using a combination of CSS and PHP, you might try something like
<td style="display:<?/*Your condition here*/?>;">
Use this
//in the Head
if ($h2 != ""){ echo'<td><h3>'.$h2.'<h3></td>'; }
// in loop
if ($h2!= ""){ echo'<td>'.$ARRAY[$i]['PatientName'].'</td>'; }
I have got a question regarding setting up proper categories for my posts that would be done automatically. I'm using PHP.
Here is my sample example document from the database:
{
"_id" : "css-clearfix-explained",
"title" : "CSS Clearfix Explained",
"category" : [
"CSS/HTML",
" Wordpress"
],
"date_time" : ISODate("2014-08-13T21:03:45.367Z"),
"description" : "Blalalal ",
"content" : " ",
"author" : "Maciej Sitko"
}
So, for that purpse I wrote the code that inserts the categories in the view page, to be more specific, it inserts them into the table. This is the code:
<?php if(!isset($_GET['cat'])) {
$categories = $collection->find();?>
<table class="table table-hover table-striped">
<thead class='table-head' >
<tr ><th colspan='2'>Categories</th></tr>
</thead>
<tbody>
<?php foreach($categories as $category) {
foreach($category as $keys) {
if((is_array($keys)) && (!empty($keys))) {
foreach($keys as $key => $value) { ?>
<tr>
<td><a class="normalize" href="">
<?php echo $keys[$key]; ?></a></td>
<td class="small"> Posts</td>
</tr>
<?php } } } } ?>
</tbody>
</table>
The problem is, and you see it (I bet it), that when it is executed this way there would be duplicates of the categories in the table shown. How can I prevent those categories from repeating themselves in the listing? I know its a rookie question, but I'm still learning.
You could write $category into an array and every iteration - before displaying your data - you could check if $category is already in there. You could use "in_array": http://php.net/manual/de/function.in-array.php
<?php if(!isset($_GET['cat'])) {
$categories = $collection->find();?>
<table class="table table-hover table-striped">
<thead class='table-head' >
<tr ><th colspan='2'>Categories</th></tr>
</thead>
<tbody>
<?php
$uniqueCats = array();
foreach($categories as $category) {
foreach($category as $keys) {
if((is_array($keys)) && (!empty($keys))) {
foreach($keys as $key => $value) {
if( in_array($value, $uniqueCats) ) { continue; }
$uniqueCats[] = $value;
?>
<tr>
<td><a class="normalize" href="">
<?php echo $value; ?></a></td>
<td class="small"> Posts</td>
</tr>
<?php } } } } ?>
</tbody>
</table>
I hope that's what you were looking for :)
The code/variables slightly differs from how I would read the data in the example so I might have misinterpreted your question :)
I'm trying to to make a form that will submit a new record and automatically show that as DIV inside of the main DIV and after all the results from the PHP while loop.
Here is the while loop that I've built:
<?php
while ($row_apps = mysql_fetch_array($result_apps))
{
if ( ($row_apps['type'] == 'ar') && ($row_apps['client'] == NULL) ) {
echo '<center>
<div id="_'.$row_apps['app_id'].'" class="tab_listing">
<table width="248" border="0" cellspacing="10px" cellpadding="0px">
<tr>
<td width="100%" colspan="3"><div class="tab_listing_header">'.$row_apps['app_name'].'</div></td>
</tr>
<tr>
<td class="tab_listing_values"><b>App ID: </b>'.$row_apps['app_id'].'</td>
<td class="tab_listing_values"><b>Users: </b>'.$row_apps['users'].'</td>
</tr>
</table>
<div id="edit">Edit</div>
<div id="delete"></div>
</div>
</center><br>';
}
}
?>
Now basically what i need to do is when a form is submitted and the new record is in the database i want it to show a new "block" exact same like the while "blocks" live.
I was thinking about something like:
$.post("create.php",{ value1:$('#value1').val(),value2:$('value2').val(),rand:Math.random() } ,function(data)
{
if(data=='yes')
{
HERE I'M STUCK.
Thanks!
Try this
$.post("create.php",{ value1:$('#value1').val(),value2:$('value2').val(),rand:Math.random() } ,function(data)
{
if(data)
{
$("mainDivSelector").html(data);
}
);
data will contain a result string returned by create.php and that is entirely up to you. What does create.php do at the moment?
this is the index.php
<table align="center" border="0" cellpadding="0" cellspacing="0">
<tbody>
<?php include 'header.php'; ?>
<tr>
<td class="row_2">
<!-- header_eof //-->
<!-- body //-->
<table class="main_table" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<?php
if($cond)
include 'left.php'; ?>
<!-- body_text //-->
<?php get_page(); ?>
<!-- body_text_eof //-->
<?php
if($cond)
include 'right.php'; ?>
</tr>
<tr>
<?php
if(!$cond)
include 'contents/contact_us.php';?>
</tr>
</tbody>
</table>
<!-- body_eof //-->
<!-- footer //-->
</td>
</tr>
<?php include 'footer.php'; ?>
</tbody>
</table>
This is header.php . I have created link from database
<?php
$menus = db_query("select * from menus where type=0 order by weight");
$sr = 0;
while($menu = mysql_fetch_object($menus)) { ?>
<?php if(($sr++) > 0){ ?>
<td class="menu_separator"><img src="<?php echo SROOT;?>images/menu_separator.png" alt="" class="png" width="2" border="0" height="49"></td>
<?php } ?>
<td id="<?php echo get_id($menu->page_name); ?>" <?php echo get_event($menu->page_name); ?> onClick="document.location='<?php echo SROOT . $menu->page_name;?>'" nowrap="nowrap"><?php echo $menu->title; ?></td>
<?php } ?>
this is the get_page function
function get_page() {
$page = arg(0);
$page = (empty($page)) ? 'home' : $page;
$cat = db_query("select * from mb_category where title='".$page."'");
$page = (mysql_num_rows($cat)) ? 'brands' : $page;
include 'contents/'. $page .'.php';
}
I have everything in the right place.The same code is working for my friend but we are unable to understand the problem here. I get error cannot find page. His is working fine.
When i click link it says cannot find page..but his goes to page
Can anyone please help and tell me what i am doing wrong
Edited:
The part I don't understand is this:
$page = arg(0);
$page = (empty($page)) ? 'home' : $page;
$cat = db_query("select * from mb_category where title='".$page."'");
What is "arg(0)?, so how do you get $page?
Ok, I understand this is a drupal function or alike.
But, pls, verify that arg(0) returns sth.
If you are not sure of the path the include is taken, I would change this line:
include 'contents/'. $page .'.php';
for:
include $_SERVER["DOCUMENT_ROOT"]."/contents/'. $page .'.php';