Here the menu tabs are not becoming and don't know why it seems look like this.Here is the control please have a look
public function vehicle($id=NULL)
{
if (!empty($id)) {
$data['active'] = 2;
$this->Vehicle_model->_table_name = "tbl_vehicles"; //table name
$this->Vehicle_model->_order_by = "id";
$data['vehicle_info'] = $this->Vehicle_model->get_by(array('id' => $id), TRUE);
} else {
$data['active'] = 1;
}
$data['all_vehicle_info'] = $this->Vehicle_model->view_vehicle(null,null);
$this->load->view('admin/vehicle/add_vehicle',$data);
}
here is the view
<ul class="tabs rs-tab">
<li class="<?php echo ($active == 1) ? "active" : ""; ?> tab col s3 "><a href="#manage" >All Vehicles</a></li>
<li class="<?php echo ($active == 2) ? "active" : ""; ?> tab col s3"><a href="#create" >New Vehicles</a></li>
</ul>
<div class="<?php echo ($active == 1) ? "active" : ""; ?>" id="manage" >
</div>
<div class="<?php echo ($active == 2) ? "active" : ""; ?>" id="create">
</div>
Related
I have my nav.php setup with code like this. This is to determine the page and then set both the navigation header and the item as active.
if ($_SERVER['PHP_SELF'] == ''.$path.'/links.php') {
$opslinks = "active";
$nav1_active = "active";
} elseif($_SERVER['PHP_SELF'] == ''.$hpath.'/tunnel_status.php') {
$tunnelstatus = "active";
$nav2_active = "active";
$refresh = "<meta http-equiv=\"refresh\" content=\"240\"/>";
} elseif($_SERVER['PHP_SELF'] == ''.$hpath.'/qcall_status.php') {
$qcallstatus = "active";
$nav2_active = "active";
} elseif ($_SERVER['PHP_SELF'] == ''.$path.'/checklist.php') {
$opsdash = "active";
$nav1_active = "active";
} elseif ($_SERVER['PHP_SELF'] == ''.$path.'/index.php') {
$opsindex = "active";
$nav1_active = "active";
} elseif ($_SERVER['PHP_SELF'] == ''.$path.'/tasks_closed.php') {
$optaskclosed = "active";
$nav1_active = "active";
}
I then have the following html code.
<div class="menu-submenu">
<div class="menu-item <?=$opsindex ?? '';?>">
<div class="menu-text">Home</div>
</div>
<div class="menu-item <?=$opsdash ?? '';?>">
<div class="menu-text">Checklist</div>
</div>
<div class="menu-item <?=$opsoutages ?? '';?>">
<div class="menu-text">Outage Management</div>
</div>
<div class="menu-item <?=$opsissues ?? '';?>">
<div class="menu-text">Task List / Issues</div>
</div>
<div class="menu-item <?=$optaskclosed ?? '';?>">
<div class="menu-text">Task List (Closed)</div>
</div>
<div class="menu-item <?=$opslinks ?? '';?>">
<div class="menu-text">Common Links</div>
</div>
</div>
How can I optimize this as I feel this is horribly done and outdated. I've been working on cleaning up all my older code and this is one area I'm not sure about. I know I could technically add the code into the html block itself, but it's not really any better that way.
I also realize the php code block only partially matches what I posted. I have dozens of links, so to condense the info and present enough, I truncated it down.
I'm also working on revamping my PATH variables to be constants and defined in a single file, its sort of a mess at the moment. :)
Using the approach outlined by #CBroe comment above
// set up an array on the php side with a mapping to then loop over to create the nav elements
// the skeleton code below should work with some modifications
$nav_options = [
['page_link' => 'links.php', 'link_text' => 'Common Links' ],
[],
...
]
$arr = [];
foreach( $nav_options as $key => $nav_opt ) {
$url = $path . '/' . $nav_opt["page_link"];
if( $_SERVER['PHP_SELF'] == $url ){
// active
$arr[$key]['css_class'] = 'active';
$arr[$key]['link_href'] = $url;
$arr[$key]['link_text'] = $nav_opt['link_text'];
} else {
// not active
$arr[$key]['css_class'] = '';
$arr[$key]['link_href'] = $url;
$arr[$key]['link_text'] = $nav_opt['link_text'];
}
}
// Then loop over $arr on the html side to produce the nav div elements
I want to make a pagination for search results. I can see the results in first page when I use the search box but I can't see the other results in other pages. What am I doing wrong?
I would be really glad if you could help me
Here' my search page codes.
Codes for pagination
<?php
if(isset($_GET["page"])) {
$page = $_GET["page"];
}else {
$page = "";
}
if($page == "" || $page == 1) {
$starter_post = 0;
} else {
$starter_post = ($page * 6) - 6;
}
$sql_query2 = "SELECT * FROM posts ";
$look_all_post = mysqli_query($conn, $sql_query2);
$all_post_count = mysqli_num_rows($look_all_post);
$page_number = ceil ($all_post_count / 6);
Codes for search results
if(isset($_POST["searchbtn"])) {
$search = $_POST["search"];
$query = "SELECT * FROM posts WHERE post_tags LIKE '%$search%' ORDER BY post_id DESC LIMIT $starter_post, 6";
$search_query = mysqli_query($conn, $query);
if(!$search_query) {
die("QUERY FAILED:". mysqli_error($conn));
}
$search_count = mysqli_num_rows($search_query);
if($search_count == 0) {
echo "<h3> No Result </h3>";
} else {
while ($row = mysqli_fetch_assoc($search_query)){
$post_id = $row["post_id"];
$post_date = $row["post_date"];
$date = strtotime($post_date);
$newdate = date("d/m/Y", $date);
$post_title = $row["post_title"];
$post_text = $row["post_text"];
$post_image = $row["post_image"];
?>
<div class="col-md-6">
<div class="blog">
<div class="blog-img ">
<img src="images/<?php echo $post_image; ?>" class="img-fluid" >
</div>
<div class="blog-content">
<ul class="blog-meta">
<li><i class="far fa-calendar-alt"></i><span class="writer"><?php
echo $newdate; ?></span></li>
</ul>
<h3><?php echo $post_title; ?></h3>
<p><?php echo $post_text; ?></p>
<div class="blog-content2 text-center">
</div>
</div>
</div>
</div>
<?php }
}
}
?>
Codes for pagination
</div>
<div class="row">
<nav aria-label="Page navigation example">
<ul class="pagination justify-content-center">
<li <?php if ($page == 1 or $page == "") {echo "class='page-item disabled'";} ?>>
<a class="page-link" href="search.php?page=<?php if ($page > 1) {echo $page - 1;} ?>">Previous</a>
</li>
<?php //Pagination Continue
for($i=1; $i<=$page_number; $i++) {
echo "<li class='page-item'><a class='page-link' href='search.php?page=$i'>{$i}</a></li>";
}
?>
<li <?php if ($page == $page_number) {echo "class='page-item disabled'";} ?>>
<a class="page-link" href="search.php?page=<?php if ($page == "") {echo $page = 2;} else if($page_number!=$page){echo $page+1;} else if($page_number==$page){echo $page;}?>">Next</a>
</li>
</ul>
</nav>
</div>
Here is my site nav.php is look like :
<li <?php echo $active; ?>>Home</li>
<li <?php echo $active; ?>>Report</li>
<li <?php echo $active; ?>>Chart</li>
<li <?php echo $active; ?>>Export</li>
and header.php page is look like :
<?php
$pageName = basename($_SERVER['PHP_SELF']);
$explode = explode('.', $pageName);
$title = ucfirst($explode[0]);
if($title == "Report") {
$active = 'class="active"';
} else {
$active = '';
}
?>
I am using above code to show css .active class on currently view any page. but it's adding .active class to all pages.
Note : I have 4 pages. e.g: index, report, chart and export.
and My full page structure is like that :
In index.php page I am calling following page.
header.php
nav.php
js.php
footer.php
use this
$activePage = basename($_SERVER['PHP_SELF'], ".php");
and in your li
<li <?php if($activePage=="Report") { echo "class='active'"; } ?>>Home</li></li>
Wrapping will give you additional flexibility over static content
$pageName = basename($_SERVER['PHP_SELF']);
$explode = explode('.', $pageName);
$title = ucfirst($explode[0]);
$nav = [
'index' => 'Home',
'report' => 'Report',
'chart' => 'Chart',
'export' => 'Export'
];
foreach ($nav as $key => $value) {
echo '<li class="'.($key == $title ? 'active' : '').'>';
echo ''.$value.'' ;
echo '</li>'
}
Easiest way:
$pages = array();
$pages["home.php"] = "Home";
$pages["report.php"] = "Report";
$pages["chart.php"] = "Chart";
$pages["export.php"] = "Export";
$active = "home.php";
<?php foreach($pages as $url=>$title):?>
<li>
<a <?php if($url === $active):?>class="active"<?php endif;?> href="<?php echo $url;?>">
<?php echo $title;?>
</a>
</li>
<?php endforeach; ?>
Because you're defining $active only once and for all at the same time.
You probably should work with an array:
$navigation = array('index', 'report', 'chart', 'export);
And now you loop through that array, checking, which is active:
foreach($navigation as $n) {
if(ucfirst($explode('.', $pageName) == $n) {
echo '<li class="active">' . ucfirst($n) . '</li>';
} else {
echo '<li>' . ucfirst($n) . '</li>';
}
}
Try to do it like this:
<li class="<?= ('Home' == $title) ? 'active' : ''; ?>">
Home
</li>
<li class="<?= ('Report' == $title) ? 'active' : ''; ?>">
Report
</li>
<li class="<?= ('Chart' == $title) ? 'active' : ''; ?>">
Chart
</li>
<li class="<?= ('Export' == $title) ? 'active' : ''; ?>">
Export
</li>
try doing the following
<li <?php echo ($pageName=="index.php")?" class='active'" :""; ?>>Home</li>
<li <?php echo ($pageName=="report.php")?" class='active'" :""; ?>>Report</li>
<li <?php echo ($pageName=="chart.php")?" class='active'" :""; ?>>Chart</li>
<li <?php echo ($pageName=="export.php")?" class='active'" :""; ?>>Export</li>
First of all, apoligise for the messy title, I could not came up with a better one. You will understand the question better in the code. When I click in Private University I can make that button active, but I either want to make active the button Study Opportunity. Thanks.
<li class="dropdown <?php if(basename($_SERVER['SCRIPT_NAME']) == 'study-opportunity.php'){echo 'active'; }else { echo ''; } ?>">
Study Opportunity<span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li class="<?php if(basename($_SERVER['SCRIPT_NAME']) == 'universitetet-me-konkurim.php'){echo 'active'; }else { echo ''; } ?>">Universitetet me Konkurim</li>
<li class="<?php if(basename($_SERVER['SCRIPT_NAME']) == 'private-university.php'){echo 'active'; }else { echo ''; } ?>">Private University</li>
<li class="<?php if(basename($_SERVER['SCRIPT_NAME']) == 'studime-jashte-vendit.php'){echo 'active'; }else { echo ''; } ?>">Studime Jashte Vendit</li>
<li class="<?php if(basename($_SERVER['SCRIPT_NAME']) == 'bursa.php'){echo 'active'; }else { echo ''; } ?>">Bursa Studimi</li>
</ul>
</li>
You have to check all of the links in the dropdown too:
<li class="dropdown <?php if(basename($_SERVER['SCRIPT_NAME']) == 'study-opportunity.php' || basename($_SERVER['SCRIPT_NAME']) == 'universitetet-me-konkurim.php' || basename($_SERVER['SCRIPT_NAME']) == 'private-university.php' || basename($_SERVER['SCRIPT_NAME']) == 'studime-jashte-vendit.php' || basename($_SERVER['SCRIPT_NAME']) == 'bursa.php'){echo 'active'; }else { echo ''; } ?>">
Study Opportunity<span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li class="<?php if(basename($_SERVER['SCRIPT_NAME']) == 'universitetet-me-konkurim.php'){echo 'active'; }else { echo ''; } ?>">Universitetet me Konkurim</li>
<li class="<?php if(basename($_SERVER['SCRIPT_NAME']) == 'private-university.php'){echo 'active'; }else { echo ''; } ?>">Private University</li>
<li class="<?php if(basename($_SERVER['SCRIPT_NAME']) == 'studime-jashte-vendit.php'){echo 'active'; }else { echo ''; } ?>">Studime Jashte Vendit</li>
<li class="<?php if(basename($_SERVER['SCRIPT_NAME']) == 'bursa.php'){echo 'active'; }else { echo ''; } ?>">Bursa Studimi</li>
</ul>
</li>
The website www.indowesterncaterers.com/ has menu in header.php
<ul>
<li class="<?php if(basename($_SERVER['SCRIPT_NAME']) == 'index.php'){echo 'active'; }else { echo ''; } ?>">Home</li>
<li class="<?php if(basename($_SERVER['SCRIPT_NAME']) == 'about-us.php'){echo 'active'; }else { echo ''; } ?>">About US</li>
<li class="<?php if(basename($_SERVER['SCRIPT_NAME']) == 'plan-your-wedding.php'){echo 'active'; }else { echo ''; } ?>">PLAN YOUR WEDDING
<ul>
<li class="<?php if(basename($_SERVER['SCRIPT_NAME']) == 'venues.php'){echo 'active'; }else { echo ''; } ?>">venues</li>
<li class="<?php if(basename($_SERVER['SCRIPT_NAME']) == 'invitations.php'){echo 'active'; }else { echo ''; } ?>">Invitations</li>
<li class="<?php if(basename($_SERVER['SCRIPT_NAME']) == 'flower-decoration.php'){echo 'active'; }else { echo ''; } ?>">flower decoration</li>
<li class="<?php if(basename($_SERVER['SCRIPT_NAME']) == 'mehandi-function.php'){echo 'active'; }else { echo ''; } ?>">mehandi function</li>
</ul>
</li>
<li class="<?php if(basename($_SERVER['SCRIPT_NAME']) == 'wedding-catering.php'){echo 'active'; }else { echo ''; } ?>">wedding catering</li>
<li class="<?php if(basename($_SERVER['SCRIPT_NAME']) == 'image-gallery.php'){echo 'active'; }else { echo ''; } ?>">Image Gallery</li>
<li class="<?php if(basename($_SERVER['SCRIPT_NAME']) == 'special-offer.php'){echo 'active'; }else { echo ''; } ?>">special offer</li>
</ul>
from other pages , like http://www.indowesterncaterers.com/wedding-catering.php
If I click on homepage , the url shows http://www.indowesterncaterers.com/index.php
I want to hide index.php url when clicked from other navigation urls.
The site in core PHP ,
Instead of using
Home
try
Home
Assuming DirectoryIndex is set to index.php, you should be able to use -
<li class="<?php if(basename($_SERVER['SCRIPT_NAME']) == 'index.php'){echo 'active'; }else { echo ''; } ?>">Home</li>