RE: [PHP] undefined variable when using if ($var) {}

2002-03-25 Thread Darren Gamble

Good day.

What is this message that you get, that you don't want?

A cursory glance of the code reveals two "else" statements attached to the
same "if" statement.  You should address that.


Darren Gamble
Planner, Regional Services
Shaw Cablesystems GP
630 - 3rd Avenue SW
Calgary, Alberta, Canada
T2P 4L4
(403) 781-4948


-Original Message-
From: Martha S [mailto:[EMAIL PROTECTED]]
Sent: Monday, March 25, 2002 9:44 AM
To: [EMAIL PROTECTED]
Subject: [PHP] undefined variable when using if ($var) {}


I'm rather new to PHP, so this should be fairly easy to answer. I checked
the manual and FAQ already.

I'm using the following code, and I get the following message if $id has
nothing in the var (i have it set to a default of  type int, not null in
mysql). Is there a way around this or something I'm missing?

Thanks :)

-- code---

if ($id) {

   $result = mysql_query("SELECT * FROM entries WHERE id=$id",$db);

   $myrow = mysql_fetch_array($result);

   printf("\n");
   printf("%s", $myrow["title"]);
   printf("%s | ", $myrow["id"]);
   printf("%s", $myrow["posted"]);
   printf("%s\n", $myrow["post"]);
   printf("\n");

   printf("all");

   } else {

do {

printf("%s %s\n", $myrow["id"], $PHP_SELF,
$myrow["id"], $myrow["title"], $myrow["post"]);

  } while ($myrow = mysql_fetch_array($result));

} else {

  // no records to display

  echo "Sorry, no records were found!";

}




-- 
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




[PHP] undefined variable when using if ($var) {}

2002-03-25 Thread Martha S

I'm rather new to PHP, so this should be fairly easy to answer. I checked
the manual and FAQ already.

I'm using the following code, and I get the following message if $id has
nothing in the var (i have it set to a default of  type int, not null in
mysql). Is there a way around this or something I'm missing?

Thanks :)

-- code---

if ($id) {

   $result = mysql_query("SELECT * FROM entries WHERE id=$id",$db);

   $myrow = mysql_fetch_array($result);

   printf("\n");
   printf("%s", $myrow["title"]);
   printf("%s | ", $myrow["id"]);
   printf("%s", $myrow["posted"]);
   printf("%s\n", $myrow["post"]);
   printf("\n");

   printf("all");

   } else {

do {

printf("%s %s\n", $myrow["id"], $PHP_SELF,
$myrow["id"], $myrow["title"], $myrow["post"]);

  } while ($myrow = mysql_fetch_array($result));

} else {

  // no records to display

  echo "Sorry, no records were found!";

}




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