473,748 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pagination within image - IF problem

118 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. if (isset($_GET['page']) && is_numeric($_GET['page'])) {
  4.  
  5.     $page = mysql_real_escape_string(htmlspecialchars($_GET['page']));
  6.  
  7. } else {
  8.     $page = 1;
  9. }
  10.  
  11. //other code - not relevant for this purpose
  12.  
  13. if ($page == 1) {
  14.     imagegif($image); // paint the image in browser
  15.     imagegif($image, "user/" . $user . ".gif"); //export as gif file
  16. } elseif(!isset($filter) && $page == 1) {
  17.     imagegif($image); // paint the image in browser
  18.     imagegif($image, "user/" . $user . ".gif"); //export as gif file
  19. } elseif($page != 1) {
  20.     imagegif($image); // paint the image in browser
  21. } elseif(isset($filter)) {
  22.     imagegif($image); // paint the image in browser
  23. } else {
  24.  
  25. }
  26. ?>
  27.  
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
Jun 2 '08 #1
3 1624
pbmods
5,821 Recognized Expert Expert
Heya, Sam.

Let me get out my nitpicking needles here....

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. if (isset($_GET['page']) && is_numeric($_GET['page'])) {
  4.  
  5.     $page = mysql_real_escape_string(htmlspecialchars($_GET['page']));
  6.  
  7. } else {
  8.     $page = 1;
  9. }
  10.  
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.

Expand|Select|Wrap|Line Numbers
  1. if ($page == 1) {
  2.     imagegif($image); // paint the image in browser
  3.     imagegif($image, "user/" . $user . ".gif"); //export as gif file
  4.  
So far so good.
Expand|Select|Wrap|Line Numbers
  1. } elseif(!isset($filter) && $page == 1) {
  2.  
By this point, you already know that $page == 1 because of the previous condition.
Expand|Select|Wrap|Line Numbers
  1. } elseif($page != 1) {
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:
Expand|Select|Wrap|Line Numbers
  1. 3 == true == 1  // But 3 != 1 except in rare instances.
  2. 3 !== true !== 1
  3.  
This should do just fine:
Expand|Select|Wrap|Line Numbers
  1. if( $page === 1 )
  2. {
  3.     // display and save
  4. }
  5. else
  6. {
  7.     // display only
  8. }
  9.  
Jun 3 '08 #2
helraizer1
118 New Member
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.

Expand|Select|Wrap|Line Numbers
  1. if ($page == 1) {
  2.     imagegif($image); // paint the image in browser
  3.     imagegif($image, "user/" . $user . ".gif"); //export as gif file
  4.  
So far so good.
Expand|Select|Wrap|Line Numbers
  1. } elseif(!isset($filter) && $page == 1) {
  2.  
By this point, you already know that $page == 1 because of the previous condition.
Expand|Select|Wrap|Line Numbers
  1. } elseif($page != 1) {
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:
Expand|Select|Wrap|Line Numbers
  1. 3 == true == 1  // But 3 != 1 except in rare instances.
  2. 3 !== true !== 1
  3.  
This should do just fine:
Expand|Select|Wrap|Line Numbers
  1. if( $page === 1 )
  2. {
  3.     // display and save
  4. }
  5. else
  6. {
  7.     // display only
  8. }
  9.  
Yeah, I realised that. Thanks for that, I made some changes; I had to use this in the end:
Expand|Select|Wrap|Line Numbers
  1.  
  2. if (isset($filter)) {
  3.     imagegif($image); // paint the image in browser
  4. } elseif ($page == 1) {
  5.     imagegif($image); // paint the image in browser
  6.     imagegif($image, "user/" . $user . ".gif"); //export as gif file
  7. } else {
  8.     // Here, $page != 1 && !isset($filter)
  9.     imagegif($image); // paint the image in browser
  10. }
  11.  
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
Jun 3 '08 #3
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
Jun 4 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1432
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
2
2327
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...
11
2778
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...
4
2182
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,
1
1839
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.
2
2139
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..
16
2776
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...
1
1147
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.
4
3574
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...
0
8983
marktang
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...
0
9528
Oralloy
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...
0
9236
tracyyun
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...
0
8235
agi2029
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...
1
6792
isladogs
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...
0
4592
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...
1
3298
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
2
2774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.