Get userid in Popup - php

<head>
<link type='text/css' href='css/osx.css' rel='stylesheet' media='screen' />
<script type='text/javascript' src='js/jquery.js'></script>
<script type='text/javascript' src='js/jquery.js'></script>
<script type='text/javascript' src='js/jquery.simplemodal.js'></script>
<script type='text/javascript' src='js/osx.js'></script>
</head>
<?php
$myuser = 3;
$a = mysql_query('SELECT cmc.coursemoduleid, cma.sourcecmid, cmc.userid
FROM course_modules_completion, course_modules_availability cma
WHERE cmc.userid = '.$myuser.'');
echo '<table>
<tr><th>Course Module ID</th><
<th>Course Module ID</th>
</tr>';
foreach($a as $aa)
{
$mid = $aa->coursemoduleid;
$sid = $aa->sourcecmid;
$user = $aa->userid;
<tr><td>'.$user.'</td>
<td>'.$mid.'</td>
<td>'.$sid.'</td>
<td>
<div id="container">
<div id="content"><div id="osx-modal">View More
</div></div>
<div id="osx-modal-content">
<div class="close">X</div>
<div id="osx-modal-data">';
echo $user.'Welcome Here';
</div></div>
</td>
</tr>';
}
echo '</table>';
?>
I want to get $user value in popup (If suppose If the $myuser is 6 in a table then even i should get 6 inside the popup when I click viewmore). My popup was working exactly no errors in jquery just I need to pass $user value inside popup.
Right now, it displays only the first userid 9 in all popups.
Could anyone suggest me?

You need to give the user id to the popup.
<script type='text/javascript'>
function showUser(userID)
{
var userWindow = window.open(url, "User", "width=600,height=400");
}
</script>
<a href="#" class="osx" onclick="showUser(<?= $user ?>)">

Related

DataTables failing to be applied to a table

I'm trying to use DataTables but for some reason, it doesn't seem to be working. I'm using Bootstrap 4 and I need buttons from DataTables so that I can export the table later. I think I've added everything I need but it's not showing up. anyone know why it hasn't worked? The table is being posted from a database, it works just fine in bootstrap and all the information shows up but as soon as I try to add DataTables to it nothing seems to change.
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include_once('connection.php');
if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['someAction']))
{
func();
}
function func()
{
$conn = mysqli_connect("localhost", "root", "", "SportsDB");
}
session_start();
if( !isset($_SESSION['username']) ){ /* Change into role = teacher or admin*/
header('Location:login.php');
}
print_r($_SESSION);
?>
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset="UTF-8">
<title>Register exporting</title>
<!--- Link to Bootstrap 4 -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<!-- Link to Data Tables -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/jszip-2.5.0/dt-1.10.18/b-1.5.4/b-flash-1.5.4/b-html5-1.5.4/datatables.min.css"/>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/bs4/jszip-2.5.0/dt-1.10.18/b-1.5.4/b-flash-1.5.4/b-html5-1.5.4/datatables.min.js"></script>
<!-- Link to jquery -->
<script
src="http://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
</head>
<body>
<div class='container-fluid' style='margin-top: 20px'>
<div class="row">
<div class="col-md-8 mx-auto">
<table class="table table-bordered table-hover" id='example'>
<thead>
<tr>
<td>ID</td>
<td>Username</td>
<td>T1_choice</td>
<td>T2_choice</td>
<td>T3_choice</td>
</tr>
</thead>
<tfoot>
<tr>
<td>ID</td>
<td>Username</td>
<td>T1_choice</td>
<td>T2_choice</td>
<td>T3_choice</td>
</tr>
</tfoot>
<tbody>
<?php
ini_set("display_errors", 1);
$stmt = $conn->query('SELECT * FROM Student_Choices');
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo '<tr>
<td>'.$row['Unique_ID'].'</td>
<td>'.$row['Username'].'</td>
<td>'.$row['T1_Choice'].'</td>
<td>'.$row['T2_Choice'].'</td>
<td>'.$row['T3_Choice'].'</td>
</tr>
';
}
?>
</tbody>
</table>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#example').DataTable();
} );
</script>
</body>
</html>
Thanks for the help. I needed to call the jquery before DataTables.

