How to implement this image preloader into my php file? - php

I want to have my images which are processed via ajax to be preloaded visually rather then the usual loading of images where you see them build up from top to bottom. Please take a look here. What you see there is what I want to have in my php file visually.
The part where the pictures are loaded from the database are the following:
$sql = "SELECT * FROM `fabric`".$filter;
$result=mysql_query("$sql");
//echo $sql;
$data = "";
$ii = 0;
$m = 0;
while($myrow = mysql_fetch_array($result)){
$ii++;
$m++;
if ($m == 1) $data = $data."<div class=\"page current\">";
elseif ($ii == 1) $data = $data."<div class=\"page\">";
$data = $data."<img src=\"".$image_directory.$myrow['thumbnail']."\" width=\"100 px\" height=\"100 px\"><div class=\"fb_name\">".$myrow['name']."</div>\n";
if ($ii == 10) {
$data = $data."</div>";
$ii = 0;
}
}
if ($ii != 10) {
$data = $data."</div>";
}
if (empty($data)) echo "No result";
else echo $data;
?>
I really don't know how to change the php in order to have the effect shown in the demo.
Thank you for all constructive advices and forgive my noobiness :)

You will need javascript for this, you canĀ“t do it in php alone. The basic idea is to hide your images using for example a visibility: hidden and have them fade in when they are completely loaded. And at load-time you position a loading image on top that you remove when you start fading in the image.
As the example you've given, is a plugin, perhaps you can even use that one instead of writing it yourself.

Related

Header may not contain more than a single header, new line detected error [duplicate]

This question already has answers here:
getting warning "Header may not contain more than a single header, new line detected"
(9 answers)
Closed 9 months ago.
I managed to get every other error ironed out, but I am stuck with this error! For the life of me, I cannot seem to diagnose where I went wrong. Any help from you brilliant people out there would be amazing!
I made a form editing php where it is supposed to edit a submission made into the system. This is then processed by my processing php but for some reason I am getting a "header may not contain more than a single header" error in my form submission. I changed the header code multiple times but I do not know why I am still getting it: https://imgur.com/reX4Yyb
Edit:
Also wanted to add that this code was working fine for about a month. The only thing I changed was updating the hosting service platform from PHP 7.3 -> PHP 7.4. I tried reverting and it exactly the same error.
if($_POST['form_submitted'] == 'editgroupreferral'){
include("../../inc/inc.con.php");
/* assign values to checkboxes */
if(isset($_POST['OtherServices'])){
$otherservices = 1;
} else {
$otherservices = 0;
}
if(isset($_POST['Medication'])){
$medication = 1;
} else {
$medication = 0;
}
if(isset($_POST['HaveAllergies'])){
$allergies = 1;
} else {
$allergies = 0;
}
if(isset($_POST['Device'])){
$device = 1;
} else {
$device = 0;
}
if(isset($_POST['Share'])){
$share = 1;
} else {
$share = 0;
}
if(isset($_POST['TakeTurns'])){
$taketurns = 1;
} else {
$taketurns = 0;
}
if(isset($_POST['Wait'])){
$wait = 1;
} else {
$wait = 0;
}
if(isset($_POST['MultInstructions'])){
$multinstr = 1;
} else {
$multinstr = 0;
}
if(isset($_POST['SitChair'])){
$sitchair = 1;
} else {
$sitchair = 0;
}
if(isset($_POST['Routine'])){
$routine = 1;
} else {
$routine = 0;
}
/* insert vars from form into ReferralSC table */
$sql = "UPDATE ReferralGR SET
ReferrerName = :refname,
ReferrerRelationship = :refrelationship,
ReferrerPhone = :refphone,
ReferrerEmail = :refemail,
ReferMethod = :refmethod,
RefSupport = :refsupp,
OtherServices = :otherservices,
School = :school,
Diagnosis = :diagnosis,
Medication = :medication,
MedicationList = :medicationlist,
HaveAllergies = :allergies,
AllergiesList = :allergieslist,
Device = :device,
Share = :share,
TakeTurns = :taketurns,
Wait = :wait,
MultInstructions = :multinstr,
SitChair = :sitchair,
Routine = :routine,
ExplainFurther = :explain,
HeardAbout = :heardabout,
RefNotes = :notes
WHERE ref_id = :grid";
$s = $pdo->prepare($sql);
$s->bindvalue(':refname', $_POST['ReferrerName']);
$s->bindvalue(':refrelationship', $_POST['ReferrerRelationship']);
$s->bindvalue(':refphone', $_POST['ReferrerPhone']);
$s->bindvalue(':refemail', $_POST['ReferrerEmail']);
$s->bindvalue(':refmethod', $_POST['ReferMethod']);
$s->bindvalue(':refsupp', $_POST['RefSupport']);
$s->bindvalue(':otherservices', $otherservices);
$s->bindvalue(':school', $_POST['School']);
$s->bindvalue(':diagnosis', $_POST['Diagnosis']);
$s->bindvalue(':medication', $medication);
$s->bindvalue(':medicationlist', $_POST['MedicationList']);
$s->bindvalue(':allergies', $allergies);
$s->bindvalue(':allergieslist', $_POST['AllergiesList']);
$s->bindvalue(':device', $device);
$s->bindvalue(':share', $share);
$s->bindvalue(':taketurns', $taketurns);
$s->bindvalue(':wait', $wait);
$s->bindvalue(':multinstr', $multinstr);
$s->bindvalue(':sitchair', $sitchair);
$s->bindvalue(':routine', $routine);
$s->bindvalue(':explain', $_POST['ExplainFurther']);
$s->bindvalue(':heardabout', $_POST['HeardAbout']);
$s->bindvalue(':notes', $_POST['RefNotes']);
$s->bindvalue(':grid', $_POST['ref_id']);
$s->execute();
header('location:../refer_gr/referral-view.php?rid=' . $_POST['ref_id'] );
}
This warning occurs to indicate that you might have a new line [/n] in the string content of your variables. The solution is to strip out the passable new line contents of the variable Like this
$val=$_POST['ref_id'];
$url="../refer_gr/referral-view.php?rid='$val'";
$url=str_replace(PHP_EOL, '', $url);
header("Location: $url");
Okay, this one was a toughie but I figured it out. Here is my method:
So the clue lies in the error itself. It was pointing me from my processing php. But it was only because the data being asked in the header (requires a reference ID) is wrong.
The problem was in the reference ID (after much debugging). It was taking the wrong value from the wrong variable. This was in the php form page not the php processing page.
So here is the solution:
$s->bindvalue(':refid', $refid);
Rest of the code:
<input type="hidden" name="ref_id" value="<?php echo $rid; ?>" >
The variable $rid is not the same as the variable $refid.
Here is the fix:
<input type="hidden" name="ref_id" value="<?php echo $refid; ?>" >
This means that with this type of error, it might be worth looking at which part of the code it is trying to get the value from and start debugging from there.
Thanks for the help everyone!

How to get a single variable attached to the URI?

I don't seem to able to acquire a GET variable that is attached to the URI.
The codes are => at the controller
...
parse_str($_SERVER['QUERY_STRING'], $_GET);
....
$data['ti'] = $this->input->get('hamleno');
this->load->view('anasayfa', $data);
The codes are => at the view the link is
...
<div class="row"><?php for ($b=0; $b<=(count($hml)-1); $b++) { ?><?php echo $hml[$b]." "; ?> <?php } ?></div>
The link is working. I have added the
$config['uri_protocol'] = "PATH_INFO";
to the config.php file.
However I am not able to get the $ti variable
if ($ti){
$t=$ti;
}else{
$t = $this->input->post('t');
if (!$t) $t = 0;
if( $this->input->post('ileri') ) {
$t=$t+1;
if($t>($uz-1)){
$t=$uz-1;
}
} // Forward button was pressed;
if( $this->input->post('geri') ) {
$t=$t-1;
if($t<0){
$t=0;
}
} // Back button was pressed;
}
I'm not familiar with codeigniter, but I've always passed GET variables in this manner:
URL = www.site.com/folder/webpage.php?myvariable=myvalue
I would retrieve that value this way:
$x = $_GET['myvariable'];
or with codeigniter: (I think)
$x = $this->input->get('myvariable');
Tailored to your example, I would personally de-obfuscate your loop code just a little and instead of switching from PHP to HTML and back in one line, I would simply echo both from PHP like this:
(I also don't exactly understand the url you're using, so here is my approximate)
<?php
for ($b=0; $b<=(count($hml)-1); $b++)
{
echo '',$hml[$b],' ';
}
?>
I found out how Codeigniter solves the problem =>
$get = $this->uri->uri_to_assoc();
if(isset($get['hamleno'])){
$data['ti'] = $get['hamleno'];
}
This sends the $b assigned to $hamleno together with all the other stuff in $data.
Thank you all for your kind comments

