jQuery Hide and Show effect with data from php
Topics related to client-side programming language.
Post questions and answers about JavaScript, Ajax, or jQuery codes and scripts.
-
JanMolendijk
- Posts: 198
- Location: Holland Rotterdam
jQuery Hide and Show effect with data from php
Dear Admin I would love to use this script, but their is a problem with the first record in my sql-table (DESC)
The first record (DESC) is not opening, furter all records are opening
Code: Select all
$sql=mysqli_query($conn,"SELECT * FROM `notice_second` WHERE user='$users[email]' ORDER BY `notice_second`.`notice_id` DESC LIMIT 20");
$rehtm='';
// if the $sql contains at least one row
if(mysqli_num_rows($sql) >0){
//get rows data
while($row = mysqli_fetch_assoc($sql)){
$rehtm .='
<script type="text/javascript"><!--
$(document).ready(function() {
// reveal the tag with id="idd", when the tag with id="btn" is clicked
$("#btn'. $row['notice_id'] .'").click(function(){
$("#idd'. $row['notice_id'] .'").show("slow", function() {
$("#btn'. $row['notice_id'] .'").hide(650);
});
});
});
--></script>
<div id="idd'. $row['notice_id'] .'" style="display:none;">
<iframe src="test.php?notice_id='. $row['notice_id'] .'"
width="100%" height="100%" frameborder="0" scrolling="yes"
align="top" marginwidth="0" marginheight="0" name="offtopic">
</iframe>
</div>
<button id="btn'. $row['notice_id'] .'">Show</button>';
Admin
The php, javascript and html codes are wrong mixed.
It is good to avoid mixing javascript code in php strings.
- Try this:
Code: Select all
<?php
//your code...
$sql=mysqli_query($conn,"SELECT * FROM `notice_second` WHERE user='$users[email]' ORDER BY `notice_second`.`notice_id` DESC LIMIT 20");
$rehtm='';
// if the $sql contains at least one row
if(mysqli_num_rows($sql) >0){
//get rows data
while($row = mysqli_fetch_assoc($sql)){
$rehtm .='<div id="idd'. $row['notice_id'] .'" style="display:none;">
<iframe src="test.php?notice_id='. $row['notice_id'] .'"
width="100%" height="100%" frameborder="0" scrolling="yes"
align="top" marginwidth="0" marginheight="0" name="offtopic">
</iframe>
</div>
<button class="btn_notice_id" id="btn_'. $row['notice_id'] .'">Show</button>';
}
}
echo $rehtm;
?>
//this in the html code
<script type="text/javascript">
$(document).ready(function() {
$('.btn_notice_id').on('click', function(){
var btn_id = $(this).attr('id');
$('#idd'+btn_id.replace('btn_', '')).show('slow', function() {
$('#'+btn_id).hide(650);
});
});
});
</script>
Similar Topics
-
Traffic and Site Access - Records data but not show stats
Scripts from this website
First post
One more question please about this script:
I have one central page that shows the stats for the site. There are pages that I want to log but not...
Last post
that seems to have done it...thank you for both the speed in which you fix problems and your scripts. I recommend this program to anyone that wants...
-
facebook like and share show same number
General Forum
After I included fb-like and fb-share buttons on this website i noticed they show same count number.
When you click like or share button, the count...
-
Register and show Time Spent from ip on website
JavaScript - jQuery - Ajax
First post
Dear admin, I`m searching for round 10 hours for a solution to track & store spending-time from a visitor on the website.
I found a Ajax...
Last post
Maybe it is not working with onunload to execute ajax request when the user closes the page.
Try the following code.
- JavaScript:...
-
Show total results from rating in mysql
PHP - MySQL
First post
I have a rating script where new people able to rate from 1 till 5.
Now i have this simple code what shows the total number of rates:
<?php...
Last post
Thank you so mutch Admin great work
-
Show Dropdown menu from Iframe in main window
PHP - MySQL
First post
Well I have some new problem I`m rebuilding a comment system
& succesfully placed it as Iframe addon but for the smilies I want
to use a...
Last post
The content from iframe cannot be displayed outside it.
To display the menu it the parent window, it must be created in that page.
From iframe you...