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: 140
- 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...
-
Show Inline the Divs into a parent
HTML - CSS
First post
I have this code
<section class= b-search >
<div class= container >
<h1 class= wow zoomInUp data-wow-delay= 0.3s >UNSURE WHICH...
Last post
Those elements are set display:inline; , but the problem is from their width . They have set: width:33.3% but there are 4 elements, so, put width:24%...
-
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 html code from php string in textarea
PHP - MySQL
First post
I wanna add text into an textarea where i have html code into the title but it does not show the whole html code into the textarea.
Title:...
Last post
In <textarea> you not have to add data in value attribute, but between starting and ending tags.
Try simple like this:
Title: <textarea...