Turning data retrieved from mysql database into chart

For some reason my chart will not load up . The user enters a date , php send query to mysql that recieves data and displays a table, underneath that table i want a chart to be displayed using the google API's. Can someone please help here is my code.
<!doctype html>
<html>
<head>
<!-- links to scripit for jquery drop down calendar -->
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src= "//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<!-- links to CSS style sheets -->
<link href="styles/main.css" rel="stylesheet" type="text/css">
<link href="styles/date.css" rel="stylesheet" type="text/css">
<link href="styles/date2.css" rel="stylesheet" type="text/css">
<meta charset="utf-8">
<title>Cartridge Details</title>
<!--The following script tag downloads a font from the Adobe Edge Web Fonts server for use within the web page. We recommend that you do not modify it.-->
<script>var __adobewebfontsappname__="dreamweaver"</script>
<script src="http://use.edgefonts.net/short-stack:n4:default;abel:n4:default;annie-use- your-telescope:n4:default.js" type="text/javascript"></script>
</head>
<!-- php connection to database to query table for Cartridge Details -->
<?php
$username = "root";
$password = "*******";
$hostname = "localhost";
$my_db = "print_consump";
//connection to the database
$dbhandle = mysqli_connect($hostname, $username, $password, $my_db)
or die("Unable to connect to MySQL");
echo "cond";
?>
<body>
<div class="divH">
<header id="heading1">Cartridge Details</heade>
</div>
<div class="LinkedPages">
<form method="post" action="cartridgedetails.php" name="frm1">
<div>
Date:<input type="text" name="YEAR" value="Enter Year (i.e '2013')">
<input type="submit" value="submit">
</div>
</form>
<span></span>
<?php
//formula for toner usage total pages/35000 = #toner used for month
if(isset($_POST["YEAR"])) {
$year = $_POST['YEAR'];
$result = mysqli_query($dbhandle,"SELECT `Servers`, `Total Pages` / 35000 FROM summaryofserver WHERE
RIGHT(Servers,4) = '$year'");
$data = array(array('Server, Month, Year', 'Number of Toner Cartridges Used'));
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row[0] . "</td>";
echo "<td>" . $row[1] . "</td>";
echo "</tr>";
$data[] = array($row[0], $row[1]);
}
}
?>
<script>
function drawChart () {
var data = google.visualization.arrayToDataTable(<?php echo json_encode($data, JSON_NUMERIC_CHECK); ?>);
// draw a ColumnChart
// you can change this to whatever chart type you need
var chart = new google.visualization.ColumnChart(document.querySelector('#myChart'));
chart.draw(data, {
// chart options, eg:
height: 400,
width: 600
});
}
google.load('visualization', '1', {packages: ['corechart'], callback: drawChart});
</script>
<div id="myChart"></div>
</div>
</body>
</html>

