PHP get record in page from URL - php

I have database name is "db" Table is 'tbl_pro' is Feild are "msid" "subid" "pid" and "pname".
when I try to fetch the data through "msid" from URL it is working fine on a new page. but through "pname" I am not able to get it. here is my code
Page 1 code:
<?
$QryP=mysql_query("Select * from tbl_pro where Pname='test' order by Rank desc") or die("Error loading Products");
if(mysql_num_rows($QryP)>0) {
while($rs=mysql_fetch_array($QryP)){
?>
<div class="col-md-3 col-sm-4 ">
<div class="w-box product">
<figure>
<img alt="" src="upload/spic/<?=$rs["Spic"]?>" class="img-responsive img-center">
</figure>
<h2><?=$rs["Pname"]?></h2>
<p>
on the other page its.
Page 2 code:
<?
$QryP=mysql_query("Select * from tbl_pro where Pname=".$_REQUEST["Pname"]." AND Display='y'" ) or die("Error loading Products");
if(mysql_num_rows($QryP)>0) {
while($rs=mysql_fetch_array($QryP)){
?>
if i use "msid" instead of "Pname" its working fine.

Its better to go with the like operator when you were using a string in a query
if(isset($_REQUEST['Pname'])){$Pname=$_REQUEST['Pname'];}else{$Pname='';}
if(Pname!=''){
$QryP=mysql_query("Select * from tbl_pro where Pname like '%".$Pname."%' AND Display='y'" ) or die("Error loading Products");

Related

How can I display only certain images from my database that have the same ID and not just display all of them?

This image shows that I assigned different house_ID's for each image. Despite that, I would like to display images that have the same house_id, instead of just displaying all of them. For example, I would like to only display images with the house_id of 4. Does anyone know how to do this?
This is my current code which just displays all of them in a slide show.
<?php
// Include the database configuration file
include_once 'dbConfig.php';
// Get images from the database
$query = $db->query("SELECT * FROM images2 ORDER BY house_id DESC");
?>
<div class="frame">
<div class="slideshow-container">
<?php if($query->num_rows > 0){
while($row = $query->fetch_assoc()){
$imageURL = 'uploads2/'.$row["file_name"];?>
<div class="mySlides fade">
<img style="height: 200px;" src="<?php echo $imageURL; ?>">
</div><?php }?>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div></div>

PHP gallery album

i am writing a php script that retrieves images from a database and shows them on page inside an album , each album contains several images...
here is an example for the code below :
$sql = "SELECT * FROM tbl_album where status='process' ORDER BY albumid DESC LIMIT $start_from, 12";
<?php
$rs_result = mysql_query ($sql,$con);
while ($row = mysql_fetch_assoc($rs_result))
{
$aid=$row['albumid'];
$aimage=$row['image'];
$aname=$row['name'];
$astatus=$row['status'];
echo '<div class="col-lg-4 col-md-6 col-sm-6 agile_gallery_grid">';
echo '<div class="hover ehover14">';
?>
<?php
echo"<a href='#details?d=$aid' onclick='showfunction()'>";
echo "<img src='admin/acatch/$aimage' class='img-responsive' alt='$aname' width='200' height='200' data-picture_id='$aid'>";
echo'</a>';
}
?>
this code shows all the albums contained in the database ,
but what i want to do is that when i click on the album cover , i want to display the images inside it on the same page , but i am not able to pass the album id to another php script on the same page to do this,
please if anyone can help
thank u in advance
Have a look at the following code:
<?php
$sql = "SELECT * FROM tbl_album where status='process' ORDER BY albumid DESC LIMIT $start_from, 12";
$rs_result = mysql_query($sql, $con);
while($row = mysql_fetch_assoc($rs_result)):
$aid=$row['albumid'];
$aimage=$row['image'];
$aname=$row['name'];
$astatus=$row['status'];
?>
<div class="col-lg-4 col-md-6 col-sm-6 agile_gallery_grid">
<div class="hover ehover14">
<a href='#details?d=$aid' onclick='showfunction()'>
<img src="admin/acatch/<?=$aimage?>" class="img-responsive" alt="<?=$aname?>" width="200" height="200" data-picture_id="<?=$aid?>">
</a>
</div>
</div>
<div class="gallery_album" id="gallery_album_<?=$row['albumid']?>">
<?php
/**
* now collect all images associated with each album by using $aid
*/
$sql_images = "SELECT * FROM tbl_album_images WHERE fk_album_id = $aid";
$images_result = mysql_query($sql_images, $con);
while($image = mysql_fetch_assoc($images_result)):
?>
<div class="gallery_album_image"><img src="<?=$image['dir_and_filename']?>"></div>
<?php
endwhile;
?>
</div>
<?php endwhile; ?>
What we are doing here is gettign all the albums as you allready does. But we introduce a subquery inside the first while-loop to fetch all associated images for each album.
We put these images inside new div-container with a unique album id you can use to show or hide the actual album with your showfunction()
Use CSS and javascript to show or hide accordingly.
OBS! WARNING!! Your mysql queries, and the one I provided, is very very BAD!
Have a look into prepared statement using php PDO or mysqli...

Load php query in div onclick

I'm loading photos from database with mysql query. For default it load data from database with pagination.
<div class="col-md-10 bg col-md-push-2 ">
<div class="align_center gallery">
<?php
include "anj.php";
$sql = 'SELECT * FROM new_photos ;
/* function anjaan content code for loading photos .*/
anjaan($sql);
}
?>
</div>
<div class=" align_center ">
<div class=" col-md-12 pagination gallery">
<?php
echo $paginationctrl;
?>
</div>
</div>
Now I want when user click a button data should change with this
<?php
include "anj.php";
$sql = 'SELECT * FROM new_photos WHERE weight BETWEEN 10 AND 15';
anjaan($sql);
?>
Php is just server side, so i think u only will have two options.
1 - On click reload de page and send a post or get params to the application usign form and then load the page with the new query.
2 - If u want to do not reload te page, will be better to send an Ajax request to server side with JavaScript and then bring and replace the old content for the new one.

Looping through PHP database with columns that link to specific profiles

I have a website where I am getting information of college student profiles on a database and displaying it as a linked collection. When I'm looping through the database I want to give each row a specific link to the profile of the student. Right now I am linking it to "profilePage.html" with generic information but I want it to be correlated with the row the user chose on the last(college) page.How do I save/transfer that information to the page. I do not want multiple profile pages but one template that is filled with the user previous choice.
<?php
$result = mysql_query("SELECT * FROM student_info WHERE college='Boston College'", $db);
if (!$result) {
die("Database query failed: " . mysql_error());
}
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
?>
<a href="profilePage.html" class="collection-item">
<div class="row summary">
<div class="col s4 center">
<img class = "profile-pic" src="img/defaultProfile.jpg">
</div>
<div class="col s8">
<div class="title"> <?php echo $row[student_Name]; ?> </div>
<div class="black-text condensed thin"><i class="tiny material-icons">today</i> Founder, CEO at Linkle since January 1st, 2015</div>
<div></div>
</div>
</div>
</a>
<?php } ?>
Key thing, my urls are mysite.com/college.php and have no id's to specify them.
Structure of the Database student_info:
Shows the structure of the database
First, do you have an URL Rewriting ? If not, your target page should be a PHP page, like profilePage.php.
Your link to this page have to include a parameter (Query String) which is, for example, the student's ID :
<a href="profilePage.php?id=<?php echo $row['id'] ?>" class="collection-item">
This type of URL will be generated: profilePage.php?id=36
In profilePHP.php, retrieve the parameter in the Query String :
<?php
$idStudent = mysql_real_escape_string($_GET['id']);
?>
mysql_real_escape_string() is really important, it prevents SQL injections.
After that, you could retrieve the student's informations with a SQL query.
<?php
$idStudent = mysql_real_escape_string($_GET['id']);
$sql = sprintf("SELECT * FROM student_info WHERE id = %s", $idStudent);
$query = mysql_query($sql);
$student = mysql_fetch_object($query);
// you should check if the ID exists, and if there is 1 result
?>
<p>Student name is <?php echo $student['student_Name'] ?></p>
A little advice: mysql_query() will disappear soon, you should take a look at PDO.

background image in div doesn't show with PHP

I'm trying to give an div a background image that is attached to a specific post (zo everytime there is another image needed). I'm retrieving the URLS out of the database and then put it into the following code:
<div class="parallax_banner" style="background-image:url(<?= "_/".$rowImage['imgPath']."/".$rowImage['imgName'] ?>)"></div>
the whole code:
<?
$result = mysql_query("SELECT * FROM `items` WHERE `itemID` = ".$_GET['postID'])or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
$resultImage = mysql_query("SELECT * FROM `images` WHERE `itemID` =".$row['itemID']." LIMIT 1")or die(mysql_error());
while ($rowImage = mysql_fetch_assoc($resultImage)) {
?>
<div class="paginaBannerWrapper">
<div class="paginaBannerSlideshow">
<div class="parallax_banner" style="background-image:url(<?= "_/".$rowImage['imgPath']."/".$rowImage['imgName'] ?>)"></div>
</div>
</div>
<div id="content">
<div id="bigTitle">
<h1><?=$row['itemTitle']?></h1>
</div>
<div id="centerContent">
<div id="colDesc">
<div class="itemContent"><?=$row['itemContent']?></div>
</div>
<div id="colImg"><img src="<?= "_/".$rowImage['imgPath']."/".$rowImage['imgName'] ?>"/></div>
<?
}
}
?>
</div>
</div>
It's doesn't show anything, but If I test the link with <img src= instead of background-image:url() it shows up. So the path is right. How to solve this?
If you are using background-* css settings you need to give the div some dimensions of height and width or it will default to none and you will not see your image.

Categories