Session variables not working correctly - php

In my code i use a for each and for some reason it takes for ever to load and it screws up half way through with not displaying the name or it just does show up.
Code, http://hastebin.com/axutiqaqev.php (Not displaying correctly here)
<?php
$griditems = json_decode(file_get_contents($url));
foreach ($griditems->rgInventory as $index=>$items) {
$_SESSION['itemdesc'] = json_decode(file_get_contents($url));
$_SESSION['itemnamevalue'] = strval($items->classid) . "_" . strval($items->instanceid);
$_SESSION['itemname'] = $_SESSION['itemdesc']->rgDescriptions->$_SESSION['itemnamevalue']->market_name;
//echo $index; // will get index
?>
<div class="col-lg-2 col-sm-3 col-xs-4">
<a href="#">
<p><a class="hovertext" href="#" title="<?php echo $_SESSION['itemname']; ?>"><img src="https://steamcommunity-a.akamaihd.net/economy/image/class/730/<?= $items->classid ?>/150fx125f" class="thumbnail img-responsive"></a></p>
</a>
</div>
<?php
}
session_unset();
?>
Website: csgohighroller.com
Everything is working fine but it stops working after i use it once and when a player has too many items.
Example inventory http://www.csgohighroller.com/backpack.php?id=baconcraze

Related

Pass information from item to a item display page in PHP