How do I make a pagination system with PHP? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a PHP page that displays my MySQL table's data four rows at a time. If there are, for example, nine rows, the first page would be http://webste.ca/usedunits.php?page=1 and would display the first four rows. The second page would be http://webste.ca/usedunits.php?page=2 and would display the fifth to the eigth rows, and the third page would be http://webste.ca/usedunits.php?page=3 and would display the ninth row.
I am trying to make a link that appears as an arrow that will send the user to http://webste.ca/usedunits.php?page=2 if they are on http://webste.ca/usedunits.php?page=1. If they are on page two there will be a link to page 3, and so on.
I am also trying to make a link that appears as a fast forward button that will send the user to the very last page. My problem is actually making this function.
Here is my full PHP page code:
<?php
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$dbhost = 'dnam';
$dbuser = 'kabm';
$dbpass = 'Kazer';
$dbname = 'kam';
$connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
if(! $connection )
{
die('Could not connect: ' . mysqli_error());
}
$start_from = ($page-1) * 4;
$sql = "SELECT * FROM `used_trailers` ORDER BY `orderid` ASC LIMIT $start_from,4";
$rs_result = mysqli_query ($connection, $sql);
echo mysqli_error( $connection );
?>
<!doctype html>
<!--[if lt IE 7]> <html class="ie6 oldie"> <![endif]-->
<!--[if IE 7]> <html class="ie7 oldie"> <![endif]-->
<!--[if IE 8]> <html class="ie8 oldie"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="">
<!--<![endif]-->
<head>
<meta name="author" content="Kelsey Nealon(Kelseynealon#gmail.com), Contract Web Developer" />
<meta name="description" content="GBM Trailer Service Ltd. Calgary-based, proudly serving the tanker and bulk goods transportation industry for over 25 years." />
<meta name="keywords" content="Tanker, Barrel, Parts, Betts, Camloc, Scully, Lubecore, Dixon, GBM, Flotech" />
<title>GBM Trailer Service Ltd. ::: Service</title>
<link rel="stylesheet" type="text/css" media="screen" href="css/mobilemenu.css"/>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="boilerplate.css" rel="stylesheet" type="text/css">
<link href="responsiveused.css" rel="stylesheet" type="text/css">
<link href="perfect-scrollbar.css" rel="stylesheet" type="text/css" />
<!--
To learn more about the conditional comments around the html tags at the top of the file:
paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/
Do the following if you're using your customized build of modernizr (http://www.modernizr.com/):
* insert the link to your js here
* remove the link below to the html5shiv
* add the "no-js" class to the html tags at the top
* you can also remove the link to respond.min.js if you included the MQ Polyfill in your modernizr build
-->
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- jQuery library (served from Google) -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<!-- include Cycle2 -->
<script src="jquery.mousewheel.js"></script>
<script src="perfect-scrollbar.js"></script>
<script src="jquery.cycle2.min.js"></script>
<script>
$(document).ready(function(){
$(".nav-button").click(function () {
$(".nav-button,.primary-nav").toggleClass("open");
});
});
</script>
<script>
jQuery(document).ready(function ($) {
"use strict";
$('.Default').perfectScrollbar();
});
</script>
<script src="respond.min.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-45342007-3', 'gbmtrailer.ca');
ga('send', 'pageview');
</script>
</head>
<body bgcolor="#102540">
<div class="gridContainer clearfix">
<div id="div1" class="fluid">
<div id="navcontain"></div>
<div id="wrapper">
<div id="cover"></div>
<div id="mainnaviphone">
<img id="logo" src="images/gbmlogo.jpg" alt="G.B.M. Trailer Service LTD. Logo" title="G.B.M. Trailer Service LTD. Logo"/>
<img src="images/newunitsbutton.png" alt="New Units Button" title="New Units Button" id="buto1">
<img src="images/usedunitsbutton.png" alt="Used Units Button" title="Used Units Button" id="buto2">
<img src="images/homebutton.png" alt="home" title="Home" id="homebuto"/>
<img src="images/previousbutton.png" alt="previous" title="Previous" id="prevbuto"/>
<img src="images/nextbutton.png" alt="next" title="Next" id="nextbuto"/>
</div>
<div id="background2">
<div id="textcontrol">
<?php
while ($row = mysqli_fetch_assoc($rs_result)) {
?>
<div id='used1'>
<div id='rigtitle' class="contentHolder Default">
<? echo $row["title"]; ?>
</div>
<table class="infotabe1"><tr><td class="desctde">Description: </td><td rowspan="2" id="content_1" class="infotde contentHolder Default"><? echo $row["description"]; ?></td></tr></table>
<table class="infotabe"><tr><td class="desctd">Make: </td><td id="content_1" class="infotd contentHolder Default"><? echo $row["make"]; ?></td></tr></table>
<table class="infotabe"><tr><td class="desctd">Model: </td><td id="content_1" class="infotd contentHolder Default"><? echo $row["model"]; ?></td></tr></table>
<table class="infotabe"><tr><td class="desctd">Year: </td><td id="content_1" class="infotd contentHolder Default"><? echo $row["year"]; ?></td></tr></table>
<table class="infotabe"><tr><td class="desctd">Price: </td><td id="content_1" class="infotd contentHolder Default"><? echo $row["price"]; ?></td></tr></table>
<!-- Unit Picture -->
<img src='images/<? echo $row["photo"]; ?>' id='mainimage'>
<a href='#'><img src='images/picturesandspecsbutton.png' alt='Pictures and Specs' title='Pictures and Specs' id='picsandspecsbuto'></a>
</div>
<?php
};
?>
</div>
<div id="description" class="resize">
<p><u>Click</u> or call for more information or enquiries.</p>
</div>
<div id="bottomquote">
Your Certified Tanker Trailer Specialist
</div>
<div id="bottomcontactinfo">
<em>Phone <a style="color:white; text-decoration:none;" href="tel:1-4032799717">403 279 9717</a> or <a style="color:white; text-decoration:none;" href="tel:1-888-426-9717">1 888 426 9717</a> 9300 Endeavor Dr. SE, Calgary Alberta, T3S 0A1<br /><a style="color:white; text-decoration:none;" href="mailto:info#gbmtrailer.ca">info#gbmtrailer.ca</a>
</div>
<img src="images/visamastercardlogos.gif" id="visamastercardlogos" alt="Visa and Mastercard Logo" title="Visa and Mastercard Logo">
<img id="mycart" src="images/mycart.gif" alt="My Cart" title="My Cart">
</div>
</div>
</div>
</div>
<script>
<!--
var autoSizeText;
autoSizeText = function() {
var el, elements, _i, _len, _results;
elements = $('.resize');
console.log(elements);
if (elements.length < 0) {
return;
}
_results = [];
for (_i = 0, _len = elements.length; _i < _len; _i++) {
el = elements[_i];
_results.push((function(el) {
var resizeText, _results1;
resizeText = function() {
var elNewFontSize;
elNewFontSize = (parseInt($(el).css('font-size').slice(0, -2)) - 1) + 'px';
return $(el).css('font-size', elNewFontSize);
};
_results1 = [];
while (el.scrollHeight > el.offsetHeight) {
_results1.push(resizeText());
}
return _results1;
})(el));
}
return _results;
};
autoSizeText(); // here is where we call the function.
</script>
</body>
</html>
<?php
$sql = "SELECT COUNT(`orderid`) FROM `used_trailers`";
$rs_result = mysqli_query($connection, $sql);
$row = mysqli_fetch_row($rs_result);
$total_records = $row[0];
$total_pages = ceil($total_records / 4);
$sqlef = 'SELECT * FROM `used_trailers`';
$rs_resultt = mysqli_query($connection, $sqlef);
$rowcount = mysqli_num_rows($rs_resultt);
$record_start = $start_from + 1;
$record_end = $record_start + 3;
// Remember to check against the max record
if ($record_end > $total_records) {
$record_end = $total_records;
}
echo "Showing ".$record_start." - ".$record_end." of ".$rowcount." results ";
echo "asd<a href='usedunits.php?page=".$i."'>".$i."</a>";
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='usedunits.php?page=".$i."'>".$i."</a> ";
};
?>
If you want to put a link to the last page, you need to know what the last page will be.
The way to do that is to do an additional query to your database asking for the total number of items matching the criterias, and with that and your step (i.e. number of items per page) calculating the number of pages.
In your example that query would be
SELECT count(*) FROM `used_trailers`
P.S. assuming you put the result of that query in a $count variable, the last page (counting from 1) would then be ceil($count / 4) (with a corner case for $count == 0), 4 being the number of items you show on each page according to your code.

