Hey folks,
I have made an image-based shoutbox and now users can view older and newer message on the shoutbox depending on the $_GET['page'] - pagination - that works. However, since it's image based and can be linked in forums etc. on the Internet I only want it to save the gif image if $page == 1, so the newest shouts are saved onto the image. Yet the users can still view the other messages on site without it changing the saved gif image.
What I've tried so far is this: - <?php
-
-
if (isset($_GET['page']) && is_numeric($_GET['page'])) {
-
-
$page = mysql_real_escape_string(htmlspecialchars($_GET['page']));
-
-
} else {
-
$page = 1;
-
}
-
-
//other code - not relevant for this purpose
-
-
if ($page == 1) {
-
imagegif($image); // paint the image in browser
-
imagegif($image, "user/" . $user . ".gif"); //export as gif file
-
} elseif(!isset($filter) && $page == 1) {
-
imagegif($image); // paint the image in browser
-
imagegif($image, "user/" . $user . ".gif"); //export as gif file
-
} elseif($page != 1) {
-
imagegif($image); // paint the image in browser
-
} elseif(isset($filter)) {
-
imagegif($image); // paint the image in browser
-
} else {
-
-
}
-
?>
-
Which, to me means that when $page == 1 then it loads the image in the browser and also saves user/helraizer.gif and if $page != 1 then it only loads it to the browser and doesn't save the gif. But even if $page == 3 then it saves that as the image and therefore the image hosted on a forum will keep changing as each user views a different thing.
I know that $page works because it changes the contents of the image, but it doesn't work within the if statement.
Can you see what's/if anything's wrong with the code? Would a switch statement be a better solution?
Thanks,
Sam
3 1624 pbmods 5,821
Recognized Expert Expert
Heya, Sam.
Let me get out my nitpicking needles here.... - <?php
-
-
if (isset($_GET['page']) && is_numeric($_GET['page'])) {
-
-
$page = mysql_real_escape_string(htmlspecialchars($_GET['page']));
-
-
} else {
-
$page = 1;
-
}
-
If you've established that $_GET['page'] is numeric, you don't need to do any SQL or HTML escaping. A simple $page = (int) $_GET['page'] will do. -
if ($page == 1) {
-
imagegif($image); // paint the image in browser
-
imagegif($image, "user/" . $user . ".gif"); //export as gif file
-
So far so good. -
} elseif(!isset($filter) && $page == 1) {
-
By this point, you already know that $page == 1 because of the previous condition.
This is effectively an else block.
And the rest of the code will never get executed.
Try using the identity operator, since PHP does some screwy things when you use the equality operator on a value that could evaluate to (bool) true.
In other words: -
3 == true == 1 // But 3 != 1 except in rare instances.
-
3 !== true !== 1
-
This should do just fine: -
if( $page === 1 )
-
{
-
// display and save
-
}
-
else
-
{
-
// display only
-
}
-
Heya, Sam.
Let me get out my nitpicking needles here....
If you've established that $_GET['page'] is numeric, you don't need to do any SQL or HTML escaping. A simple $page = (int) $_GET['page'] will do. -
if ($page == 1) {
-
imagegif($image); // paint the image in browser
-
imagegif($image, "user/" . $user . ".gif"); //export as gif file
-
So far so good. -
} elseif(!isset($filter) && $page == 1) {
-
By this point, you already know that $page == 1 because of the previous condition.
This is effectively an else block.
And the rest of the code will never get executed.
Try using the identity operator, since PHP does some screwy things when you use the equality operator on a value that could evaluate to (bool) true.
In other words: -
3 == true == 1 // But 3 != 1 except in rare instances.
-
3 !== true !== 1
-
This should do just fine: -
if( $page === 1 )
-
{
-
// display and save
-
}
-
else
-
{
-
// display only
-
}
-
Yeah, I realised that. Thanks for that, I made some changes; I had to use this in the end: -
-
if (isset($filter)) {
-
imagegif($image); // paint the image in browser
-
} elseif ($page == 1) {
-
imagegif($image); // paint the image in browser
-
imagegif($image, "user/" . $user . ".gif"); //export as gif file
-
} else {
-
// Here, $page != 1 && !isset($filter)
-
imagegif($image); // paint the image in browser
-
}
-
I had to use the $filter one first because the $page variable is still in the url even when $filter is set, so if $page was it the first IF, it would still save even if $filter was set. The way I have it now it works poifectly.
Thanks for your help once again. :)
Sam
pbmods 5,821
Recognized Expert Expert
Glad to hear you got it working! Good luck with you project, and you need anything else... well, you've heard this speech before :P
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Don Quijote de Nicaragua |
last post by:
Hello chic@s, I have problem with pagination and procedure stored, can to
show information within DataGrid, but when I do click in nobody of the
number which they down appear for the pagination, do not change the
registries.... always shows the first page, somebody has some idea of so
that it can be this... greetings and thanks.
Don Quijote de Nicaragua.
Elder Soto.
Nota: Aqui esta el código que uso
|
by: Chris H |
last post by:
I am having a problem with pagination, basically the problem is happening in
the "PREV / NUMBERS / NEXT" links, it appears as if the reason is becasue
the increment and decrement operators aren't functioning or the $page
variable isnt working in that part of the code... Below is the link to the
working but broken page.. as well as the main part of my code... Hopefully
someone can explain why the operators arent working or maybe see what i...
|
by: ste |
last post by:
Hi there,
Further to my recent posts where I've received excellent help from Rik and
Jerry, I've ended up with an image gallery on my website that displays
images in a table, 3 images per row. This works great and opens all images
in the database when I open the url mywebsite/gallery.php, or I can choose
certain images (by category) by going to url's like
mywebsite/gallery.php?category=landscape
Although the above worked perfectly...
|
by: comp.lang.php |
last post by:
'll try to explain this as clearly as possible, sorry if it's unclear.
You have in your directory /foo 42 images
You have in your database metadata for 30 out of those 42 images
You have to display all 42 images in the /foo directory whether they
have database metadata or not.
If any of the 42 images have metadata, you must display the metadata,
|
by: OceanBreeze |
last post by:
I am new to .Net. I am using ASP 2.0 and C#.
I want to pupolate a data grid programatically using the values obtained from a list conating domain objects.
E.g., DAL.GetEmployee() returns a List of all Employee object. Each Employee object has two attributes (ID and Name).
I drop a data grid control on ASP.Net Web form.
Data grid will have 2 columns - one to display ID, another to display Name of employee.
| |
by: mac |
last post by:
Hi,
I'm looking for a script that will allow me to upload images to a
folder and shows pagination...
pls can any body help me?
i hav done with the uploading, but not able to do with the
pagination...here is the upload code..
|
by: gnawz |
last post by:
I have a pagination function I am using in a file called functions.php as below<? //Pagination functions function getPagingQuery($sql, $itemPerPage = 10) { if (isset($_GET) && (int)$_GET > 0) { $page = (int)$_GET; } else { $page = 1; } // start fetching from this row number $offset = ($page - 1) * $itemPerPage; return $sql . " LIMIT $offset, $itemPerPage"; } /* Get the links to navigate between...
|
by: vinpkl |
last post by:
hi all
i m using pagination to show my products results according to particular category.
it shows
PREV 1,2, NEXT
but when i click these links then these links dont show next and prev results of particular category i m on.
|
by: ArizonaJohn |
last post by:
Hello,
The code below works great. The user enters a name into an HTML form, the code looks up a table with that name, and then that table is displayed.
I am trying to use pagination with it, and the pagination almost works. The first page of the pagination works fine, but when I click on one of the links for one of the next pages, the page is blank.
I have seen people mention this problem, and they have been told that a variable is...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |