Page not loading until refresh - php

i'm having a little problem on a website:
Some of the pages doesn't load automatically when reached after clicking on a link.
For example if i go directly to this page http://www.micheleferrotti.it/photo_shop.php?id=1 it works properly but if i click of the "SHOP" http://www.micheleferrotti.it/ it shows a grey empty page until i perform a page refresh.
Coa someone help me to understand where is the issue?
Please consider that php script in the page only generate image boxes and if it can be usefull i'm attaching it here below:
$files = glob("images/photo_shop/$id_catalogo/*.*");
echo '<div id="img_row">';
for ($i=0; $i<count($files); $i++)
{
$num = $files[$i];
$cleanName = str_replace("images/photo_shop/$id_catalogo/","",$num);
if ($i > 0 and $i % 6 == 0) {
echo '</div><div id="img_row">';
}
echo '<div class="img_box" id="img_box">
<a href="'. $num .'" rel="lightbox" title="'.$cleanName.'">
<img src="'.$num.'" alt="'.$num.'" width="120px" height="120px" style="padding:2px" />
</a>
<a href="'.$cleanName.'" class="over_img buy white">
COMPRA FOTO
</a>
</div>';
}
echo '</div>';

Related

simple php pagination or css pagination with php/mysql

I am trying to built a simple php pagination ( a sort of ).
or to be more specific css pagination with php/mysql.
Accessing and storing the values from db
while($row = $result->fetch_assoc()) {
$id[]=$row["id"];
$name[]=$row["name"];
$url[]=$row["url"];
//echo "id: " . $row["id"]. " - Name: " . $row["name"]. " " . $row["url"]. "<br>";
}
Displaying them
<ul class="pagination">
<li>«</li>
<?php
$i=1;
for ($x = 0; $x < count($id); $x++) { ?>
<li>
<a href=<?php echo "$url[$x]"; ?> target="iframe1"
title="<?php echo "$name[$x]"; ?>"><?php echo "$i";?></a>
</li>
<?php $i++;} ?>
<li>»</li>
</ul>
Once any number shown above is clicked required url is displayed inside iframe1
<div align="center">
<iframe name="iframe1" src="http://www.w3schools.com"
frameborder='0' height='1000' width='1000' align="center"></iframe>
</div>
when I click any number it display the url inside the iframe "iframe1" .
Question:
How do i display first and NEXT {NOT LAST} record in
<li>«</li> [First]
<li>»</li> [Next]
I am looking for a very small code to do the same.
The first link is pretty easy:
<a href=<?php echo "$url[0]"; ?> target="iframe1"
title="<?php echo $name[0]"; ?>"><<</a>
For next link It would kind of depend on how your urls are set out. If the $url values are just a name and your url is domain.com/blog?page=page1 where page1 is the value from $url then we get use $_GET['page'] to grab the current page. Then using:
$next = array_search($_GET['page'], $url);
will give us the number in the order of the current page so the next page will simply be $url[$next + 1]
EDIT:
OK if its a url that changes in domain part then the $_GET wont work. You could grab the current url using $_SERVER[REQUEST_URI] and then use the same technique as above to find its position in the array of urls.

retrieve image from mysql database to array php

By compiling this, display three image get my database and show it, when i click each image popup window show last image of my database.I want to know how to display the particular image, when i click first image,then popup window show first image and description, as well as same way second and third image. check to array loop in this code...
enter code here
<?php
$sql=mysql_query("select * from product_reg")or die(mysql_error());
while($row=mysql_fetch_array($sql))
{
$productname=$row['productname'];
$productid=$row['productid'];
$description=$row['description'];
$image=$row['image'];
$firstN = array();
$i=0;
$firstN = '<img src="'.$row ['image'].'">';
echo ' <a href="#" class="big-link" data-reveal-id="myModal" name="image" style="float:left;margin:100px 0 100px 100px;"> ' ; echo $productname;echo $firstN[$i];
$r=$firstN[$i];
echo '</a>';
$i++;
}
?>
<div id="myModal" class="reveal-modal">
<form>
<table>
<tr><td><?php echo $r; ?></td>
<td><h1>Reveal Modal Goodness</h1>
<p>This is a default modal in all its glory, but any of the styles here can easily be changed in the CSS.</p></td>
<a class="close-reveal-modal">×</a>
</div>
</body>
</html>
I guess you have the images stored in the database like BLOB data. If so you need to create a handler to retrieve those images and render them as image/[mime]...
So in short.
In your code you need to create a new file iz get_image.php in it you need to make a request to the server and retrieve the image so you can send it to the client.
In your code you need to change the image path to the handler path with some query parameters.
$firstN = '<img src="get_image.php?imageid='.$row ['productid'].'">';
There are a lot information how to render the image to the client from the internet.
may be you have to declare your $firstN = array(); and then incrementor $i=0; out of while loop and put in array like this:
$firstN[$i] = '<img src="'.$row['image'].'">';
below is the full code:
<?php
$sql=mysql_query("select * from product_reg")or die(mysql_error());
$firstN = array();
$i=0;
while($row=mysql_fetch_array($sql))
{
$productname=$row['productname'];
$productid=$row['productid'];
$description=$row['description'];
$image=$row['image'];
$firstN[$i] = '<img src="'.$row['image'].'">';
echo '<a href="#" class="big-link" data-reveal-id="myModal" name="image" style="float:left;margin:100px 0 100px 100px;"> ';
echo $productname;
echo $firstN[$i];
$r=$firstN[$i];
echo '</a>';
$i++;
}
?>
Updates:
You have a space here:
$firstN[$i] = '<img src="'.$row['image'].'">';
//-----------------------------^----here at this code block;
To get the last image , you need to modify your query to have SORT BY productid DESC
To display the images
echo "<a href='xxx.php?imgid=$image'><img src='yourimagesfolderpath/$image.jpg'> </a>";
to navigate in the images , you have to use JQUERY

