Good day! I'm using datatable that shows a list for students and active and deactive as a hyperlink.
It works on page 1 but on page 2 or when I search the data my function which is the active and deactive doesn't work..
This my codes to deaactive an active acccount:
<td class="text-center">
<?php if($row->Status=='Active') echo 'Active'; ?>
<?php if($row->Status=='Inactive') echo 'Inactive'; ?>
</td>
Related
I have a code in PHP that prints HTML elements based on the information we got in the database, so if we have for example 8 products the code will print 8 divs with the following elements inside
h1 the id of this element will be the same as the product in the database
input for client name
buy button that send the ID of the H1 to the database
here is some code i made
<?php
while($row=$consulta->fetch())
{
?> <img src="<?php echo $row["Imagen"];?>"style="width:12rem;height:12rem;" alt="Scotter" >
<br>
<div>
<h4 id="<?php echo $row["ID_Scooter"]; ?>"> <?php echo $row["ID_Scooter"]; ?> </h4>
<br>
<?php
echo $row["Nombre"];
?>
<br>
<?php
echo $row["Descripcion"];
?>
<br>
<?php
?>
<button onclick="abrir()">Alquilar</button>
<br>
</div>
<?php
}
?>
JavaScript
function abrir(){
var dialog = document.getElementById('favDialog');
dialog.show();
var id=document.getElementById("heres is where im supposed to get the id of the id i clicked");
alert("div id is="+id);
}
php assing ID for example (3,4,5,6,7) but when i click the button inside the div with id=5 it prints the id=3 no matter which button i click
please note that you've set onclick="abrir()" without passing any specific data!
you have got 2 way to do it:
1- passing data with php:
HTML:
abrir(<?php echo $row["ID_Scooter"]; ?>)
and use it in your js :
function abir(id){
let id_scooter = id;
...
}
2- passing clicked element with js:
HTML:
onclick="abrir(this)"
JS:
function abir(el){
let id_scooter = (el).attr(id);
...
}
So I have this code:
Javascript:
<script>
function hidenow(id) {
var divelement = document.getElementById(id);
var button = document.getElementById("hidebutton");
if(divelement.style.display == 'none')
divelement.style.display ='block',
button.style.display = "block";
else
divelement.style.display = 'none',
button.style.display = "none";
}
</script>
And two buttons:
<p>Programma's waarop u kunt abonneren:</p>
<form action="#" enctype="multipart/form-data" method="post">
<?php wp_nonce_field( 'set_programma_action', 'set_programma' ); ?>
<table>
<?php foreach ( $retrieve_data as $retrieved_data ) { ?>
<tr>
<th>Programma:</th>
<td id="hideit" style="vertical-align: middle;">
<?php
echo $alreadysub; echo esc_html( $retrieved_data->Anaam );
?>
</td>
<th>
<button id="hidebutton" style="display:block" onclick="hidenow('hideit')" name="programma" type="submit" value="<?php echo esc_attr( $retrieved_data->Anaam ); ?>">Abonneer</button>
</th>
</tr>
<?php } ?>
</table>
</form>
<!-- Dit stuk code laat de programma's zien waar de radiostation al op geabonneerd is. -->
<br>
<p>De programma's waarop u geabonneerd bent:</p>
<form action="#" enctype="multipart/form-data" method="post">
<?php wp_nonce_field( 'set_programmatest_action', 'set_programmatest' ); ?>
<table>
<?php foreach ( $retrieve_data as $retrieved_data ) { ?>
<tr>
<th>Programma:</th>
<td style="vertical-align: middle;"><?php echo esc_html( $retrieved_data->meta_value ); ?></td>
<th>
<button name="programmatest" type="submit" id="button" value="<?php echo esc_attr( $retrieved_data->meta_value ); ?>">Abonnement opzeggen</button>
</th>
</tr>
<?php }
?>
</table>
</form>
At the moment, when I click a button; it dissapears. But it comes back as soon as the data is submitted to the database and the page is refreshed. I want the button (along with the program that comes with it) to dissapear. I already tried making a isset. But this results in BOTH buttons dissapearing and not just one.
Example:
This is the first button, it is written in the second piece of code. When I click one button, it needs to dissapear along with the program. I tried doing this using isset but it resulted in the button dissapearing all together (both).
I also have this button:
I have done nothing to this button, since I do not want it.
I have tried looking on Stack Overflow and several articles and youtube videos. I have been busy making this for a week but I do not know how to make it work.
How can I make sure that the first button is not shown even after the data is submitted in the db or after the page is refreshed?
Have you tried https://developer.mozilla.org/pt-BR/docs/Web/API/Event/preventDefault ?
This stops the page from refreshing.
document.getElementById("form").addEventListener("click", function(event){
event.preventDefault()
});
You have to add some condition which checks whether to display button or not.
After submitting form you can set localStorage data and in your logic first check for this localStorage, if it is set do not display button otherwise display them.
This way if someone also refreshes page the localStorage will not loose and your button will not display.You can reset localStorage through your code to display them again.
Otherwise you can do on page load check for data / value in database, if it exist do not display the button otherwise display them.
I want show post with for-each. My condition is 1st show 5 post and hide other post with a show more button if loop has more than 5 post, then when I click show more then will show other post and hide show more button and show less more button. If post has less then 5 then no showing show more button. How can I do that by jQuery?
<?php
foreach ($hotel_data as $key => $hoteldata)
{
//Show 3 lowest price of hotel link
if(isset($hoteldata[0]->rooms)){
/*$ii = 0;*/
foreach ($hoteldata[0]->rooms as $key => $bookinginfo) {
?>
<tr>
<td class="">
<div class="hotel_name">
<?php echo $bookinginfo->desc; ?>
</div>
</td>
<td class="booking-img">
<img src="http://pics.avs.io/hl_gates/100/30/<?php echo $bookinginfo->agencyId; ?>.png"/>
</td>
<td>
<div class="hotel-price">
Price : $ <?php echo $bookinginfo->price; ?>
</div>
</td>
<td class="booking-url">
BOOK NOW
</td>
</tr>
<?php
/*$ii++;
if($ii > 2){
break;
}*/
}
}
}
?>
You need to re-think your strategy. What you want can be best achieved with AJAX calls. Therefore you need to write your loop with with JS /jQuery. PHP would only handle the retrieval of posts.
For example, you can create an AJAX call that sends a POST request to a PHP script, sending the number of posts you would want. When PHP receives the request, it fetches the posts needed from the DB and sends the results back in JSON format, JS will then parse the results into your HTML.
The AJAX call can be called once at page load (loads first 5), then it can be called again when the "load more" button is clicked.
Take count of array if more than 5 show "show more" button. Please see example below:
<?php
// Get count
$count = count($hotel_data);
foreach ($hotel_data as $key => $hoteldata) {
//Show 3 lowest price of hotel link
if(isset($hoteldata[0]->rooms)) {
/*$ii = 0;*/
foreach ($hoteldata[0]->rooms as $key => $bookinginfo) {
?>
<tr>
<td class="">
<div class="hotel_name">
<?php echo $bookinginfo->desc; ?>
</div>
</td>
<td class="booking-img">
<img src="http://pics.avs.io/hl_gates/100/30/<?php echo $bookinginfo->agencyId; ?>.png"/>
</td>
<td>
<div class="hotel-price">
Price : $ <?php echo $bookinginfo->price; ?>
</div>
</td>
<td class="booking-url">
BOOK NOW
</td>
</tr>
<?php
}
}
if ($count>5) {
// Code for "show more" button
}
}
?>
Then you have to hide other post by some css class's style property display: none;.
For jQuery code, you have to make script on show more button and change property of other posts you have hide. Also change button text to "show less".
I am working on a simple Chat right now, its already working, but its not very efficient.
Whenever I run my script it refreshes the whole Chat and loads the content over and over again.
Im trying to find a way that the script only loads new content from my chat database, the old messages shouldnt load over and over again.
This is the part from my index.php:
<div id="chat" class="full rund">
<table border="1" class="full chattable">
<?php
$abfrage = "SELECT * FROM chat";
$ergebnis = mysql_query($abfrage);
while($row = mysql_fetch_object($ergebnis)) {?>
<tr class="chattr">
<td style="width:200px;"><h3 class="text">ƬψƬ ☢ <?php echo $row->name;?>:</h3></td>
<td style="width:440px;"><p><h3 class="text"><?php echo $row->text;?></h3></p></td>
<td style="width:160px;"><h3 class="text"><?php echo $row->timestamp;?></h3></td>
</tr>
<?php
}
?>
</table>
</div>
This is my chat.js:
setInterval( "updateShouts()", 1000 );
function fx(form,target){
var _target=target;
var url=form.action;
var data=$(form)[(form.method.match(/^post$/i))?'serializeArray':'serialize']();
$(_target).load(url,data,function(){setTimeout(function(){
$(_target).empty();
},0);});
return false;}
function updateShouts(){
$('#chat').load('php/latestMsg.php');
}
My latestMsg.php (same as index):
<div id="chat" class="full rund">
<table border="1" class="full chattable">
<?php
$abfrage = "SELECT * FROM chat";
$ergebnis = mysql_query($abfrage);
while($row = mysql_fetch_object($ergebnis)) {?>
<tr class="chattr">
<td style="width:200px;"><h3 class="text">ƬψƬ ☢ <?php echo $row->name;?>:</h3></td>
<td style="width:440px;"><p><h3 class="text"><?php echo $row->text;?></h3></p></td>
<td style="width:160px;"><h3 class="text"><?php echo $row->timestamp;?></h3></td>
</tr>
<?php
}
?>
</table>
</div>
I hope anyone can help me, ive been searching for a long time now and I couldnt find anything that solves my problem!
Thanks :)
2 Solutions.
You will need a way to mark your messages as read, per user of course.
You can ignore that and only read back the last X messages.
in your chat table, you must add 'unread' field or something, to identify the message status (read/unread) , same like #geggleto solution
add filter to your query to something like this :
$abfrage = "SELECT * FROM chat WHERE timestamp between '$from' AND '$to' ";
to make sure you have a role to limit message by time
Just wondering if there is a way that I can add discounts to the shopping cart in Opencart.
Basically im wanting customers to be able to select an option, i,e size, then add bulk amounts to the shopping cart. This would then add say 1000 of this item directly to the shopping cart. Im trying to get something like this:
Buy 1000 or more for only £5.00 per unit [Add to cart]
Buy 2000 or more for only £4.50 per unit [Add to cart]
Here is my code so far, unfortunatly Im not sure how to get this working correctly so any help would be great.
Thanks!
<?php if ($discounts) { ?>
<br />
<div class="discount">
<?php foreach ($discounts as $discount) { ?>
<div class="discount-item">
<h3>Buy <?php echo $discount['quantity']; ?> or more for only <?php echo $discount['price']; ?></h3>
<a onClick="addToCart('<?php echo $product['product_id']; ?>');" class="button"><?php echo $button_cart; ?></a>
</div>
<?php } ?>
</div>
<?php } ?>
It's unclear exactly what you're asking for. But if it's any help, the addToCart method that comes with the default template accepts an optional second field, which is the quantity. So you could do:
<a onClick="addToCart('<?php echo $product['product_id']; ?>', <?php echo $discount['quantity']; ?>);" class="button"><?php echo $button_cart; ?></a>
Edit for items with options:
I'll assume you're on the product page, as you need to select the options somehow... now we could clone the whole function that submits the data to the cart. But I think this is easier to manage:
First, change the link to look like this:
<a class="buy-bulk" data-quantity="<?php echo $discount['quantity']; ?>" class="button"><?php echo $button_cart; ?></a>
Then add the following near the bottom:
<script type="text/javascript">
$(document).ready(function() {
$('.buy-bulk').on('click', function() {
var quantity = $(this).data('quantity');
// change the quantity
$('input[name="quantity"]').val(quantity);
// simulate a click on the "add to cart button"
$('#button-cart').trigger('click');
})
});
</script>
NOTE: untested! :)