How to fix:Parse error: syntax error, unexpected ',' in /home/monkeybu/public_html/index.php on line 2 [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Can some one help me fix this?
Parse error: syntax error, unexpected ',' in /home/monkeybu/public_html/index.php on line 2
I am using x10hosting for my host.
Here's my code:
<?php
require_once "lib/steam-condenser.php",
require_once "config.php";
$id = $_GET['sid'];
$getData = SteamId::create($id);
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/main.css" type="text/css" media="screen">
<link rel="stylesheet" href="css/jquery.maximage.css" type="text/css" media="screen" title="CSS" charset="utf-8" />
<script type="text/javascript" src="js/progressbar.js"></script>
</head>
<body>
<section id="downloadInfo">
<div id="progressBarText"><span id="fileName">filename.vmt </span><span id="downloadPresent"><b>0%</b></span></div>
<div id="progressBar"><div></div> </div>
</section>
<section id="playerInfo" style="margin-left: 15%;">
<?php
echo '
<img src="'.$getData->getFullAvatarUrl().'" width="299">
<ul>
<li style="width: 70%;"><h1 id="serverName">serverName</h1></li>
<li style="width: 60%;"><h2>'.$getData->getNickname().'<span class="steamid">['.SteamId::convertCommunityIdToSteamId($id).']</span></h2></li>
<li style="width: 50%;"><h3 id="mapName">mapName</h3></li>
</ul>';
?>
</section>
<?php
if($loadingScreen['backgroundMusic'] != "")
{
$ytLink = explode("v=", $loadingScreen['backgroundMusic']);
echo '<iframe width="1" height="1" src="//www.youtube.com/embed/'.$ytLink[1].'?autoplay=1" frameborder="0" style="opacity: 0;"></iframe>';
}
?>
<div id="maximage">
<?php
$imgDir = scandir("images/backgrounds/");
$picNum = 0;
foreach($imgDir as &$files)
{
$picNum++;
if($picNum >= 3)
{
echo "<img src='images/backgrounds/".$files."' alt='' width='1400' height='1050' />\n";
}
}
?>
</div>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.js'></script>
<script src="js/jquery.cycle.all.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.maximage.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(function(){
jQuery('#maximage').maximage();
});
function GameDetails( servername, serverurl, mapname, maxplayers, steamid, gamemode )
{
document.getElementById("serverName").innerHTML = servername;
document.getElementById("mapName").innerHTML = mapname;
}
function SetFilesTotal( total ) {
var totalFiles = total;
}
function SetFilesNeeded( needed ) {
var filesLeft = needed;
var present = (totalFiles / filesLeft);
document.getElementById("downloadPresent").innerHTML = present + "%";
progressBar(Math.round(present), $('#progressBar'));
}
function DownloadingFile( fileName ) {
document.getElementById("fileName").innerHTML = fileName;
}
</script>
<footer>
</footer>
</body>
</html>
config:
<?php
$loadingScreen['backgroundMusic'] = "http://www.youtube.com/watch?v=0UjsXo9l6I8"; //Only youtube links.. (for now). (if you dont want to play music leave it blank)
?>
steam:
<?php
/**
* This code is free software; you can redistribute it and/or modify it under
* the terms of the new BSD License.
*
* Copyright (c) 2010-2013, Sebastian Staudt
*
* #author Sebastian Staudt
* #license http://www.opensource.org/licenses/bsd-license.php New BSD License
* #package steam-condenser
*/
define('STEAM_CONDENSER_PATH', dirname(__FILE__) . '/');
define('STEAM_CONDENSER_VERSION', '1.3.6');
require_once STEAM_CONDENSER_PATH . 'steam/community/SteamId.php';

This line:
require_once "lib/steam-condenser.php",
//- ^ should be a semi-colon
should have a semi-colon and not a comma
require_once "lib/steam-condenser.php";
Dagon, sorry I saw your comment after I posted this.

Related