How to make a php variable $_POST upon clicking it?

I'm trying to make $suggestion[$ss_count] become a clickable link that does a $_POST once it is clicked. I'm trying to achieve a query expansion sort of an effect. The word itself of course needs to be the information posted and it needs to be recognized as
if ($_POST['query'])
The code I use for this is:
<?php
if ($_POST['query'])
{
$query = urlencode($_POST['query']);
$s_count = 0;
$ss_count = 0;
$query = 'http://www.dictionaryapi.com/api/v1/references/collegiate/xml/'.$query.'? key=135a6187-af83-4e85-85c1-1a28db11d5da';
$xml = new SimpleXMLIterator(file_get_contents($query));
foreach ($xml -> suggestion as $suggestion[$s_count])
{
$s_count++;
}
if ($s_count > 1)
{
echo ('<h4>Did you mean?</h4>');
while ($ss_count <=$s_count)
{
echo ($suggestion[$ss_count].'<br>');
$ss_count++;
}
}
}
?>

Is there a way to tell Drupal not to cache a specific page?

I have a custom php page that processes a feed of images and makes albums out of it. However whenever i add pictures to my feed, the Drupal page doesn't change until I clear the caches.
Is there a way to tell Drupal not to cache that specific page?
Thanks,
Blake
Edit: Drupal v6.15
Not exactly sure what you mean oswald, team2648.com/media is hte page.
I used the php interpreter module. Here is the php code:
<?php
//////// CODE by Pikori Web Designs - pikori.org ///////////
//////// Please do not remove this title, ///////////
//////// feel free to modify or copy this software ///////////
$feedURL = 'http://picasaweb.google.com/data/feed/base/user/Techplex.Engineer?alt=rss&kind=album&hl=en_US';
$photoNodeNum = 4;
$galleryTitle = 'Breakaway Pictures';
$year = '2011';
?>
<?php
/////////////// DO NOT EDIT ANYTHING BELOW THIS LINE //////////////////
$album = $_GET['album'];
if($album != ""){
//GENERATE PICTURES
$feedURL= "http://".$album."&kind=photo&hl=en_US";
$feedURL = str_replace("entry","feed",$feedURL);
$sxml = simplexml_load_file($feedURL);
$column = 0;
$pix_count = count($sxml->channel->item);
//print '<h2>'.$sxml->channel->title.'</h2>';
print '<table cellspacing="0" cellpadding="0" style="font-size:10pt" width="100%"><tr>';
for($i = 0; $i < $pix_count; $i++) {
print '<td align="center">';
$entry = $sxml->channel->item[$i];
$picture_url = $entry->enclosure['url'];
$time = $entry->pubDate;
$time_ln = strlen($time)-14;
$time = substr($time,0,$time_ln);
$description = $entry->description;
$tn_beg = strpos($description, "src=");
$tn_end = strpos($description, "alt=");
$tn_length = $tn_end - $tn_beg;
$tn = substr($description, $tn_beg, $tn_length);
$tn_small = str_replace("s288","s128",$tn);
$picture_url = $tn;
$picture_beg = strpos($picture_url,"http:");
$picture_len = strlen($picture_url)-7;
$picture_url = substr($tn, $picture_beg, $picture_len);
$picture_url = str_replace("s288","s640",$picture_url);
print '<a rel="lightbox[group]" href="'.$picture_url.'">';
print '<img '.$tn_small.' style="border:1px solid #02293a"><br>';
print '</a></td> ';
if($column == 4){ print '</tr><tr>'; $column = 0;}
else $column++;
}
print '</table>';
print '<br><center>Return to album</center>';
} else {
//GENERATE ALBUMS
$sxml = simplexml_load_file($feedURL);
$column = 0;
$album_count = count($sxml->channel->item);
//print '<h2>'.$galleryTitle.'</h2>';
print '<table cellspacing="0" cellpadding="0" style="font-size:10pt" width="100%"><tr>';
for($i = 0; $i < $album_count; $i++) {
$entry = $sxml->channel->item[$i];
$time = $entry->pubDate;
$time_ln = strlen($time)-14;
$time = substr($time,0,$time_ln);
$description = $entry->description;
$tn_beg = strpos($description, "src=");
$tn_end = strpos($description, "alt=");
$tn_length = $tn_end - $tn_beg;
$tn = substr($description, $tn_beg, $tn_length);
$albumrss = $entry->guid;
$albumrsscount = strlen($albumrss) - 7;
$albumrss = substr($albumrss, 7, $albumrsscount);
$search = strstr($time, $year);
if($search != FALSE || $year == ''){
print '<td valign="top">';
print '<a href="/node/'.$photoNodeNum.'?album='.$albumrss.'">';
print '<center><img '.$tn.' style="border:3px double #cccccc"><br>';
print $entry->title.'<br>'.$time.'</center>';
print '</a><br></td> ';
if($column == 3){
print '</tr><tr>'; $column = 0;
} else {
$column++;
}
}
}
print '</table>';
}
?>
Thanks for your answer.
The site you linked gave me some new verbiage to search with, and thus I found this:
http://www.drupalcoder.com/story/365-disable-drupals-page-cache-for-some-pages
which then led me to this:
http://drupal.org/project/cacheexclude
which did exactly what I wanted.
Hope this helps.
That is for Drupal 6.
This doesn't answer your specific question about caching, but -- consider using Drupal-native solutions like the Picasa module for things like this.
When you use non-Drupal PHP applications in a Drupal environment like you have here, you get weird interactions with other Drupal components. Drupal modules are build with Drupal in mind, so things like sane caching usually come built in.
Write this code line at the top of the custom page you dont want to be cached:
$GLOBALS['conf']['cache'] = FALSE;
For Drupal 6,
If you just want to exclude a specific page from being cached then you can use Cache exclude module, where you just have to provide a url.
for drupal 7 also it is available but its in the development version.
Yes you can do it programmatically and the below code is valid for Drupal 6 and 7 both.
Reference : http://techrappers.com/post/27/how-prevent-javascript-and-css-render-some-drupal-pages
/**
* Implements hook_init().
*/
function MODULE_NAME_init() {
global $conf;
// current_path() is the path on which you want to turn of JS or CSS cache
if (current_path() == 'batch' || current_path() == 'library-admin') {
// If you want to force CSS or JS cache to turned off
$conf['preprocess_js'] = FALSE;
$conf['preprocess_css'] = FALSE;
// If you want normal caching to turned off
drupal_page_is_cacheable(FALSE);
}
}
Please Note that drupal_page_is_cacheable(FALSE); can only turn off normal caching, it will not force JS caching to be turned off automatically unless you use $conf['preprocess_js'] = FALSE.

