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 1594
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
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...
|
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...
|
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. ...
|
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...
|
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...
|
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...
|
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) ...
|
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...
|
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,...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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,...
| |