Re: [PHP] What's wrong with this IF statement?

2004-04-22 Thread Richard Davey
Hello Robert,

Thursday, April 22, 2004, 8:02:55 PM, you wrote:

RS   $cat_id = $cats[id_num];

Try this:

$cat_id = $cats['id_num'];

You need to quote array elements otherwise PHP expects a constant.

-- 
Best regards,
 Richard Davey
 http://www.phpcommunity.org/wiki/296.html

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] What's wrong with this IF statement?

2004-04-22 Thread Michael Sims
John W. Holmes wrote:
 You want  instead of ||

 if ($cat_id != 53  $cat_id != 54  $cat_id != 55  $cat_id
 != 117  $cat_id != 118  $cat_id != 74)

For stuff like this I've always found the following slightly easier on the
eyes:

if (!in_array($cat_id, array('53', '54', '55', '117', '118', '74')))

YMMV...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] What's wrong with this IF statement?

2004-04-22 Thread Robert Sossomon
My IF statement should be picking up on the numbers, and if the number
matches not be displaying out the information, however I look at the
outputted page and the information is still there, what have I got wrong
on the code?

CODE SNIPPET
//Show categories first
$get_cats = select id_num, id_name, description, cat_code from
categories order by id_name;
$get_cats_res = mysql_query($get_cats) or die(mysql_error());

if (mysql_num_rows($get_cats_res)  1)
{
 $display_block = PemSorry, no categories to browse./em/P;
}
else
{
 while ($cats = mysql_fetch_array($get_cats_res))
 {
  $cat_id = $cats[id_num];
  if ($cat_id != 53 || $cat_id != 54 || $cat_id != 55 || $cat_id
!= 117 || $cat_id != 118 || $cat_id != 74)
  {
  $cat_title = strtoupper(stripslashes($cats[id_name]));
  $cat_desc = stripslashes($cats[description]);
  $display_block .= stronga
href=$_SERVER[PHP_SELF]?cat_id=$cat_id$cat_title
$cat_desc/a/strongbr\n;
  while ($items = mysql_fetch_array($get_items_res))
   {
$item_id = $items[id];
$item_num = $items[item_num];
$item_desc = stripslashes($items[description]);
if ($item_num != ABC-R37 || $item_num !=  ABC-R42 || $item_num
!= HB-99100 || $item_num != RO-PUMPS || $item_num != ML-HDGALJUG
|| $item_num != PFS-CAC21 || $item_num != PFS-CO2)
{
$item_num = ltrim($item_num);
$item_num = rtrim($item_num);
$display_block .= nbsp;nbsp;nbsp;nbsp;emstronga
href=\catalog/$item_id.html\$item_num/a/strong -
$item_desc/embr\n;
} 
   }
END SNIPPETS

My assumption is that BOTH IF statements are not working correctly since
the logic is that if they are built the same they would react the same.
HELP!

TIA!
Robert

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] What's wrong with this IF statement?

2004-04-22 Thread Daniel Clark
What about removing the quotes around the numbers.

 if ($cat_id != 53 || $cat_id != 54 || $cat_id != 55 etc...


 My IF statement should be picking up on the numbers, and if the number
 matches not be displaying out the information, however I look at the
 outputted page and the information is still there, what have I got wrong
 on the code?

 CODE SNIPPET
 //Show categories first
 $get_cats = select id_num, id_name, description, cat_code from
 categories order by id_name;
 $get_cats_res = mysql_query($get_cats) or die(mysql_error());

 if (mysql_num_rows($get_cats_res)  1)
 {
  $display_block = PemSorry, no categories to browse./em/P;
 }
 else
 {
  while ($cats = mysql_fetch_array($get_cats_res))
  {
   $cat_id = $cats[id_num];
   if ($cat_id != 53 || $cat_id != 54 || $cat_id != 55 || $cat_id
 != 117 || $cat_id != 118 || $cat_id != 74)
   {
   $cat_title = strtoupper(stripslashes($cats[id_name]));
   $cat_desc = stripslashes($cats[description]);
   $display_block .= stronga
 href=$_SERVER[PHP_SELF]?cat_id=$cat_id$cat_title
 $cat_desc/a/strongbr\n;
   while ($items = mysql_fetch_array($get_items_res))
{
 $item_id = $items[id];
 $item_num = $items[item_num];
 $item_desc = stripslashes($items[description]);
 if ($item_num != ABC-R37 || $item_num !=  ABC-R42 || $item_num
 != HB-99100 || $item_num != RO-PUMPS || $item_num != ML-HDGALJUG
 || $item_num != PFS-CAC21 || $item_num != PFS-CO2)
 {
 $item_num = ltrim($item_num);
 $item_num = rtrim($item_num);
 $display_block .= emstronga
 href=\catalog/$item_id.html\$item_num/a/strong -
 $item_desc/embr\n;
 }
}
 END SNIPPETS

 My assumption is that BOTH IF statements are not working correctly since
 the logic is that if they are built the same they would react the same.
 HELP!

 TIA!
 Robert

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] What's wrong with this IF statement?

2004-04-22 Thread John W. Holmes
From: Robert Sossomon [EMAIL PROTECTED]

   if ($cat_id != 53 || $cat_id != 54 || $cat_id != 55 || $cat_id
 != 117 || $cat_id != 118 || $cat_id != 74)

Okay, if $cat_id is 53, this will work out to:

if(FALSE || TRUE || TRUE || TRUE || TRUE || TRUE)

which results in TRUE overall. 

You want  instead of ||

if ($cat_id != 53  $cat_id != 54  $cat_id != 55  $cat_id
!= 117  $cat_id != 118  $cat_id != 74)

which results in

if(FALSE  TRUE  TRUE  TRUE  TRUE  TRUE)

which results in FALSE overall.

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] What's wrong with this IF statement?

2004-04-22 Thread Chris Shiflett
--- Robert Sossomon [EMAIL PROTECTED] wrote:
 if ($cat_id != 53 || $cat_id != 54 || $cat_id != 55 || $cat_id
 != 117 || $cat_id != 118 || $cat_id != 74)

That looks like a pretty big logical flaw to me. Just read that out loud
to yourself. It should be clear that this statement is equivalent to:

if (true)

Hope that helps.

Chris

=
Chris Shiflett - http://shiflett.org/

PHP Security - O'Reilly
 Coming Fall 2004
HTTP Developer's Handbook - Sams
 http://httphandbook.org/
PHP Community Site
 http://phpcommunity.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php