How to display default div when the content to be displayed is not present

I'm new to PHP, I tried to get the data from a XML file and display it accordingly.
Now, I was successful in extracting the data and displaying it.
Below is the code -
if($xml_response = #simplexml_load_file('http://www.test.com/Testapp/TestSite?code=Test'))
{
foreach ($xml_response->promotions as $promotions) {
//print_r($promotions);
foreach ($promotions->promotion as $promotion) {
if(isset($promotion)){
$text=$promotion->text;
if (strlen($text) > 80) {
$stringCut = substr($text, 0, 80);
$text = substr($stringCut, 0, strrpos($stringCut, ' ')).' ... ';
}
?>
<div class="ads" style="margin-right:0px;">
<a href="<?=$promotion->link;?>" title="" target="_blank">
<h2><?php echo $promotion->title;?></h2>
<img src="<?php echo $promotion->image;?>" align="left" width="100px" height="80px">
<h2 style="vertical-align:text-top"><?php echo $text ?></h2></a>
</div>
<?php }
else
{?>
<div class="ads" style="margin-right:0px;">
<h2>Advertisement Title 1</h2>
<img src="images/side-banner.jpg" align="left" width="100px" height="80px">
<h2 style="vertical-align:text-top">We improve your way of working and communicating with your groups.</h2>
</div>
<?php } }
Now, I'm able to display the images when content is there but when there is no content default content should be displayed. So I checked with the isset condition, still I'm not able to display the default images.
Below is the XML -
<promotions>
<promotion>
<title>Test</title>
<text>Sign off for limited time offer</text>
<link>NewCentrescdr.jpg</link>
<image>test.jpg</image>
<date>2013-07-16</date>
</promotion>
<promotion>
<title>Test</title>
<text>Test text</text>
<link>http://www.test.com</link>
<image>test.jpg</image>
<date>2013-09-28</date>
</promotion>
</promotions>
Now, based on the number of promotion in XML, I want to display only three in the page. If there are no promotion, then default promotion to be displayed. In the above XML there are only 2 promotions, so the third one should be a default one.How can I do this condition
I'd advise to simplify it down to the bare minimum of code and get it working from there.
Once it does what you want it to do, build up from there and add HTML, CSS etc.
Code:
$xml_response = simplexml_load_string($x); // assume XML in $x
// count <promotion>, but maximum is 3
$count = count($xml_response->promotion);
if ($count > 3) $count = 3;
// loop over <promotion>, echo it out
for ($i = 0; $i < $count; $i++) {
$promotion = $xml_response ->promotion[$i];
echo "$promotion->title<br />$promotion->text<br /><br />";
}
// if there are less than 3 <promotion>, echo out standard.
if ($count < 3) {
echo "Standard<br />Standard Promotion<br /><br />";
}
see it working: http://codepad.viper-7.com/JMjPVo

How get url from database and show it in a iframe page

That's a simple script to adult content site I'd make with pieces of another codes. I am not a expertin PHP! I just can understand the basic.
<html>
<body>
<div align="center">
<div align="center" id="box">
<div align="center" id="carrosel">
<?php
$quantidade = 64;
$pagina = (isset($_GET['pagina'])) ? (int)$_GET['pagina'] : 1;
$inicio = ($quantidade * $pagina) - $quantidade;
$sql = "SELECT * FROM teen ORDER BY RAND() ASC LIMIT $inicio, $quantidade";
$qr = mysql_query($sql) or die(mysql_error());
while($ln = mysql_fetch_assoc($qr)){
?>
So, my problem is here. In that way, when you click the thumb, the browser will open that url that is out my site. the idea is to embed the video on a new iframe page. Someone can help me?
<a href="<?php echo $ln['url_video'];?>"target="_blank">
<img src="<?php echo $ln['thumb_video'];?>" /></a>
<?php
}
?>
<div align="center">
<?php
$sqlTotal = "SELECT thumb FROM teen";
$qrTotal = mysql_query($sqlTotal) or die(mysql_error());
$numTotal = mysql_num_rows($qrTotal);
$totalPagina= ceil($numTotal/$quantidade);
for($i = 1; $i <= $totalPagina; $i++){
if($i == $pagina)
echo $i;
else
echo "$i ";
}
?>
</div><br><br>
</body>
</html>
_blank : Opens the linked document in a new window or tab
_self : Opens the linked document in the same frame as it was clicked (this is default)
_parent : Opens the linked document in the parent frame
_top : Opens the linked document in the full body of the window
Or you can use iframe .or embed some players to play the video in the same area.
Use echo to print your links
while($ln = mysql_fetch_assoc($qr)){
echo '<a href='.$ln['url_video'].'target="_blank">',
'<img src='.$ln['thumb_video'].'/></a>';
}
And I found one more thing replace your echo "$i "; with this:
echo '$i';
And one more thing, use mysqli instead of mysql
You can also use window.open function, it will open the video in a new popup,
<a href="Javascript:;" onclick="window.open('<?php echo $ln['url_video'];?>',
'View Video')" ><img src="<?php echo $ln['thumb_video'];?>" /></a>
More details for window.open at http://www.w3schools.com/jsref/met_win_open.asp

How do I make one section disappear when another is clicked? In PHP

The output of the code below looks like:
Current Discounts for: *category name*
<5 book cover images that link to books>
<5 book cover images that link to books>
MORE CURRENT DISCOUNTS image link
PAST Discounts for: *category name*
<5 book cover images that link to books>
<5 book cover images that link to books>
MORE PAST DISCOUNTS image link
QUESTION: "I have current discount books and past discount books being displayed (incrementally from $Bookarray and $Bookoldarray. When a user clicks on MORE PAST DISCOUNTS, I want CURRENT DISCOUNTS to disappear, and PAST DISCOUNTS be the only section visible on page. How do you do this in PHP? In Visual Basic I would have made an increment variable and incremented it if MORE CURRENT DISCOUNTS was pressed, then say IF incvariable is > 1 run both section, else just run second section."
HERE IS THE CODE
<p>Current Discounts for: <?php echo $whatcategory ?></p>
<?php
$currentp = isset($_GET['currentp']) ? $_GET['currentp'] : 1;
for($i = 0; $i < $currentp; $i++)
next($Bookarray);
if(current($Bookarray) === false){
reset($Bookarray);
$i = 0;
}
$currentIndex = current($Bookarray);
?>
<?=current($Bookarray)?></br><img src="images/bookdiv.jpg" width="547" height="20" /></br>
<img src="images/current.jpg" width="215" height="32" /></br>
<p>Old Discounts for: ><?php echo $whatcategory ?></p>
<?php
$oldp = isset($_GET['oldp']) ? $_GET['oldp'] : 1;
for($i = 0; $i < $oldp; $i++)
next($Bookoldarray);
if(current($Bookoldarray) === false){
reset($Bookoldarray);
$i = 0;
}
$currentIndex = current($Bookoldarray);
?>
<?=current($Bookoldarray)?></br><img src="images/bookdiv.jpg" width="547" height="20" /></br>
<img src="images/old.jpg" width="190" height="32" />
As you are reloading the page and going back to PHP to get the next set of discounts to display, you can just put a php if block around the entire "Current Discounts" section and checking if the 'oldp' variable has been set.
<?php
// Check if user clicked on Past Discounts
if(!isset($_GET['oldp']) {
?>
<p>Current Discounts for: <?php echo $whatcategory ?></p>
<?php
$currentp = isset($_GET['currentp']) ? $_GET['currentp'] : 1;
for($i = 0; $i < $currentp; $i++)
next($Bookarray);
if(current($Bookarray) === false){
reset($Bookarray);
$i = 0;
}
$currentIndex = current($Bookarray);
?>
<?=current($Bookarray)?></br><img src="images/bookdiv.jpg" width="547" height="20" /></br>
<img src="images/current.jpg" width="215" height="32" /></br>
<?php
}
// End if (Hide current discounts if past discounts clicked)
?>
<p>Old Discounts for: ><?php echo $whatcategory ?></p>

Categories