OK so I'm doing a web application to sell games.
I've done a cycle to put all the games from the database in the index page.
Now when a user clicks a game it goes to the page with the game's info.
How can I save the info from the database in session variables to use in the other page ?
btw: JOGO = GAME
$stmt = $conn->query('SELECT * FROM JOGO');
foreach ($stmt as $row){
$_SESSION['id_jogo'] = $idJ;
echo '<link href="home/vendor/bootstrap/css/bootstrap.min.php" rel="stylesheet">';
echo '<link href="style.php" rel="stylesheet">';
echo '
<div class="col-lg-4 col-md-6 mb-4" >
<div class="card h-100 ">
<img class="card-img-top" src="http://placehold.it/700x400" alt="">
<div class="card-body">
<h4 class="card-title">
' .$row["nome"].'
</h4>
<h5>' .$row["preco"].'€ </h5>
<p class="card-text">' .$row["descricao"].' </p>
</div>
<div class="card-footer">
<small class="text-muted">Vendedor: </small>
</div>
</div>
</div> ' ;
}
?>
Storing game id in session is not an option. Line
$_SESSION['id_jogo'] = $idJ;
(though I don't know where $idJ comes from), I presume that you want to put game id in session, something like
$_SESSION['id_jogo'] = $row['id']; // assuming id is a primary key.
But this will not work, as this line just overwrites $_SESSION['id_jogo'] on every iteration.
Use standard approach with $_GET parameters, when your page url is itempage.php?game_id=42
In itempage.php you can get game id as $_GET['game_id'] and use it in a query.
So, your markup is something like:
<img class="card-img-top" src="http://placehold.it/700x400" alt="">
Assuming you’re initializing a session somewhere else in your code with session_start() you can create a new session variable name with $_SESSION[‘some_key’] = ‘data’;

how to call columns from database and format it with HTML code

Actually I am beginner programmer in HTML, CSS and PHP. I have simple website for add and register in courses. The user should be add course into website and the courses should be posted on the site.so users can browse and register.
Actually my problem is how to call the course name from database and how to format it with HTML code as I want.
This is the page of courses which is content the list of available courses in website ( please note it is only HTML code, I do that to see how the page will be )
Screenshot of page:
So as you see, the first page include many this HTML code to add course list into website with the following code:
<div class="card card-1">
<a href="http://127.0.0.1/project2/course details/course1.php">
<img src="http://127.0.0.1/project2/icons/coursepic.jpg" alt="Avatar" style="width:101% "></a> <div class="container">
<h4 class="textstyle"><b>Operating System</b> </h4>
<p class="textstyle">Free Course</p>
</div>
</div>
what i want do with PHP?
I want to write a PHP code to replace the P and h4 with the course name, cost of courses from my database for each available course.
Please note: the pic for each course it will be from my pc, no need to call the pic from database.
I tried to write PHP code like below:
<div>
<div class="card card-1">
<a href="http://127.0.0.1/project2/course details/course1.php">
<img src="http://127.0.0.1/project2/icons/coursepic.jpg" alt="Avatar" style="width:101% "></a> <div class="container">
<?php
include_once("db.php");
$result = mysqli_query(OpenCon(), "SELECT Course_Name,cost FROM `course`");
//while($res = mysql_fetch_array($result)) { // mysql_fetch_array is deprecated, we need to use mysqli_fetch_array
while($res = mysqli_fetch_array($result)) {
echo "<p>".$res['Course_Name']."</p>";
echo "<p>".$res['cost']."</p>";
}
?>
</div>
</div>
</div>
This is my result:
It's okay but I want the style to be like the first screenshot. each course should have picture.
After that when the user click on course name. I want move to another page which is content the course details ( for the same course that user clicked ) also it's called for my database
like this:
I hope any one help my to solve this problem only, I should solve this problem within 2 days only. and sorry if my explanation is bad.
Thanks in advance for everyone.
Put the code in a PHP loop.....
So, this
<div class="card card-1">
<a href="http://127.0.0.1/project2/course details/course1.php">
<img src="http://127.0.0.1/project2/icons/coursepic.jpg" alt="Avatar" style="width:101% ">
</a>
<div class="container">
<h4 class="textstyle"><b>Operating System</b> </h4>
<p class="textstyle">Free Course</p>
</div>
</div>
Becomes (after cleaning up the code a bit - I think you didn't mean to use two <p> in there, but I left them so you can see it. Note that using different lines for the segments makes it a lot easier to see what you have.)
include_once("db.php");
$result = mysqli_query(OpenCon(), "SELECT Course_Name,cost FROM `course`");
$count = 0;
while($res = mysqli_fetch_array($result)) {
$count ++;
// NOTE: Here is the LOOP! - not outside the query, but INSIDE it
// First you 'jump out' of PHP, going back to HTML
?> <!-- now you are in HTML (when you need PHP again, you 'jump in' and 'jump out' as needed - see the code below....) -->
<div class="card card-<?php echo $count;?>">
<a href="http://127.0.0.1/project2/course details/course<?php echo $count;?>.php">
<img src="http://127.0.0.1/project2/icons/coursepic.jpg" alt="Avatar" style="width:101% ">
</a>
<div class="container">
<h4 class="textstyle">
<b><p><?php echo $res['Course_Name'];?></p></b>
</h4>
<p class="textstyle">
<p><?php echo $res['cost'];?></p>
</p>
</div>
</div>
<?php // we are in PHP again....
}
That should do what you asked for - though I would go a step (well, more than one...) further and make as much of this dynamic as you can.
For this I will presume that:
your database table has a column called 'id' (if it doesn't, you should have) and it relates to the course number (you could make a course number column if they don't match up, but I'm keeping it simple)
you have all your pictures labeled 'coursepicX' where the X is the course number.
We'll use 'coursepic' as a default in case there isn't a picture yet...
Now, the code is more dynamic!
include_once("db.php");
$result = mysqli_query(OpenCon(), "SELECT id,Course_Name,cost FROM `course`");
while($res = mysqli_fetch_array($result)) {
// NOTE: Here is the LOOP! - not outside the query, but INSIDE it
// First you 'jump out' of PHP, going back to HTML
?> <!-- now you are in HTML (when you need PHP again, you 'jump in' and 'jump out' as needed - see the code below....) -->
<div class="card card-<?php echo $res['id']?>">
<a href="http://127.0.0.1/project2/course details/course<?php echo $res['id']?>.php">
<?php
$pic = "http://127.0.0.1/project2/icons/coursepic.jpg";
if(file_exists("http://127.0.0.1/project2/icons/course" . $res['id'] . ".jpg") {
$pic = "http://127.0.0.1/project2/icons/course" . $res['id'] . ".jpg";
}
<img src="<?php echo $pic; ?>" alt="Avatar" style="width:101% ">
</a>
<div class="container">
<h4 class="textstyle">
<b><p><?php echo $res['Course_Name'];?></p></b>
</h4>
<p class="textstyle">
<p><?php echo $res['cost'];?></p>
</p>
</div>
</div>
<?php // we are in PHP again....
}
Note that this is the basic 'shopping cart' sort of program - you will likely use it many (many) times in your career.
Happy Coding!

Loading data from database with pagination in PHP PDO

I have a website developed using PHP PDO programming. In this website there is one page where the details of holiday packages is listed from database along with pagination. My problem is only 6 records from database is loading in the page, but the pagination shows more than one page. Actually I am using PDO for the first time and I can't manage this problem.
Here is my code
index.class (all database functions are written here)
<?php
include_once "class/common.php";
class INDEX {
var $doAction;
var $msg;
var $objScr;
var $objCommonFunc; // This is common function object.
var $rsltInfo; // A common result set used by this class in various queries.
var $rsltOp; // A common result set used by this class in various queries.
var $arrSysVar; // Array that stores the System Variable those are used in screen.
// Other variables
var $adminEmail;
var $arrMetaContent; // For storing content and meta information.
var $leftMenuId; // Recid of 'menugroup' table for managing leftbar.
var $rightMenuId; // Recid of 'menugroup' table for managing rightbar.
var $menuPos;
function getHolydays($rgnId,$start_from, $record_per_page){
$qrySel = "SELECT h.recid recid, h.regionid regionid, h.name name, h.subtitle subtitle, h.txtDays txtDays, h.txtNights txtNights, h.pricingfrom pricingfrom, h.thumb_img thumb_img
FROM holydays h";
if($rgnId!=0){ $qrySel.= " WHERE h.regionid=".$rgnId; }
$qrySel .=" LIMIT $start_from,$record_per_page";
$objDbResult = $this->rsltInfo->getResult($qrySel);
return $objDbResult;
}
function getHolydaysPagntnCount($rgnId){
$qrySel = "SELECT h.recid recid, h.regionid regionid, h.name name, h.subtitle subtitle, h.txtDays txtDays, h.txtNights txtNights, h.pricingfrom pricingfrom, h.thumb_img thumb_img
FROM holydays h";
if($rgnId!=0){ $qrySel.= " WHERE h.regionid=".$rgnId; }
//echo $qrySel ;
$objDbResult = mysql_query($qrySel);
return $objDbResult;
}
}
$objScr = new INDEX();
?>
international-holidays.php
<?php $active_menu = 'Holidays';
include_once("index.class.php");
include_once 'header.php';
$objScr = new INDEX();
//$region_name="";
//if($_REQUEST['mcId'])$mcId=$_REQUEST['mcId'];
$rgnId=0;
if($_REQUEST['rgnId'])$rgnId=$_REQUEST['rgnId'];
if($_REQUEST['pgId'])
$pgId=$_REQUEST['pgId'];
$start_from=!empty($_REQUEST['page'])?$_REQUEST['page']:0;
//echo $start_from;
$record_per_page=6;
$rsltrgn = $objScr->getRegionname();
$rsltsdrgn = $objScr->getRegionname();
$rsltholyDetails = $objScr->getHolydays($rgnId,$start_from, $record_per_page);
$holydetailscount = mysql_numrows($objScr->getHolydayscount());
$holydaycount = mysql_numrows($objScr->getHolydaysPagntnCount($rgnId));
$total_pages = ceil($holydaycount/$record_per_page);
$rsltbannerDets= $objScr->getbannerImg($rgnId);
$rowbannerdts = $rsltbannerDets->fetchAssoc();
?>
<div class="col-md-8 col-sm-12 col-8">
<div class="right">
<div class="pagination-wrp clearfix">
<nav class="nav-pagination">
<?php //Here is the code for pagination
if($total_pages>0){?>
<ul class="pagination">
<?php if($pgId>1){?>
<li class="active"> <?php $prvpages=$start_from-6; $prev = ($pgId - 1); ?>
<a href="international-holidays-details.php?<?php echo "page=".$prvpages."&rgnId=".$rgnId."&pgId=".$prev; ?>" aria-label="Previous">
<img src="images/left-arrow.svg" alt=""></a></li>
<?php }?>
<?php
if($pgId!="" && $pgId!=1){ $spage=$pgId-1; }else{ $spage=1; $pgId=1; }
$maxPages=5;
$maxDisplayPage = $pgId + $maxPages - 1;
if($total_pages-$spage<5){ $spage=$total_pages-5; }
if($spage<=0){ $spage=1; }
for($i=$spage;$i<=min($maxDisplayPage, $total_pages);$i++){
if($i==1){ $st=0; }
else{
$st = ($i - 1) * $record_per_page;
}
?>
<li <?php if($i==$pgId){?> class="active" <?php }?>>
<a href="international-holidays-details.php?<?php echo "page=".$st."&rgnId=".$rgnId."&pgId=".$i; ?>" >
<?php echo $i; ?></a>
</li>
<?php
}
?>
<li class="active"><?php $nextpages=$start_from+6; if($pgId<$total_pages){ $next = ($pgId + 1); ?>
<a href="international-holidays-details.php?<?php echo "page=".$nextpages."&rgnId=".$rgnId."&pgId=".$next; ?>" aria-label="Next">
<img src="images/right-arrow.svg" alt=""> </a></li>
<?php }?></ul><?php }?>
</nav>
</div>
<?php
if($holydetailscount > 0) {
while($rowhly = $rsltholyDetails->fetchAssoc())
{
//$catgryname=str_split("Hello",3);
?>
<div class="col-sm-6 wow fadeInUp">
//Here the holiday packages as shown in boxes.
<a href="international-holidays-details.php?holyId=<?php echo $rowhly['recid']; ?>" class="offer-thumb">
<div class="offer-img"><img src="../sysimages/origimages/<?php echo $rowhly['thumb_img']; ?>" class="w-100" alt=""></div>
<div class="details clearfix">
<div class="title"><?php echo $rowhly['name']; ?><span><?php echo $rowhly['subtitle']; ?> </span></div>
<div class="price"><span>aed <?php echo $rowhly['pricingfrom']; ?></span>
<?php echo $rowhly['txtDays']; ?> days <?php echo $rowhly['txtNights']; ?> night</div>
</div>
</a>
</div>
<?php } }?>
</div>
</div>
The same code works perfectly in other page. The thing is the pagination shows 5 pages, but when i click on any page for example 2, it doesn't load the 2nd page rather it shows the first page itself.
I didn't understand what is happening. This code has been developed by someone else and my task is to do some updates on this.
Can anyone please help me.. I really needed to get this done.
What about if you use this pluggin? In my case it was very helpfull.
https://mottie.github.io/tablesorter/beta-testing/example-pager-custom-controls.html
Or you can just do it manually using mysql.
Pagination using MySQL LIMIT, OFFSET

Image src with php variable does not display the image on the web page

I wrote a code which is retrive image paths and display on the website in bootstrap grid style.But it does not showing the image. Code is working fine, Please help me. here is my code
<div class="row">
<?while ($row = mysql_fetch_assoc($query)) {?>
<div class = "col-md-3">
<?php echo $row['keywords'];?>
<?php $imagePath = $row['video_url'];?>
<?php echo $imagePath;?>
<div id="video_thumbnail">
<a href="#" class="thumbnail">
<?php echo '<img src="' . $imagePath . '">'; ?>
<img src="<?php echo file_dir . '/' . $imagePath; ?>" height="100" width="100"/>
</a>
</div>
</div>
<?php } ?>
</div>
unless file_dir is a constant using DEFINE, I suspect it's because you didn't put a $ in front of it $file_dir
You are also displaying two files. One with the file path and one without.
Chances are, the mysql query is returning a path which is not linked ....
ie <image src="myImage.jpg" /> is not the same as <image src="images/myImage.jpg" />
As #pmahomme said, right click the element and check the pat and if need be add the additional requirements

Facebook PHP Api suddenly not working

<?php
//get token
$access_token = $facebook->getAccessToken();
$albumCover = $facebook->api("/". $album_id ."?fields=picture", "get");
//echo $albumCover['picture']['data']['url'];
//echo '<pre>';
//print_r($albumCover);
//echo '</pre>';
?>
<div class="fb-album<?php if ($counter % 5 == 0){echo ' no-right';}; ?>">
<a href="<?php the_permalink(); ?>">
<div style="width:160px; height:100px; overflow:hidden;">
<img width="160px" src="<?php echo $albumCover['picture']['data']['url']; ?>" />
</div>
</a>
<p><?php the_title() ?></p>
</div>
All of a sudden this doesnt work, and returns no error, could someone shed some light on this for me?
Thanks
UPDATE:
Found the answer, looks like I could not access the cover photo of each album with ?fields=picture anymore, I had to use ?fields=cover_photo and dig into that array, heres my solution, thanks for all your help STACK
<?php
//get token
$access_token = $facebook->getAccessToken();
$albumCover = $facebook->api("/". $album_id ."?fields=cover_photo", "get");
//echo $albumCover['picture']['data']['url'];
$albumCover2 = $facebook->api("/". $albumCover['cover_photo'] ."?fields=picture", "get");
//echo '<pre>';
//print_r($albumCover2);
//echo '</pre>';
?>
<div class="fb-album<?php if ($counter % 5 == 0){echo ' no-right';}; ?>">
<a href="<?php the_permalink(); ?>">
<div style="width:160px; height:100px; overflow:hidden;">
<img width="160px" src="<?php echo $albumCover2['picture']; ?>" />
</div>
</a>
<p><?php the_title() ?></p>
</div>
I appologize for the formatting, its quite hard to make it look right in this editor
Whenever Facebook API does not get data or does not work,
it logs error in PHP's error log. Check your PHP error log.
There was a breaking changes release today; it's worth checking out the release notes to see how you might have been affected. At a guess, something to do with the privacy changes...
You also need to use setAccessToken method after getAccessToken.
$access_token = $facebook->getAccessToken();
$facebook->setAccessToken($access_token);
As per the error message your have posted in the comment,
If the index active does not exist then you get notice error mod_fcgid. To avoid that you can do check if that index is set / exists.
Code:
if($blah['active']=="something"){foo();}
Should be:
Code:
if(isset($blah['active']) && $blah['active']=="something"){foo();}

Categories