Author Topic: (isset(..)) gives wrong results!!!!!  (Read 12499 times)

0 Members and 1 Guest are viewing this topic.

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
(isset(..)) gives wrong results!!!!!
« on: November 25, 2007, 01:47:35 AM »
Hi,
I have an little issue:

I have a 1 foto, fotoYES.jpg in the folder foto on my gallery.

On the php page I use this code:

Code: [Select]
$fotoYES = $site_sess->url("http://www.website.com/foto/fotoYES.jpg");
$fotoNO = $site_sess->url("http://www.website.com/foto/fotoNO.jpg");

$painFOTO = $site_sess->url("http://www.website.com/foto/spainFOTO.jpg"); //This foto DOES NOT EXIST

$foto = (isset($painFOTO)) ? $fotoYES : $fotoNO;

That means if spainFOTO.jpg exist, the result will be $fotoYES, OTHERWISE $fotoNO.

I don't understand why the result always $fotoYES even spainFOTO.jpg not in the folder foto.

I think I should use another code instead of (isset(....)) ? ..:...;

NOTE: http://www.website.com/foto/spainFOTO.jpg give an 404 error! (spainFOTO.jpg does not exist in the folder foto)

Any help will be great,
Cruxy


Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: (isset(..)) gives wrong results!!!!!
« Reply #1 on: November 25, 2007, 02:09:15 AM »
3 line ... how I help for this ?
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
Re: (isset(..)) gives wrong results!!!!!
« Reply #2 on: November 25, 2007, 02:12:35 AM »
I think that the request is very clear. So I do not have to post the hole code.

Please if you read goed the post you will understand what I mean. :wink:

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: (isset(..)) gives wrong results!!!!!
« Reply #3 on: November 25, 2007, 02:57:33 AM »
Quote
I think that the request is very clear. So I do not have to post the hole code.

If I ask - is very clear for request ? :?
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
Re: (isset(..)) gives wrong results!!!!!
« Reply #4 on: November 25, 2007, 03:25:37 PM »
oK no problem. I will explain and feel free to ask me if you need more information or explaination.

I can not post here the hole code of details (it is very big). That why I made for you onother example.

In a custom page I want some information from the table EVENTS.
On events.php you find als results the information of the events + the foto of this events.
Because not all the events has a foto I used the FUNCTION ISSET to show a thumb (thumb.jpg) if the events has a foto or show the thumb (thumb_no) if the events has no foto.

I use this code on the events.php:

Code: [Select]
$events_thumb = "<a href=\"".$site_sess->url(ROOT_PATH."events".$events_row['events_id']).".php \" target=\"_blank\"><img src=\"".$site_sess->url(ROOT_PATH."images/events/thumb".$events_row['events_id']).".jpg\" width=\"120\" height=\"80\" border=\"0\" alt=\"".$events_row['events_name']."\" />";
   
       $events_thumb_no = "<a href=\"".$site_sess->url(ROOT_PATH."events".$events_row['events_id']).".php \" target=\"_blank\"><img src=\"".$site_sess->url(ROOT_PATH."images/events/geen_thumb.jpg")."\") width=\"120\" height=\"80\" border=\"0\" alt=\"".$events_row['events_name']."\" />";

       $foto_url = $site_sess->url(ROOT_PATH."images/events/thumb".$events_row['events_id']).jpg;
       
       $thumb = (isset($foto_url)) ? $events_thumb : $events_thumb_no;


NOTE: $foto_url IS NOT STORED in database (table events), otherwise it will be easy to solve this problem.

Here is the code of the events.php:
Code: [Select]
<?php
$main_template 
substr(($_SERVER['PHP_SELF']),0,7);


define('GET_CACHES'1);
define('ROOT_PATH''./');
include(
ROOT_PATH.'global.php');
require(
ROOT_PATH.'includes/sessions.php');
$allowed_users_access_page = array(substr(($_SERVER['PHP_SELF']),8,-4)); // Change for all user ID need.
if (function_exists('check_for_valid_user_access_page') && !check_for_valid_user_access_page($allowed_users_access_page) && $user_info['user_level'] < ADMIN) {
   
redirect($url);
}
$user_access get_permission();
include(
ROOT_PATH.'includes/page_header.php');
include(
ROOT_PATH.'includes/stats.php');




//-----------------------------------------EVENTS--------------------------------------------------------------------
$additional_sql "";
  
$additional_sql_array = array();
  if (isset(
$additional_user_fields) && is_array($additional_user_fields) && !empty($additional_user_fields)) {
      foreach (
$additional_user_fields as $key => $val) {
          
$additional_sql ", u." $key;
          
$additional_sql_array[] = $key;
      }
  }
  
  if (isset(
$additional_user_fields) && is_array($additional_user_fields) && !empty($additional_user_fields)) {
   foreach (
$additional_user_fields as $key => $val) {
      
$additional_sql .= ", u.".$key;
   }
}
  
  
   
