I'm coding a staff panel but I'm stuck I've added a menu (navigation) but I'm stuck on how to go about opening it when clicked and closing it when clicked if open.
Here is the code i have so far;
<ul id="menu" class="nav">
<?php
$url = $_GET['url'] ? $core->clean($_GET['url']) : 'core.home';
$query3 = $db->query("SELECT * FROM menu WHERE url = '{$url}'");
$array3 = $db->assoc($query3);
if (!$array3['usergroup']) {
$array3['usergroup'] = "invalid";
}
$query = $db->query("SELECT * FROM usergroups ORDER BY weight ASC");
while ($array = $db->assoc($query)) {
if (in_array($array['id'], $user->data['uGroupArray'])) {
?>
<div class="menustyle" onclick="Radi.menuToggle('<?php echo $array['id']; ?>');">
<div class="menutext"><?php echo $array['name']; ?></div>
</div>
<ul>
<li class="menuitems"<?php if ($array['id'] != $array3['usergroup']) { ?> onclick="Radi.menuToggle('<?php echo $array['id']; ?>');" style="display: none;"<?php } ?> id="mitems_<?php echo $array['id']; ?>">
<?php
$query2 = $db->query("SELECT * FROM menu WHERE usergroup = '{$array['id']}' AND visible = '1' ORDER BY weight ASC");
$i = "a";
while ($array2 = $db->assoc($query2)) {
?>
<li>
<?php echo $array2['text']; ?>
</li>
<?php
$i++;
if ($i == "c") {
$i = "a";
}
}
?>
</ul>
</li>
<?php
}
}
?>
</li>
</ul>
</div>
And this is the defualt code when you download radipanel;
<div style="float: left; width: 200px;">
<?php
$url = $_GET['url'] ? $core->clean($_GET['url']) : 'core.home';
$query3 = $db->query("SELECT * FROM menu WHERE url = '{$url}'");
$array3 = $db->assoc($query3);
if (!$array3['usergroup']) {
$array3['usergroup'] = "invalid";
}
$query = $db->query("SELECT * FROM usergroups ORDER BY weight ASC");
while ($array = $db->assoc($query)) {
if (in_array($array['id'], $user->data['uGroupArray'])) {
?>
<div class="box">
<div class="square menu" style="background: #<?php echo $array['colour']; ?>;" onclick="Radi.menuToggle('<?php echo $array['id']; ?>');">
<img id="menutoggle_<?php echo $array['id']; ?>" class="menutoggle" src="_img/<?php echo ( $array['id'] != $array3['usergroup'] ) ? 'plus' : 'minus'; ?>_white.png" alt="Toggle" align="right" />
<strong><?php echo $array['name']; ?></strong>
</div>
<div class="menuitems"<?php if ($array['id'] != $array3['usergroup']) { ?> style="display: none;"<?php } ?> id="mitems_<?php echo $array['id']; ?>">
<?php
$query2 = $db->query("SELECT * FROM menu WHERE usergroup = '{$array['id']}' ORDER BY weight ASC");
$i = "a";
while ($array2 = $db->assoc($query2)) {
?>
<a href="<?php echo $array2['url']; ?>" class="<?php echo $i; ?>">
<?php echo $array2['text']; ?>
</a>
<?php
$i++;
if ($i == "c") {
$i = "a";
}
}
?>
</div>
</div>
<?php
}
}
?>
</div>
So any ideas on why my code is not doing it?
Related
I am trying to create a hoverable mega menu, all works fine except the active one.
I checked in source codes and active class is added, but it doesn't show up the content until mouseenter on it.
see image please :
And this is when I go on it with mouse, it show up with no problem.
I gues I need to set main (FINANCE is main menu in pic) menu active, but dont know how to pass it to submenu.
Here is my full code :
$stmt_menu = $pdo->prepare("SELECT * FROM categories WHERE parentId = ? LIMIT 5");
$stmt_menu->execute([0]);
if ($stmt_menu->rowCount() > 0) {
$query = $stmt_menu->fetchAll();
foreach ($query as $row) {
if ($row['cat_type'] == 'mega') {
?>
<li class="dropdown megamenu-fw mega-li-<?php echo $row['catId']; ?>">
<?php echo $row['catName']; ?><span class="caret"></span>
<ul class="dropdown-menu megamenu-content dropdown-top" role="menu" aria-expanded="true" data-mega-ul="<?php echo $row['catId']; ?>">
<li>
<?php
$stmt_menu = $pdo->prepare("SELECT * FROM categories WHERE parentId = ? LIMIT 5");
$stmt_menu->execute([$row['catId']]);
if ($stmt_menu->rowCount() > 0) {
$subquery = $stmt_menu->fetchAll();
?>
<div class="sub-menu-left">
<ul class="nav-sub-categories">
<?php
$i = 0;
foreach ($subquery as $subq) {
$actives = '';
if($i == 0){
$actives = ' active';
}
?>
<li data-category-filter="<?php echo $subq['cat_seo_url']; ?>-<?php echo $subq['catId']; ?>" class="li-sub-category<?php echo $actives; ?>"><?php echo $subq['catName']; ?></li>
<?php
$i++;
}
?>
</ul>
</div>
<div class="sub-menu-right">
<?php
$i = 0;
foreach ($subquery as $subcats) {
$actives = '';
if($i == 0){
$actives = ' active';
}
?>
<div class="sub-menu-inner filter-<?php echo $subcats['cat_seo_url']; ?>-<?php echo $subcats['catId']; ?><?php echo $actives; ?>">
<div class="row row-menu-right">
<div class="col-sm-3 menu-post-item">
<div class="post-item-image">
<a href="is-allowance-instantly-strangers-applauded">
<img src="assets/img/img_bg_md.png" data-src="uploads/images/202203/image_380x226_624239afd7295.jpg" alt="Is allowance instantly strangers applauded" class="lazyload img-responsive img-post" width="1" height="1"/>
</a>
</div>
<h3 class="title"><?php echo $subcats['cat_seo_url']; ?> Is allowance instantly strangers applauded</h3>
<p class="post-meta">
admin
<span>Mar 28, 2022</span>
<span><i class="icon-comment"></i>2</span>
<span class="m-r-0"><i class="icon-eye"></i>894</span>
</p>
</div>
</div>
</div>
<?php
$i++;
}
?>
</div>
<?php
}
?>
</li>
</ul>
</li>
<?php
} elseif ($row['cat_type'] == 'dropdown') {
echo ' <li class="nav-item"><a class="nav-link" href="' . $row["cat_seo_url"] . '">test</a></li>';
} else {
echo ' <li class="nav-item"><a class="nav-link" href="' . $row["cat_seo_url"] . '">' . $row["catName"] . '</a></li>';
}
}
}
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>
After searching for a specific course the results are displayed correctly but once I change page it reverts back to displaying all of the available results. How do I keep the search term results?
Here's the code
<?php
$con = mysqli_connect("localhost", "root", "root", "courses");
// $total = mysqli_query($con, "SELECT count(title) as total")->fetch()['total']);
if(isset($_GET['searchword'])){
$searchword = $_GET['searchword'];
}
else {
$searchword = "";
}
$result = mysqli_query($con, "SELECT count(title) FROM course WHERE title LIKE '$searchword%'");
$row = mysqli_fetch_row($result);
// Total rows.
$rowstotal = $row[0];
//pages
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$perPage = isset($_GET['per-page']) && $_GET['per-page'] <= 100 ? (int)$_GET['per-page'] : 10;
$start = ($page > 1) ? ($page * $perPage) - $perPage : 0;
$pages = $rowstotal / $perPage;
$sql = "SELECT * FROM course WHERE title LIKE '%$searchword%' ORDER BY title ASC LIMIT {$start},{$perPage}";
$query = mysqli_query($con, $sql);
$resultsText = "$rowstotal results";
$resultsList = '';
while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
$courseId = $row["id"];
$courseAward = $row["award"];
$courseName = $row["title"];
$courseDetails = $row["summary"];
$resultsList .= ''.$courseAward.' '.$courseName.' <br>'.$courseDetails.'<br/>';
}
mysqli_close($con);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Courses</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<nav class="navbar navbar-default navbar-static-top navbar-inverse">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">
<img alt="Napier" src="">
</a>
</div>
</div>
</nav>
<div class="container">
<!-- Search -->
<form method="GET">
<input type="text" class="form-control" name="searchword" placeholder="Search" value="<?php echo $searchword ?>" style="width:30%;"><br>
</form>
<!-- Results -->
<div class="results">
<p></p>
<p>Showing <?php echo $perPage; ?> of <?php echo $resultsText; ?></p>
<p id="content"><?php echo $resultsList; ?></p>
</div>
<div class="pagination">
<?php for($x = 1; $x <= $pages; $x++): ?>
<a href="?page=<?php echo $x; ?>&per-page=<?php echo $perPage; ?>"<?php if($page === $x) { echo ' class="selected"'; } ?>><?php echo $x; ?></a>
<?php endfor; ?>
</div>
</div>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
</body>
</html>
Your page links don't preserve the searchword parameter. Change this:
<a href="?page=<?php echo $x; ?>&per-page=<?php echo $perPage; ?>"<?php if($page === $x) { echo ' class="selected"'; } ?>><?php echo $x; ?></a>
to this:
<a href="?page=<?php echo $x; ?>&per-page=<?php echo $perPage; ?>&searchword=<?php echo $searchword; ?>"<?php if($page === $x) { echo ' class="selected"'; } ?>><?php echo $x; ?></a>
I have set-up a news page which retrieves news from MYSQL news table.
I am trying to identify if the news column is odd or even, so if the news columns is odd or even it will add a class to the div element.
My code is as follows:
<?php
$cat = $_GET['cat'];
$date = $_GET['date'];
if ($date !="") {
$date = explode('-', $date);
$year = $date[1];
$month = $date[0];
$month = date("m", strtotime($month));
$sql = "SELECT * FROM news WHERE year(newsDate) = '$year' AND month(newsDate) = '$month' AND newsState = 1 ORDER BY newsDate DESC";
} else {
$sql = "SELECT * FROM news WHERE newsState = 1 ORDER BY newsDate DESC";
}
$result = $conn->query($sql);
$rows = $result->num_rows;
$pager = new PS_Pagination($conn, $sql, 5, 10, null);
$rs = $pager->paginate();
$num = $rs->num_rows;
if($num >= 1 ){
while($row = $rs->fetch_assoc()){
?>
<div class="news <?php echo $num; ?>">
<div class="four columns">
<p><img src="/news-images/thumbs/thumb_<?php echo $row['newsImage1']; ?>" alt=""/></p>
</div>
<div class="eight columns">
<h3><?php echo $row['newsTitle']; ?></h3>
<p><?php echo stripslashes(strip_tags($row['newsDescription'])); ?></p>
</div>
</div>
<?php } } else {
echo "No records found!";
}
if ($rows >= 5) {
echo "<div class='page-nav blog-nav'>";
echo $pager->renderFullNav();
echo "</div>";
}
?>
TAke any flag which maintains odd-even position...
$f = 0; //ADDED THIS LINE
if($num >= 1 ){
while($row = $rs->fetch_assoc()){
if($f%2==0) //ADDED THIS LINE
$class_name = "even"; //ADDED THIS LINE
else //ADDED THIS LINE
$class_name = "odd"; //ADDED THIS LINE
?>
<div class="news <?php echo $class_name; ?>">
<div class="four columns">
<p><img src="/news-images/thumbs/thumb_<?php echo $row['newsImage1']; ?>" alt=""/></p>
</div>
<div class="eight columns">
<h3><?php echo $row['newsTitle']; ?></h3>
<p><?php echo stripslashes(strip_tags($row['newsDescription'])); ?></p>
</div>
</div>
<?php $f++; } } else {
echo "No records found!";
}
if($num >= 1 ){
$tr = 1;
while($row = $rs->fetch_assoc()){
if($tr%2 == 0)
{
//then even class
}
else
{
//odd class
}
?>
<div class="news <?php echo $num; ?>">
<div class="four columns">
<p><img src="/news-images/thumbs/thumb_<?php echo $row['newsImage1']; ?>" alt=""/></p>
</div>
<div class="eight columns">
<h3><?php echo $row['newsTitle']; ?></h3>
<p><?php echo stripslashes(strip_tags($row['newsDescription'])); ?></p>
</div>
</div>
<?php $tr++; } } else {
echo "No records found!";
}
Use counter variable and check if it is even or odd ?
Create variable, increment that in each loop and check, if $i % 2 is 0 (even) or 1 (odd).
$i = 1;
while($row = $rs->fetch_assoc()){
?>
<div class="news <?php echo $num; echo $i % 2 == 0 ? ' even' : ' odd' ?>">
<div class="four columns">
<p><img src="/news-images/thumbs/thumb_<?php echo $row['newsImage1']; ?>" alt=""/></p>
</div>
<div class="eight columns">
<h3><?php echo $row['newsTitle']; ?></h3>
<p><?php echo stripslashes(strip_tags($row['newsDescription'])); ?></p>
</div>
</div>
<?php
$i++;
}
Take $classname = '';
Get news ID in loop and divide / 2 and compare whether you getting odd / even value. In case odd value add $classname = 'oddCLASS' and in case even value add $classname = 'evenCLASS' and updare class = $classname wherever you required.
This way it will automatically update dynamic class.
so the fastest way to do this is just by using a boolean:
$odd = false;
while ( .... )
{
echo ($odd = !$odd) ? 'odd' : 'even';
}
No need to keep a counter for that, no need for a modulo and it keeps the code pretty clean. My preferred way unless you need to keep a counter. And even then: $counter & 1 == 1 is faster than $counter % 2 == 1 and does exactly the same.
Simple explanation:
echo ($odd = !$odd) ? 'odd' : 'even';
// will become
$odd = ! $odd; // it flips the boolean
if ($odd)
echo 'odd';
else
echo 'even';
I'm making a search form with suggestions from database. All is going good but the problem is when I type "t" it shows the song with t likewise shows the song with s letter as well here is my code:
<?php
include('config.php');
if($_POST) {
$q = $_POST['searchword'];
$sql_res=mysql_query("select * from vass_songs");
while($row=mysql_fetch_array($sql_res)) {
$id=$row['id'];
$title=$row['title'];
$img=$row['img'];
$album_id=$row['album_id'];
$re_title='<b>'.$q.'</b>';
?>
<div class="suggestion_box" align="left">
<a href="/song/<?php echo $id; ?>">
<img src="/static/albums/<?php echo $id; ? >_small.jpg");">
</div><?php echo $title; ?><br/>
<span style="font-size:9px; color:#999999"><?php echo $country; ?></span>
</a>
</div>
<?php
}
} else {
}
?>
try this:
<?php
include('config.php');
if(isset($_POST['searchword'])) {
$q = $_POST['searchword'];
$sql_res=mysql_query("
SELECT *
FROM vass_songs
WHERE title LIKE '%$q%'
");
while($row=mysql_fetch_array($sql_res)) {
$id = $row['id'];
$title = $row['title'];
$img = $row['img'];
$album_id = $row['album_id'];
$re_title = "<b>{$q}</b>";
?>
<div class="suggestion_box" align="left">
<a href="/song/<?php echo $id; ?>">
<img src="/static/albums/<?php echo $id; ?>_small.jpg");">
<div><?php echo $title; ?></div><br/>
<span style="font-size:9px; color:#999999">
<?php echo $country; ?>
</span>
</a>
</div>
<?php
}
} else {
}
?>