Issue with Follow/Unfollow buttons

I have this program below that does a simple follow/unfollow function. Everything works great except that when I refresh the page only the first user in the row retains the correct follow/unfollow button. Example I can follow user1 user2 and user3 but when I refresh only user1 still says FOllOWING. Not sure what the issue is, maybe someone can spot a flaw in the code. Thanks.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css" media="screen"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery.livequery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.buttons > a').livequery("click",function(e){
var parent = $(this).parent();
var getID = parent.attr('id').replace('button_','');
$.post("follow.php?id="+getID, {
}, function(response){
$('#button_'+getID).html($(response).fadeIn('slow'));
});
});
});
</script>
</head>
<body>
<br clear="all" />
<div id="content">
<br clear="all" />
<br clear="all" />
<?php
$test = $fgmembersite-> UserID();
$userip = $_SERVER['REMOTE_ADDR'];
$result = mysql_query("SELECT fgusers.*, tblimage.* FROM fgusers LEFT JOIN tblimage ON tblimage.userid = fgusers.id_user");
while ($row = mysql_fetch_array($result))
{?>
<div class="digg-panel">
<div class="img-username">
<img alt="<?php echo $row['username']?>" src="<?php echo $row['photo']?>.png" width="40" height="40" class="userImage" alt="" />
<div class="user-title">
<?php echo $row['name']?>
<?php echo $row['username']?>
</div>
</div>
<?php
$res = mysql_query("select * from tblfollowers where follower_id = '$test' AND username = ".$row['id']);
$check_result = #mysql_num_rows(#$res);
if($check_result > 0)
{?>
<span class="buttons" id="button_<?php echo $row['id_user']?>"><a class="btn-following" href="javascript: void(0)"></a></span>
<?php
}
else
{?>
<span class="buttons" id="button_<?php echo $row['id_user']?>"><a class="btn-follow" href="javascript:void(0)"></a></span>
<?php
}?>
<br clear="all" />
<div class="bio">
<?php echo $row['email']?>
</div>
</div>
<?php
}?>
</div>
<br clear="all" />
</body>
</html>
If you can implement your click event like below.May be your problem will solve.Try it.
$('.buttons > a').expire("click").livequery("click",function(e){
});
For more information check jQuery Live Query Plugin Documentation
I hope this will help to you.

