I am trying to add ajax functionality to my pagination so the content loads in the same page instead of the user having to navigate to another page when clicking the page links.
I should mention that I am using this php pagination class.
Being new to jquery, I am unsure of how to properly do this with the pagination class.
This is what the main page looks like:
<?php
$categoryId=$_GET['category'];
echo $categoryId;
?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery_page.js"></script>
<?php
//Include the PS_Pagination class
include('ps_pagination.php');
//Connect to mysql db
$conn = mysql_connect('localhost', 'root', 'root');
mysql_select_db('ajax_demo',$conn);
$sql = "select * from explore where category='$categoryId'";
//Create a PS_Pagination object
$pager = new PS_Pagination($conn, $sql, 3, 11, 'param1=value1¶m2=value2');
//The paginate() function returns a mysql
//result set for the current page
$rs = $pager->paginate();
//Loop through the result set
echo "<table width='800px'>";
while($row = mysql_fetch_assoc($rs)) {
echo "<tr>";
echo"<td>";
echo $row['id'];
echo"</td>";
echo"<td>";
echo $row['site_description'];
echo"</td>";
echo"<td>";
echo $row['site_price'];
echo"</td>";
echo "</tr>";
}
echo "</table>";
echo "<ul id='pagination'>";
echo "<li>";
//Display the navigation
echo $pager->renderFullNav();
echo "</li>";
echo "</ul>";
?>
<div id="loading" ></div>
<div id="content" ></div>
Marketing
Automotive
Sports
Any help on this would be great. Thanks.
$("a.category").live("click", showContent)
function showContent()
{
$("#content").load("/url/path/" + $(this).attr("id"));
}
will load either
/url/path/marketing, /url/path/automotive or /url/path/sports
into the content div
Related
I want to display the exact number of new entries (records) on my page of my phpmyadmin database after reloading the page. I looked online but couldn't find anything usefull. Maybe someone can help me. This is the code for the page:
<?php
header("Refresh: 120");
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="verzoekstyle.css">
<title>Verzoekpagina DJ</title>
</head>
<body id="body">
<div id="tabel">
<?php
$con = mysqli_connect('database','username','password');
if (!$con)
{
echo 'Geen verbinding met server';
}
if (!mysqli_select_db($con, 'eventqy179_verzoeken'))
{
echo 'Database niet geselecteerd';
}
$sql = "SELECT * FROM info";
$query = mysqli_query($con,$sql);
if(!$query)
{
echo 'Onbekende fout gevonden';
}
echo '
<table class="table">
<tr>
<th><h3><b>Artiest</b></h3></th>
<th><h3><b>Titel</b></h3></th>
<th><h3><b>Verwijderen</b></h3></th>
</tr>';
while ($row = mysqli_fetch_array($query))
{
echo '<tr>';
echo '<td><h3>'.$row['artiest'].'</h3></td>';
echo '<td><h3>'.$row['titel'].'</h3></td>';
echo '<td><h3><a href=delete.php?id='.$row['id'].'>Verwijderen</a></h3></td>';
echo '</tr>';
}
echo '</table>';
?>
</div>
</body>
</html>
Already found another way, just ORDER BY id DESC. Question is therefor answered
I currently have some php script that outputs results from a query. I would like to add at the end two buttons that will show/hide the final element, but am not sure how to do this.
The following is my php script:
while($result = mysqli_fetch_array($iname))
{
echo "<b>Event Name:</b> " .$result['EventName'];
echo "<br> ";
echo "<b>Location:</b> ".$result['Location'];
echo "<br>";
//this is where I would like to add my two buttons, that would show the "hidden" content when clicked
And here is what I have written in an HTML script, that I would like to reconcile into the PHP output:
<!DOCTYPE html>
<html>
<head>
<scriptsrc="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js></script>
<script>
$(document).ready(function(){
$("#hidden").hide();
$("#hide").click(function(){
$("#hidden").hide(500);
});
$("#show").click(function(){
$("#hidden").show(500);
});
});
</script>
</head>
<body>
<button id="show">Show</button>
<button id="hide">Hide</button>
<p id="hidden">
Some Random Text that will be shown when the buttons are clicked
</p>
</body>
</html>
Any suggestions as to how this should be done?
How about if you get the number of result rows with $num_rows = mysql_num_rows($result);
Then, put a counter in your loop.
$counter = 1;
$theClass="";
while($result = mysqli_fetch_array($iname))
{
if ($counter == mysql_num_rows($result);){
$theClass="showHide";
}
echo "<div class='$theClass'>";
echo "<b>Event Name:</b> " .$result['EventName'];
echo "<br> ";
echo "<b>Location:</b> ".$result['Location'];
echo "<br>";
echo "</div>
$counter++;
}
Then, apply your javascript to the div whose class="showHide"
<?php
require ("init.php");
?>
<head>
<script src="ajax.js"></script>
<script src="common.js"></script>
</head>
<body>
<?php
$query = "SELECT * FROM User1";
$result = mysqli_query($connection, $query);
echo '<form> ';
echo "Select a Users:";
echo '<select name="users" onchange="showUser(this.value)">';
while ($row=mysqli_fetch_assoc($result)){
echo $row=['Username'];
echo '<option value="'.$row=['Username'].'">'.$row=['Username'].'</option>';
}
echo '</select></form>';
?>
<div id="txtHint"><b>User info will be listed here.</b></div>
</body>
the problem i am having is that the drop down box only shows array multiple times and does not show usernames from my database however the connection to my database is working as when tryed debugging it got it to echo out just one username
IT should be like this:
while ($row=mysqli_fetch_assoc($result)){
//echo $row=['Username']; //Invalied here
echo '<option value="'.$row['Username'].'">'.$row['Username'].'</option>';
}
No need that =sign.
Correct:
echo $row=['Username'];// This is unnecessary.
echo '<option value="'.$row=['Username'].'">'.$row=['Username'].'</option>';// what is = doing here?
To:
echo '<option value="'.$row['Username'].'">'.$row['Username'].'</option>';
I've downloaded the jQuery fancybox light box plugin for my gallery... I have a list of images in my database what I want is some extra space in the lightbox for comments descriptions etc!!
Here is my code:
$row1= mysql_query("SELECT * FROM upload_data WHERE user='$user' AND ALBUM='$user_name'");
while ($row=mysql_fetch_assoc($row1)) {
$img=$row['FILE_NAME'];
$src='user_data/'.$img;
$name=$row['ALBUM'];
$id=$row['ID'];
echo "<div style='display:none'>";
echo "<div id='contet'>";
echo "</div>";
echo "</div>";
echo "<a href='$src' class='fancybox' rel='gallery' data='$src' title='$user_name' id=''><img class='fadeto'src='$src'></a>";
echo "";
echo "<p>$user_name</p>";
echo "</div>";
}
Here is what the jQuery looks like
<script>
$(document).ready(function() {
$(".fancybox").fancybox();
});
</script>
What's holding me back is that I've successfully set up my gallery with fancybox. I can add some extra content but when I open it.. it only opens the first image and doesn't proceed to the next one.
I'm using a field in one of my databases to store the song location... When I've got 1 song in the db it plays well onClick. But with 2 or more songs in the database, onClick they all play in sync. How do I loop through the jQuery append statement to act like a PHP while loop? Sorry, I'm still learning jQuery/Javascript... I actually run into this problem allot. So a solution would really help me!
<script src="http://code.jquery.com/jquery-latest.js"></script>
<?php
mysql_connect("localhost", "root", "")or die("Could not connect: " . mysql_error());
mysql_select_db("kevin") or die(mysql_error());
$song_query = mysql_query("SELECT idsongs, songuri, songname FROM songs");
while($row = mysql_fetch_array($song_query)) {
echo "<span class='song'><b>Song Name: </b>";
echo $row['songname'];
echo "<br>";
//echo '<img alt="" id="play" src="play.png" />';
//echo '<div id="audio"></div>';
?>
<script type="text/javascript">
$(document).ready(function() {
$('#play').click(function() {
$("#audio").append('<audio autoplay="true" src="<?php echo $row['songuri'] ?>" /></audio>');
});
});
</script>
<img alt="" id="play" src="play.png" />
<div id="audio"></div>
<?php } ?>
This gives all your songs their own stop/play controls.
<script src="http://code.jquery.com/jquery-latest.js"></script>
<?php
mysql_connect("localhost", "root", "")or die("Could not connect: " . mysql_error());
mysql_select_db("kevin") or die(mysql_error());
$song_query = mysql_query("SELECT idsongs, songuri, songname FROM songs");
while($row = mysql_fetch_array($song_query)) {
echo "<div class='song' sid='".$row['idsongs']."' songuri='".$row['songuri']."'>";
echo "<b>Song Name: </b>";
echo $row['songname'];
echo "<br>";
echo "<img class='play' src='play.png' /><br>";
echo "<div class='audio'></div>";
echo "<div class='stop'>Stop!</div>";
echo "</div>";
}
?>
<script type="text/javascript">
$(document).ready(function() {
$('.play').click(function() {
var songdiv = $(this).parent('div.song');
var songuri = songdiv.attr('songuri');
var sid = songdiv.attr('sid');
// stop this song if it's already playing
stopPlayer(sid);
// play
var audio = '<audio class="player" sid="'+sid+'" autoplay="true" src="'+songuri+'" /></audio>';
$(this).siblings('div.audio').html(audio);
});
$('.stop').click(function(){
var songuri = $(this).parent('div.song').attr('sid');
stopPlayer(songuri);
});
});
function stopPlayer(id) {
var p = $('.player[sid='+id+']');
if (p[0]) {
p[0].pause();
}
}
</script>
It appears to me that you've provided no mechanism to append your autoplay=true to the specific play button that was clicked -- you're appending it to all elements with #audio. Try generating unique ids for every play and div with audio so you can link the two together.
As a first stab, try this:
while($row = mysql_fetch_array($song_query)) {
echo "<span class='song'><b>Song Name: </b>";
echo $row['songname'];
echo "<br>";
echo '<img alt="" id="' + "play-$row[idsongs]" + '" src="play.png" />';
echo '<div id="' + "audio-$row[idsongs]" +'"></div>';
This gives you unique identifiers for all your objects; I don't know JS well enough to suggest how to correlate the audio-$row[idsongs] when a play-$row[idsongs] has been clicked, but surely there must be some way to discover the id of the clicked object, change play to audio, and then append the HTML.