Is there a piece of public code available to create a page index using PHP?

I have a MySQL table holding lots of records that i want to give the user access to. I don't want to dump the entire table to the page so i need to break it up into 25 records at a time, so i need a page index. You have probably seen these on other pages, they kind of look like this at the base of the page:
< 1 2 3 4 5 6 7 8 9 >
For example, when the user clicks on the '4' link, the page refreshes and the offset is moved on (4th page x 25 records). Here is what i already have:
function CreatePageIndex($ItemsPerPage, $TotalNumberOfItems, $CurrentOffset, $URL, $URLArguments = array())
{
foreach($URLArguments as $Key => $Value)
{
if($FirstIndexDone == false)
{
$URL .= sprintf("?%s=%s", $Key, $Value);
$FirstIndexDone = true;
}
else
{
$URL .= sprintf("&%s=%s", $Key, $Value);
}
}
Print("<div id=\"ResultsNavigation\">");
Print("Page: ");
Print("<span class=\"Links\">");
$NumberOfPages = ceil($TotalNumberOfItems / $ItemsPerPage);
for($x = 0; $x < $NumberOfPages; $x++)
{
if($x == $CurrentOffset / $ItemsPerPage)
{
Print("<span class=\"Selected\">".($x + 1)." </span>");
}
else
{
if(empty($URLArguments))
{
Print("".($x + 1)." ");
}
else
{
Print("".($x + 1)." ");
}
}
}
Print("</span>");
Print(" (".$TotalNumberOfItems." results)");
Print("</div>");
}
Obviously this piece of code does not create a dynamic index, it just dumps the whole index at the bottom of the page for every page available. What i need is a dynamic solution that only shows the previous 5 pages and next 5 pages (if they exist) along with a >> or something to move ahead 5 or so pages.
Anybody seen an elegant and reusable way of implementing this as i feel i'm re-inventing the wheel? Any help is appreciated.
Zend Framework is becoming a useful collection and includes a Zend_Paginator class, which might be worth a look. Bit of a learning curve and might only be worth it if you want to invest the time in using other classes from the framework.
It's not too hard to roll your own though. Get a total count of records with a COUNT(*) query, then obtain a page of results with a LIMIT clause.
For example, if you want 20 items per page, page 1 would have LIMIT 0,20 while page 2 would be LIMIT 20,20, for example
$count=getTotalItemCount();
$pagesize=20;
$totalpages=ceil($count/$pagesize);
$currentpage=isset($_GET['pg'])?intval($_GET['pg']):1;
$currentpage=min(max($currentpage, 1),$totalpages);
$offset=($currentpage-1)*$pagesize;
$limit="LIMIT $offset,$pagesize";
It's called Pagination:
a few examples:
A nice one without SQL
A long tutorial
Another tutorial
And Another
And of course.. google
How about this jQuery-plugin?
So all the work is done on the clientside.
http://plugins.jquery.com/project/pagination
demo: http://d-scribe.de/webtools/jquery-pagination/demo/demo_options.htm
Heres an old class I dug out that I used to use in PHP. Now I handle most of it in Javascript. The object takes an array (that you are using to split the stack into pages) and return the current view. This can become tedious on giant tables so keep that in mind. I generally use it for paging through small data sets of under 1000 items. It can also optionally generate your jump menu for you.
class pagination {
function pageTotal($resultCount, $splitCount) {
if (is_numeric($resultCount) && is_numeric($splitCount)) {
if ($resultCount > $splitCount) {
$pageAverage = (integer)$resultCount / $splitCount;
$pageTotal = ceil($pageAverage);
return $pageTotal;
} else {
return 1;
}
} else {
return false;
}
}
function pageTotalFromStack($resultArray, $splitCount) {
if (is_numeric($splitCount) && is_array($resultStack)) {
if (count($resultStack) > $splitCount) {
$resultCount = count($resultStack);
$pageAverage = (integer)$resultCount / $splitCount;
$pageTotal = ceil($pageAverage);
return $pageTotal;
} else {
return 1;
}
} else {
return false;
}
}
function makePaginationURL($preURL, $pageTotal, $selected=0, $linkAttr=0, $selectedAttr=0) {
if (!empty($preURL) && $pageTotal >= 1) {
$pageSeed = 1;
$passFlag = 0;
$regLink = '<a href="{url}&p={page}"';
if (is_array($linkAttr)) $regLink .= $this->setAttributes($linkAttr); //set attributes
$regLink .= '>{page}</a>';
$selLink = '<a href="{url}&p={page}"';
if (is_array($selectedAttr)) $selLink .= $this->setAttributes($selectedAttr); //set attributes
$selLink .= '>{page}</a>';
while($pageSeed <= $pageTotal) {
if ($pageSeed == $selected) {
$newPageLink = str_replace('{url}', $preURL, $selLink);
$newPageLink = str_replace('{page}', $pageSeed, $newPageLink);
} else {
$newPageLink = str_replace('{url}', $preURL, $regLink);
$newPageLink = str_replace('{page}', $pageSeed, $newPageLink);
}
if ($passFlag == 0) {
$passFlag = 1;
$linkStack = $newPageLink;
} else {
$linkStack .= ', ' . $newPageLink;
}
$pageSeed++;
}
return $linkStack;
} else {
return false;
}
}
function splitPageArrayStack($stackArray, $chunkSize) {
if (is_array($stackArray) && is_numeric($chunkSize)) {
return $multiArray = array_chunk($stackArray, $chunkSize);
} else {
return false;
}
}
}

Categories