$sql "SELECT i.image_id, i.image_thumb_file, i.image_media_file, e.events_id, e.events_thumb, e.events_name, e.events_description, e.events_datum1, e.events_adres, e.events_prijzen, e.events_betaling, e.events_contact, e.events_image_id, e.events_user_id, i.cat_id, i.user_id, i.image_name, i.image_date, i.image_active, i.image_hits".$additional_sql.", c.cat_name".get_user_table_field(", u.""user_name")."
        FROM ("
.EVENTS_TABLE." e, ".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c)
        LEFT JOIN "
.USERS_TABLE." u ON (".get_user_table_field("u.""user_id")." = i.user_id) 
        WHERE i.image_id = e.events_id
GROUP BY e.events_id
ORDER BY i.image_datum ASC"
;
        
$result $site_db->query($sql); 
$num_rows $site_db->get_numrows($result);



if (!
$num_rows)  { 
   
$events "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\"><tr><td>".$lang['no_foto']."</td></tr>"

else  {
    
$events "<table class=\"head2\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">
    "
;
   
   while (
$events_row $site_db->fetch_array($result)){ 
   





//-----Here is my request
                     
       
$events_thumb "<a href=\"".$site_sess->url(ROOT_PATH."events".$events_row['events_id']).".php \" target=\"_blank\"><img src=\"".$site_sess->url(ROOT_PATH."images/events/thumb".$events_row['events_id']).".jpg\" width=\"120\" height=\"80\" border=\"0\" alt=\"".$events_row['events_name']."\" />";
   
       
$events_thumb_no "<a href=\"".$site_sess->url(ROOT_PATH."events".$events_row['events_id']).".php \" target=\"_blank\"><img src=\"".$site_sess->url(ROOT_PATH."images/events/geen_thumb.jpg")."\") width=\"120\" height=\"80\" border=\"0\" alt=\"".$events_row['events_name']."\" />";

       
$foto_url $site_sess->url(ROOT_PATH."images/events/thumb".$events_row['events_id']).jpg;
       
       
$thumb = (isset($foto_url)) ? $events_thumb $events_thumb_no;
       
       
       



       

  
/*
  if (empty($thumb_url)) {
  
  $thumb = $events_thumb_no;
  }
  else {
  $thumb = $events_thumb;
  }
  */ 
     
 
 
   
   
$events .= "<tr>
   <td valign=\"top\">"
.$thumb."</td></tr>
   "
;
                   
}      

  
$events .= "</table>\n";
  
$site_template->register_vars("events"$events); 
unset(
$events);
//---------------------------------------------------------------------------- 
  
 
  
//-----------------------------------------------------
//--- Clickstream -------------------------------------
//-----------------------------------------------------
$clickstream "<span class=\"clickstream\"><a href=\"".$site_sess->url(ROOT_PATH."index.php")."\" class=\"clickstream\">".$lang['home']."</a>".$config['category_separator']."Events pagina"."</span>";



//-----------------------------------------------------
//--- Print Out ---------------------------------------
//-----------------------------------------------------
$site_template->register_vars(array(
  
"clickstream" => $clickstream,

));
$site_template->print_template($site_template->parse_template($main_template));

include(
ROOT_PATH.'includes/page_footer.php');
?>

So my question is: Why when I use ISSET I get A NOT EXISTING THUMB with the events who has no foto?
I think I have to use here another fuction!!!!!!!

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: (isset(..)) gives wrong results!!!!!
« Reply #5 on: November 25, 2007, 04:17:59 PM »
I check code for this:

Code: [Select]
$main_template = substr(($_SERVER['PHP_SELF']),0,7);

I say for no one for use this. Hi risk.

Code: [Select]
$allowed_users_access_page = array(substr(($_SERVER['PHP_SELF']),8,-4)); // Change for all user ID need.

for:

Code: [Select]
$allowed_users_access_page = array(substr($self_url, 8,-4)); // Change for all user ID need.

if use my MOD.

and why two time:

Code: [Select]
$additional_sql = "";
  $additional_sql_array = array();
  if (isset($additional_user_fields) && is_array($additional_user_fields) && !empty($additional_user_fields)) {
      foreach ($additional_user_fields as $key => $val) {
          $additional_sql = ", u." . $key;
          $additional_sql_array[] = $key;
      }
  }
 
  if (isset($additional_user_fields) && is_array($additional_user_fields) && !empty($additional_user_fields)) {
   foreach ($additional_user_fields as $key => $val) {
      $additional_sql .= ", u.".$key;
   }
}

for $additional_sql for additional user fields ?

Code: [Select]
$foto_url = $site_sess->url(ROOT_PATH."images/events/thumb".$events_row['events_id']).jpg;

if use file extension at end of line - use like this:

Code: [Select]
$foto_url = (isset($events_row['events_id'])) ? get_file_extension($events_row['events_id']). ".jpg" : "";

If want to use for URL - use like this:

Code: [Select]
$foto_url = (isset($events_row['events_id'])) ? $site_sess->url(ROOT_PATH . "images/events/thumb" . get_basefile(stripslashes(trim($events_row['events_id']))) . ".jpg" : "";

(Note: I no test - is your file so I think is what you look...) 
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
Re: (isset(..)) gives wrong results!!!!!
« Reply #6 on: November 25, 2007, 10:58:38 PM »
Quote
and why two time:


Code:
$additional_sql = "";
  $additional_sql_array = array();
  if (isset($additional_user_fields) && is_array($additional_user_fields) && !empty($additional_user_fields)) {
      foreach ($additional_user_fields as $key => $val) {
          $additional_sql = ", u." . $key;
          $additional_sql_array[] = $key;
      }
  }
 
  if (isset($additional_user_fields) && is_array($additional_user_fields) && !empty($additional_user_fields)) {
   foreach ($additional_user_fields as $key => $val) {
      $additional_sql .= ", u.".$key;
   }
}

for $additional_sql for additional user fields ?

It is not important. I just used the code of onther file to get some infomation from user table.

Quote
If want to use for URL - use like this:


Code:
$foto_url = (isset($events_row['events_id'])) ? $site_sess->url(ROOT_PATH . "images/events/thumb" . get_basefile(stripslashes(trim($events_row['events_id']))) . ".jpg" : "";

Actualy is not what I want. I will change the code to make it easy for you:

Code: [Select]
$foto_url = $site_sess->url(ROOT_PATH."images/events/thumb".$events_row['events_id']).jpg;

$thumb = (isset($foto_url)) ? $lang['foto_yes']: $lang['foto_no'];

Explanation:

I have 2 events: events1 and events2 (1 and 2 are events_id's)

So this line means:
Code: [Select]
$foto_url = $site_sess->url(ROOT_PATH."events/foto".$events_row['events_id']).jpg
$foto_url = http://www.website.com/events/foto1.jpg or /foto2.jpg.

In the folder events I have only foto1.jpg.

So I want that the code look into the folder events and look for foto1.jpg for events1 and foto2.jpg for events2 if exist.
That why I used this code (But I think it is wrong)
Code: [Select]
thumb = (isset($foto_url)) ? $lang['foto_yes']: $lang['foto_no'];
That means:
If foto2.jpg exist for events2 show as results $lang['foto_yes'], otherwise $lang['foto_no'];

Because foto2.jpg does not exist, I expected $lang['foto_no']. My code shows $lang['foto_yes] and this is wrong.

I believe that In this situation I have to use onother code instead the isset code.

Good explanation, he? :wink:

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: (isset(..)) gives wrong results!!!!!
« Reply #7 on: November 26, 2007, 12:45:52 AM »
Quote
So I want that the code look into the folder events and look for foto1.jpg for events1 and foto2.jpg for events2 if exist.
That why I used this code (But I think it is wrong)

Ohh ok - now I get. You need for use loop for load all image file. Is why is no work. If no loop, is no work. ;)
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
Re: (isset(..)) gives wrong results!!!!!
« Reply #8 on: November 26, 2007, 12:19:29 PM »
You are still not understand my request, never mind!!
Thank you anyway for trying helping me!

I hope you or someone else will get the point to solve this little issue! :(
« Last Edit: November 26, 2007, 12:55:32 PM by cruxy »

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: (isset(..)) gives wrong results!!!!!
« Reply #9 on: November 26, 2007, 02:10:20 PM »
Quote
You are still not understand my request, never mind!!

If so - please post full request . You create topic so you need say problem so people get.
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
Re: (isset(..)) gives wrong results!!!!!
« Reply #10 on: November 26, 2007, 02:16:10 PM »
I explain it more than 3 times with three different ways to make it easy for you.
If you do not want to understand it, just forget it. No problem at all. :)

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: (isset(..)) gives wrong results!!!!!
« Reply #11 on: November 26, 2007, 02:17:41 PM »
Quote
If you do not want to understand it, just forget it. No problem at all.

I see no where in topic where I say I no want for understand. Your request is big but code is too small - how I get  :?:
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
Re: (isset(..)) gives wrong results!!!!!
« Reply #12 on: November 26, 2007, 02:20:21 PM »
I will think about onother way to explain it.
I will get back to you.

Thank you in advance  :)