Fatal error: Uncaught ArgumentCountError: Too few arguments to function galleryClass::listGallery() [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 16 hours ago.
Improve this question
Fatal error: Uncaught ArgumentCountError: Too few arguments to
function galleryClass::listGallery(), 0 passed in
D:\xampp\htdocs\gallery\manage\listGallery.php on line 5 and exactly 1
expected in D:\xampp\htdocs\gallery\manage\gallery\galleryClass.php:16
Stack trace:#0 D:\xampp\htdocs\gallery\manage\listGallery.php(5):
galleryClass->listGallery()#1 {main} thrown in
D:\xampp\htdocs\gallery\manage\gallery\galleryClass.php on line 16
What could be wrong here? I looked through the forum threads with similar titles but the solutions given in them don't fit here. Below I insert the files mentioned in the log.
listGallery.php
<?php
include_once './inc/header.php';
include_once './gallery/galleryClass.php';
$galleryClass=new galleryClass();
$listAlbum=$galleryClass->listGallery();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../../../favicon.ico">
<title>Justified Nav Template for Bootstrap</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
<link href="https://getbootstrap.com/docs/4.0/examples/justified-nav/justified-nav.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="masthead">
<br/>
<h3 class="text-muted">List Album</h3>
<br/>
<?php include_once './inc/navbar.php'; ?>
</div>
<!-- Example row of columns -->
<div class="col-md-6">
<table class="table table-bordered table-striped">
<thead>
<tr><th>Id</th><th>Name</th></tr>
</thead>
<tbody>
<?php
if(count($listAlbum)){
foreach ($listAlbum as $value) {
echo "<tr><td><img src='../galleryImage/$value[ImageName]' width='50px' height='50px'></td><td>$value[AlbumId]</td></tr>";
}
}
?>
</tbody>
</table>
</div>
</div> <!-- /container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script src="../../../../assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="http://getbootstrap.com/assets/js/vendor/popper.min.js"></script>
<script src="http://getbootstrap.com/dist/js/bootstrap.min.js"></script>
</body>
</html>
galleryClass.php
<?php
require_once ( dirname( __FILE__). '/../functions/connectionClass.php' );
class galleryClass extends connectionClass{
public function uploadGallery($image){
$insert="Insert into gallery (ImageName) values ('$image')";
$result=$this->query($insert);
if($result){
echo "File is uploaded";
}
else
{
echo "File is not uploaded";
}
}
public function listGallery($query){
$select="select * from gallery $query";
$result=$this->query($select);
$count=$result->num_rows;
if($count< 1){
}
else
{
while ($row = $result->fetch_array()) {
$rows[]=$row;
}
return $rows;
}
}
public function addAlbum($name){
$insert="Insert into album (AlbumName) values ('$name')";
$result=$this->query($insert);
if($result){
echo "Album created";
}
else
{
echo "Album not created";
}
}
public function listAlbum(){
$select="select * from album";
$result=$this->query($select);
$count=$result->num_rows;
if($count< 1){
}
else
{
while ($row = $result->fetch_array()) {
$rows[]=$row;
}
return $rows;
}
}
}

Is there a way to automatically use another image as a temporary placeholder for missing images sitewide?

I am working on building a site, but right now it has several images that I don't have actual images for yet. As this site has thousands of images or places where images should be, I don't want to have to manually change each of them and then change them again when I find the correct image. Is there a way to create a function that will look for the missing images and replace them with a specified image until the correct image is found?
Update: Since I am still a bit confused as to where to even place this function, I am going to add the code for one of the pages that I need this for then maybe someone can help me figure out how to place it.
Here is the code for one of the pages:
<?php
require_once('dbconnection.php');
mysqli_select_db($conn, $dbname);
$query_master = "SELECT DISTINCT * FROM `master_list` INNER JOIN types_join ON master_list.join_id=types_join.join_id WHERE `type_id` = 171 ORDER BY `item_id`";
$master = mysqli_query($conn, $query_master) or die(mysqli_error());
$row_master = mysqli_fetch_assoc($master);
$totalrows_master = mysqli_num_rows($master);
?>
<!doctype html>
<html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flower Trees</title>
<link href="/css/styles.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" type="image/png" href="img/favicon.png">
</head>
<body>
<div class="wrapper">
<a id="top"></a>
<?php require_once('header.php'); ?>
<?php require_once('nav.php'); ?>
<div class="category"><h2>Flower Trees</h2></div>
<div class="display">
<?php do { ?>
<ul>
<li><a href="details.php?recordID=<?php echo $row_master['master_id']; ?>"><img class="thumb" src="img/<?php echo $row_master['img']; ?>"/>
<br />
<span class="name"><?php echo $row_master['name']; ?></span></a></li>
</ul>
<?php } while ($row_master = mysqli_fetch_assoc($master)); ?>
<!-- end .display --></div>
<?php
mysqli_free_result($master);
?>
<?php require_once('footer.php'); ?>
<!-- end .wrapper --></div>
<script>
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
</script>
</body>
</html>
Since this is as simple as a foreach loop, and not tons of images scattered across your webpage, you can use something like:
$image = file_exists('img/' . $row_master['img']) ? 'img/' . $row_master['img'] : 'placeholder.png';
Full code:
<?php
require_once('dbconnection.php');
mysqli_select_db($conn, $dbname);
$query_master = "SELECT DISTINCT * FROM `master_list` INNER JOIN types_join ON master_list.join_id=types_join.join_id WHERE `type_id` = 171 ORDER BY `item_id`";
$master = mysqli_query($conn, $query_master) or die(mysqli_error());
$row_master = mysqli_fetch_assoc($master);
$totalrows_master = mysqli_num_rows($master);
?>
<!doctype html>
<html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flower Trees</title>
<link href="/css/styles.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" type="image/png" href="img/favicon.png">
</head>
<body>
<div class="wrapper">
<a id="top"></a>
<?php require_once('header.php'); ?>
<?php require_once('nav.php'); ?>
<div class="category"><h2>Flower Trees</h2></div>
<div class="display">
<?php do {
$image = file_exists('img/' . $row_master['img']) ? 'img/' . $row_master['img'] : 'placeholder.png';
?>
<ul>
<li><a href="details.php?recordID=<?php echo $row_master['master_id']; ?>"><img class="thumb" src="<?php echo $image; ?>"/>
<br />
<span class="name"><?php echo $row_master['name']; ?></span></a></li>
</ul>
<?php } while ($row_master = mysqli_fetch_assoc($master)); ?>
<!-- end .display --></div>
<?php
mysqli_free_result($master);
?>
<?php require_once('footer.php'); ?>
<!-- end .wrapper --></div>
<script>
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
</script>
</body>
</html>
I don't want to have to manually change each of them and then change them again when I find the correct image. Is there a way to create a function that will look for the missing images and replace them with a specified image until the correct image is found?
Such a function might be written as:
function im($imgName) {
$pathToImgs = "images/";
if (file_exists( $pathToImgs . $imgName )) {
echo $pathToImgs . $imgName;
}
else {
echo $pathToImgs . "placeholder.jpg";
}
}
Then in your html:
<img src="<?php im("product1.jpg"); ?>">
<img src="<?php im("product2.jpg"); ?>">
<img src="<?php im("product3.jpg"); ?>">
As a start.
***Edit 1:
Given your code where it says:
<img class="thumb" src="img/<?php echo $row_master['img']; ?>"/>
You might modify it with a conditional that inserts the placeholder image in the event that the target image simply doesn't exist, yet.
<img class="thumb" src="<?php
if (file_exists("img/" . $row_master['img'])) {
echo "img/" . $row_master['img'];
}
else {
echo 'img/placeholder.jpg';
}
?>">
You could reuse this functionality by turning the conditional into a php function, so described as a starter above.
Using jQuery, you can accomplish something easy enough using a global $('img') handler when errors occur. Simply swap them out with your placeholder image afterwards.
$('img').on('error', function() {
const oldSrc = encodeURIComponent($(this).attr('src'));
$(this).attr('src', `https://via.placeholder.com/300/000000/FFFFFF/?text=${oldSrc}`);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img src="imagethatdoesntexist.jpg"><br />
<img src="anotherimage.jpg">
Here I use placeholder.com (A convenient site for placeholder images such as this), and inject the old image source into the query string, which the site will render in the image itself.

PHP: Captain Oh Captain, My Switch Case Sucks

I'm trying to build a simple switch case demo here and I had it working on my school server and am now trying to carry it over to my server now that the quarter is over. I don't know what happened, the switch case was working but no longer is and I am trying to repair it. Paths are good, and i've gone through the file forwards and backwards trying to find the error in my logic, looked for missing semicolons, and everything else that i can think to do. I'm stumped and not sure what the issue is but it seems my switch case isn't delivering anything and is somehow broken.
The switch case, when working, would ideally display the date, a poster graphic and unique background image to the client (Browser).
jpg of how page would display: http://school.max-o-matic.com/itc240/_img/img_240a010sm.jpg
Link to page: http://school.max-o-matic.com/itc240/itc240_a020/index.php
<?php
/*
* a3_Dates-Conditionals.php
*
* Create a page with the following functionality:
* Use PHP to deliver a different image and bit of content
* for each weekday (Sunday to Saturday) using one PHP file.
*
* STAGE1 - Build it static (check)
* STAGE2 - build with variables (test, check)
* STAGE3 - Build with conditionals
*/
//http://us1.php.net/manual/en/function.date.php
$today = date("D, M j");
$test = ' ';
//http://www.php.net/manual/en/control-structures.switch.php
$strSun = ' ';
$strMon = ' ';
$strTues = ' ';
$strWeds = ' ';
$strThurs = ' ';
$strFri = ' ';
$strSat = ' ';
$linkSun = 'bg_img01.jpg';
$linkMon = 'bg_img02.jpg';
$linkTues = 'bg_img03.jpg';
$linkWeds = 'bg_img04.jpg';
$linkThurs = 'bg_img05.jpg';
$linkFri = 'bg_img06.jpg';
$linkSat = 'bg_img07.jpg';
$linkPoster = ' ';//isn't setting
switch (intval(date("N"))) {
case 0:
$strSun = 'class="current"';
$todayIs = 'Sunday'; //isn't setting
$linkSun = "bg_imgSpecial.jpg";
$linkPoster = 'img_poster-01.jpg';
break;
case 1:
$strMon = 'class="current"';
$todayIs = 'Monday';
$linkMon = "bg_imgSpecial.jpg";
$linkPoster = 'img_poster-02.jpg';
break;
case 2:
$strTues = 'class="current"';
$todayIs = 'Tuesday';
$linkTues = "bg_imgSpecial.jpg";
$linkPoster = 'img_poster-03.jpg';
break;
case 3:
$strWeds = 'class="current"';
$todayIs = 'New Comic book Day!';
$linkWeds = "bg_imgComicBooks.jpg";
$linkPoster = 'img_poster-04.jpg';
break;
case 4:
$strThurs = 'class="current"';
$todayIs = 'Thursday';
$linkThurs = "bg_imgSpecial.jpg";
$linkPoster = 'img_poster-05.jpg';
break;
case 5:
$strFri = 'class="current"';
$todayIs = 'Friday';
$linkFri = "bg_imgSpecial.jpg";
$linkPoster = 'img_poster-06.jpg';
break;
case 6:
$strSat = 'class="current"';
$todayIs = 'Saturday';
$linkSat = "bg_imgSpecial.jpg";
$linkPoster = 'img_poster-07.jpg';
break;
}
?>
<!DOCTYPE html>
<html lang="en">
<head> <title>a3 | itc240 (w14)</title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
<link rel="stylesheet" href="css/layout.css" type="text/css" media="all">
<link rel="stylesheet" href="css/prettyPhoto.css" type="text/css" media="all">
<link rel="stylesheet" href="css/style.css" type="text/css" media="all">
<script type="text/javascript" src="js/jquery-1.6.js" ></script>
<script type="text/javascript" src="js/cufon-yui.js"></script>
<script type="text/javascript" src="js/cufon-replace.js"></script>
<script type="text/javascript" src="js/Ubuntu_400.font.js"></script>
<script type="text/javascript" src="js/Ubuntu_700.font.js"></script>
<script type="text/javascript" src="js/bgSlider.js" ></script>
<script type="text/javascript" src="js/script.js" ></script>
<script type="text/javascript" src="js/pages.js"></script>
<script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="js/bg.js" ></script>
<script type="text/javascript" src="js/tabs.js"></script>
<script type="text/javascript" src="js/jquery.prettyPhoto.js"></script>
<!--[if lt IE 9]>
<script type="text/javascript" src="js/html5.js"></script>
<![endif]-->
<!--[if lt IE 7]>
<div style='clear:both;text-align:center;position:relative'>
<a href="http://www.microsoft.com/windows/internet-explorer/default.aspx?ocid=ie6_countdown_bannercode">
<img src="http://storage.ie6countdown.com/assets/100/images/banners/warning_bar_0000_us.jpg" border="0" alt="" /></a>
</div>
<![endif]-->
</head>
<body id="page1">
<div class="spinner"></div>
<div id="bgSlider"></div>
<div class="extra">
<div class="main">
<div class="box">
<!-- header --> <header> <h1>Max | <sup>itc</sup>240</h1>
<nav>
<ul id="menu">
<li> <br > <img src="images/<?=$linkPoster;?>" alt=""> </li>
<li><strong><?=$today;?></strong></li>
</ul>
</nav>
</header>
<!--content -->
<article id="content">
<div class="ic"><!--Content Here... --</div>
</article id="content">
<!-- / content -->
</div>
</div>
<div class="block"></div>
</div>
<div class="bg1">
<div class="main">
<!-- footer -->
<footer>
<div class="bg_spinner"></div>
<ul class="pagination">
<li <?=$strSun;?> >S</li>
<li <?=$strMon;?> >M</li>
<li <?=$strTues;?> >T</li>
<li <?=$strWeds;?> >W</li>
<li <?=$strThurs;?> >Th</li>
<li <?=$strFri;?> >F</li>
<li <?=$strSat;?> >S</li>
</ul>
<div class="col_1">
ZZZ
</div>
<div class="col_2">
<a rel="nofollow" href="http://www.max-o-matic.com/" target="_blank"> </a>
<!-- {%FOOTER_LINK} -->
</div>
</footer>
<!-- / footer-->
</div>
</div>
<script type="text/javascript"> Cufon.now(); </script>
<script>
$(window).load(function() {
$('.spinner').fadeOut();
$('body').css({overflow:'inherit'})
})
</script>
</body>
</html>
I just ran your code on my own server,
First of all, date("N") returns 1-7, and not 0 to 6, so you'll be missing one.
As a habit, always add default: to a case switch, so you can catch unexpected results.
Try using date("w") instead. (lowercase w)
Other than that, Your code is fine
According to the documentation the PHP date function N format specifier returns a value in the range 1-7. Your switch statement is expecting 0-6. Today is Sunday, so the date call is returning 7 and your switch statement isn't handling that.

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.

JEditable Not Saving in Mysql

I don't know if this is correct - I just followed the example on the jeditable website, but I can't seem to be able to get this simple code working. I just want to save the data into the database and still show the changes on the page.
Below is my code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" debug="true">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Jeditable WYSIWYG Custom Input Demo</title>
<meta name="generator" content="Mephisto" />
<link href="http://www.appelsiini.net/stylesheets/main2.css" rel="stylesheet" type="text/css" />
<link rel="alternate" type="application/atom+xml" href="http://feeds.feedburner.com/tuupola" title="Atom feed" />
<script src="/mint/?js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js""
type="text/javascript" charset="utf-8"></script>
<script src="http://www.appelsiini.net/projects/jeditable/wysiwyg/wysiwyg/jquery.wysiwyg.js" type="text/javascript"></script>
<link rel="stylesheet" href="http://www.appelsiini.net/projects/jeditable/wysiwyg/wysiwyg/jquery.wysiwyg.css" type="text/css" media="screen" charset="utf-8">
<script src="http://www.appelsiini.net/projects/jeditable/jquery.jeditable.js" type="text/javascript" charset="utf-8"></script>
<script src="http://www.appelsiini.net/projects/jeditable/wysiwyg/jquery.jeditable.wysiwyg.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
$(function() {
/* Fix FireBug */
/*
if ($.browser.mozilla) {
window.loadFirebugConsole();
};
*/
/* Handle links inside editable area. */
$('.editable > a').bind('click', function() {
$(this).parent().trigger('click');
return false;
});
$('#wysiwyg_2').editable('test-jedit.php',
{
id : 1,
content : 'wysiwyg_2',
indicator : '<img src="../img/indicator.gif">',
type : 'POST',
type : 'wysiwyg',
width : 640,
height : 'auto',
onblur : 'ignore',
submit : 'OK',
cancel : 'Cancel',
wysiwyg : { controls : { separator04 : { visible : true },
insertOrderedList : { visible : true },
insertUnorderedList : { visible : true }
}
}
});
});
</script>
<style type="text/css">
#sidebar {
width: 0px;
}
#content {
width: 770px;
}
</style>
</head>
<body>
<div id="wrap">
<div id="header">
<p>
<h1>Jeditable</h1><br />
<small>Edit in place plugin for jQuery.</small>
<ul id="nav">
<li id="first">weblog</li>
<li>projects</li>
</ul>
</p>
</div>
<div id="content">
<div class="entry">
<p>You might also want to check other custom inputs demo.
<h2>Extra settings</h2>
<div style="width: 640px" class="editable" id="wysiwyg_2"><img
src="%5C%22http://%5C%22"><span style="\"font-weight:" bold;\"="">gdgfd<span style="font-style: italic;">
gfd</span><big><br>sdfsdf<br>sdfsdf<br><br></big></span></div>
</div>
<div id="sidebar">
</div>
<div id="footer">
</div>
</body>
</html>
Here's the PHP code:
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$id = $_POST['id'];
$content = $_POST['content'];
mysql_query("INSERT INTO editable (id, content)
VALUES ('$id', '$content')");
echo $content;
mysql_close($con);
?>
The first thing to say is please read the php.net page about SQL Injection
To your problem ...
I think I might have spotted a problem ... your JavaScript is being executed before the DOM is ready ... enclose your javascript code (all of it) within the following block :
$(document).ready(function() {
// your code here
});
This means that the code within the function will only be executed once the whole page has been loaded ... calling functions on DOM elements that are not loaded will cause you issues ... further reading on ready() ...
Looking at the code I can see no obvious issue - however there are few basic things you can do to debug this issue ... first off check (using something like firebug) that the AJAX request is actually being sent ...
Secondly you can check the the PHP MySQL code is working correctly ...
$result = mysql_query($query); // execute your query
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
// if you get to here the query worked fine ...
Update
I took your code and created a jsfiddle
There are a few minor changes needed to get it working :
<div style="width: 640px" class="editable" id="wysiwyg_2">
<img src="%5C%22http://%5C%22"><span style="\"font-weight:" bold;\"="">gdgfd
<span style="font-style: italic;"> gfd</span>
<big><br>sdfsdf<br>sdfsdf<br><br></big></span></div>
should be :
<div style="width: 640px" class="editable" id="wysiwyg_2"><span style="font-weight: bold;">gdgfd<span style="font-style: italic;">
gfd</span><br>sdfsdf<br>sdfsdf<br><br></span></div>
I have removed the strange characters !
Update 2
When the OK button is pressed the PHP is called - it POSTs the following data :
1:wysiwyg_2
value:<span style="font-weight: bold;">gdgfd<span style="font-style: italic;">
gfd</span><big><br>sdfsdf<br>sdfsdf<br><br></big></span>
So in your PHP you need to change $_POST['content'] to $_POST['value']

Categories