how to get json data in a list with link

Hi i am able to get json data as a list in html page but i like to get as a list of link. Because when i click on the link it will show details.
What i have done in tenantlistmob.php
<?php
include('connection.php');
$result = mysql_query("SELECT * FROM tenanttemp");
while ($row = mysql_fetch_assoc($result))
{
$array[] = array($row['TenantFirstName']);
}
echo json_encode($array);
?>
Then my html page is
<!DOCTYPE HTML>
<html>
<link rel="stylesheet" href="../jasmine-device_2/styles/main.css" />
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
jQuery.getJSON("tenantlistmob.php", function (jsonData) {
jsonData= eval(jsonData);//get json array
for (i = 0; i < jsonData.length; i++)//iterate over all options
{
for ( key in jsonData[i] )//get key => value
{
$("#getname").append($("<li></li>").html(jsonData[i][key]), document.all ? i : null);
}
}
});
});
</script>
</head>
<body>
<form name="index">
<div id="getname"></div>
</form>
</body>
</html>
The output is
Humayun
Sahjahan
Bayezid
Bayezid
Asaduzzaman
Mouri
I am getting the TenantFirstName as a list.But i like to get it as a list of link.Because when i click on a name it will show details of that name. How can i do both work(as a list of link and when click on a link it will show details in a html page query from mysql database)?
Please help.
use table like below
<!DOCTYPE HTML>
<html>
<link rel="stylesheet" href="../jasmine-device_2/styles/main.css" />
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
jQuery.getJSON("tenantlistmob.php", function (jsonData) {
$("#user_spec").html("");//clear old options
jsonData= eval(jsonData);//get json array
for (i = 0; i < jsonData.length; i++)//iterate over all options
{
for ( key in jsonData[i] )//get key => value
{
//$("#user_spec").get(0).add(new Option(jsonData[i][key],[key]), document.all ? i : null);
//$("#getname tbody").append($("<li></li>").html(jsonData[i][key]), document.all ? i : null);
var tblRow = "<tr>" + "<td>" + "<a href='#'>" + jsonData[i][key] + "</a>" + "</td>" + "</tr>"
$(tblRow).appendTo("#getname tbody");
}
}
});
});
</script></head>
<body>
<form name="index">
<div>
<table id="getname" border="1">
<thead>
<th>Name</th>
</thead>
<tbody>
</tbody>
</table>
</div>
</form>
</body>
</html>

Categories