Re: [PHP] mysql_fecth_array() and function call as parameter

2006-03-27 Thread Paul Goepfert
I have done the following to my code hoping that the fix would work

$query1 = mysql_query(SELECT months FROM Month WHERE m_id = month(curdate()));
//echo $query1 . br /;

$query1_data = mysql_fetch_assoc($query1);
echo $query1_data . br /;  returns Array (The word that is)
switch ($query1_data)
{

I also outputted
$query2 = mysql_query(SELECT dayNum FROM Days WHERE dayNum = 
day(curdate()));
echo $query2 . br /;

and I got an empty string

This is the code that I use when I call the function

$month = $this-determineMonth();
//echo $month . br /;
$Month_query = mysql_query($month);
//echo mysql_error() . br /;
while ($x = mysql_fetch_assoc($Month_query))
{
$form .=option value={$x[m_id]}{$x[months]}/option\n;
}

And according to my apache error log I have

[Mon Mar 27 11:34:42 2006] [error] [client 192.168.0.2] PHP Warning: 
mysql_fetch_assoc(): supplied argument is not a valid MySQL result
resource in C:\\Program Files\\Apache
Group\\Apache2\\htdocs\\validation.php on line 130
[Mon Mar 27 11:34:42 2006] [error] [client 192.168.0.2] PHP Warning: 
mysql_fetch_assoc(): supplied argument is not a valid MySQL result
resource in C:\\Program Files\\Apache
Group\\Apache2\\htdocs\\validation.php on line 342

By the way I tested the SQL statements in MYSQL and they returned the
values I was looking for.

What am I missing?  At the time of this email I was unable to check
the php docs at php.net.

Thanks,

Paul
On 3/26/06, Chris [EMAIL PROTECTED] wrote:
 Paul Goepfert wrote:
  I placed the echo statements in my code and I found out that my query
  was empty.  I also went a step further and tested if I was getting the
  correct outputs from the queries that initially do at the beginning of
  the method.  Instead of getting an output like March I got an output
  that says Resource id#9.  I don't get it.  I tested the sql
  statement in MySQL that I have on my computer.  It worked,  Why
  wouldn't it give the same output through mysql_query()?

 Ahh, didn't notice that.


 $query1 = mysql_query(SELECT months FROM Month WHERE m_id =
 month(curdate()));

 $query2 = mysql_query(SELECT dayNum FROM Days WHERE dayNum =
 day(curdate()));

 $query3 = mysql_query(SELECT year FROM Year WHERE year = year(curdate()));


 These return result resources (kinda like '$fp = fopen' doesn't return
 the file - it returns a handle only), not the results. You need to do:

 $query1_data = mysql_fetch_assoc($query1, 0, 0);

 then

 switch($query1_data) {
 
 }

 see http://www.php.net/mysql_query and
 http://www.php.net/mysql_fetch_assoc for more info.


  On 3/26/06, Chris [EMAIL PROTECTED] wrote:
 
 Paul Goepfert wrote:
 
 Hi all,
 
 I have wriiten a function that determines whether tomorrows date is
 the first of the month or not then returns a SQL string based on
 whether its the first of the month or not.  According to my apache
 error logs I get an error that says:
 
 [Sun Mar 26 21:43:14 2006] [error] [client 192.168.0.2] PHP Warning:
 mysql_fetch_array(): supplied argument is not a valid MySQL result
 resource in C:\\Program Files\\Apache
 Group\\Apache2\\htdocs\\validation.php on line 331
 
 I understand that this is a warning but I believe that it has
 something to do with the fact that no output is being displayed.  All
 other mysql database outputs work fine.
 
 This is the code that sets the query in the mysql_query parameter
 
 $Month_query = mysql_query($this-determineMonth());
 
 Add this after your month_query call:
 
 echo mysql_error() . br/;
 
 It will tell you what's wrong with the query. I'd probably also print
 out the query:
 
 $qry = $this-determineMonth();
 echo $qry . br/;
 
 and run it manually (if something does get returned).
 
 --
 Postgresql  php tutorials
 http://www.designmagick.com/
 
 
 


 --
 Postgresql  php tutorials
 http://www.designmagick.com/


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



RE: [PHP] mysql_fecth_array() and function call as parameter

2006-03-27 Thread Brady Mitchell
 I have done the following to my code hoping that the fix would work
 
 $query1 = mysql_query(SELECT months FROM Month WHERE m_id =
month(curdate()));
 //echo $query1 . br /;
 
 $query1_data = mysql_fetch_assoc($query1);
   echo $query1_data . br /;  returns Array 
 (The word that is)

Use:  print_r($query1_data) or var_dump($query1_data) to see everything
in the array.  If you want to use echo, you'd have to echo each index of
the array one at a time with something like:  echo $query1_data[0]; 

http://php.net/echo
http://php.net/print_r
http://php.net/var_dump

 switch ($query1_data)
 {

You can't switch on an entire array.  Switch is used to check the value
of a variable (which could be an index of the array, but not the entire
array).

Something like this should work:

switch($query1_data[months])
{

}

http://php.net/switch

In your original posting you have lines like the following in your
switch statement: 

 if($query2 == 31)

As someone mentioned, mysql_query returns a resource ID, you then have
to use mysql_fetch_assoc (or one of the other mysql_fetch_* functions)
to get an array that you can use as you are trying to do.

So after doing:  $query2_data = mysql_fetch_assoc($query2);

You could do:  if($query2_data[dayNum] == 31)

In your switch statement you are checking for the full name of the
month, but your query will be returning the month number.  Since you
don't have a default case on your switch statement, $return is never
being set, so  $month = $this-determineMonth();  is not setting
$month to anything, which is why you are getting error messages.

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

Brady

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



Re: [PHP] mysql_fecth_array() and function call as parameter

2006-03-27 Thread Paul Goepfert
I finally got the function to work.  However I have a problem with
another function.  It is almost exactly like the origional function
but in this function I am determining the days instead of the month. 
I made the same changes to the days function as I did to the month
function.  However no value is being set to be returned. I can't find
my error. My function is below:

function determineDay ()
{
$return = ;
$query1 = mysql_query(SELECT months FROM Month WHERE m_id =
month(curdate()));
$query2 = mysql_query(SELECT dayNum FROM Days WHERE dayNum =
day(curdate()));
$query3 = mysql_query(SELECT year FROM Year WHERE year = 
year(curdate()));

$query1_data = mysql_fetch_assoc($query1);
$query2_data = mysql_fetch_assoc($query2);
$query3_data = mysql_fetch_assoc($query3);

switch ($query1_data[months])
{
case January:
case March:
case May:
case July:
case August:
case October:
case December:
if ($query2_data[dayNum] == 31)
$return .= SELECT dayNum FROM Days;
else
$return .= SELECT dayNum FROM Days 
WHERE dayNum = day(curdate()) +1;
break;
case February:
if ($query2_data[dayNum] == 28 || 
$query2_data[dayNum] == 29)
{
if ($query2_data[dayNum] == 28)
$return .= SELECT dayNum FROM 
Days WHERE dayNum = 28;
else
$return .= SELECT dayNum FROM 
Days WHERE dayNum = 29;
}
else
{
if (($query3_data[year] % 4 == 0) 
($query3_data[year] % 100
!= 0 || $query3_data[year] % 400 == 0))
$return .= SELECT dayNum FROM 
Days WHERE dayNum =
day(curdate()) +1 AND dayNum =28;
else
$return .= SELECT dayNum FROM 
Days WHERE dayNum =
day(curdate()) +1 AND dayNum =29;
}
break;
case April:
case June:
case September:
case November:
if ($query2_data[dayNum] == 30)
$return .= SELECT dayNum FROM Days 
WHERE dayNum = 30;
else
$return .= SELECT dayNum FROM Days 
WHERE dayNum =
day(curdate())+1 AND dayNum = 30;
break;
}
return $return;
}

Here is the code for where I output the contents of the query

$day = $this-determineDay();
$Day_query = mysql_query($day);
while ($a = mysql_fetch_assoc($Day_query))
{
$form .= option 
value={$a[dayNum]}{$a[dayNum]}/option\n;
}
$form .=   /select\n;

If anyone can find my error please let me know.  I have looked at this
for about an hour and I can't figure it out.

Thanks,

Paul
On 3/27/06, Brady Mitchell [EMAIL PROTECTED] wrote:
  I have done the following to my code hoping that the fix would work
 
  $query1 = mysql_query(SELECT months FROM Month WHERE m_id =
 month(curdate()));
  //echo $query1 . br /;
 
  $query1_data = mysql_fetch_assoc($query1);
echo $query1_data . br /;  returns Array
  (The word that is)

 Use:  print_r($query1_data) or var_dump($query1_data) to see everything
 in the array.  If you want to use echo, you'd have to echo each index of
 the array one at a time with something like:  echo $query1_data[0];

 http://php.net/echo
 http://php.net/print_r
 http://php.net/var_dump

  switch ($query1_data)
  {

 You can't switch on an entire array.  Switch is used to check the value
 of a variable (which could be an index of the array, but not the entire
 array).

 Something like this should work:

 switch($query1_data[months])
 {

 }

 http://php.net/switch

 In your original posting you have lines like the following in your
 switch statement:

  if($query2 == 31)

 As someone mentioned, mysql_query returns a resource ID, you then have
 to use mysql_fetch_assoc (or one of the other mysql_fetch_* functions)
 to get an array that you can use as you are trying to do.

 So after doing:  $query2_data 

RE: [PHP] mysql_fecth_array() and function call as parameter

2006-03-27 Thread Brady Mitchell
 -Original Message-
 I finally got the function to work.  However I have a problem with
 another function.  It is almost exactly like the origional function
 but in this function I am determining the days instead of the month. 
 I made the same changes to the days function as I did to the month
 function.  However no value is being set to be returned. I can't find
 my error. My function is below:

snip

   switch ($query1_data[months])
   {
   case January:
   case March:
   case May:
   case July:
   case August:
   case October:
   case December:

Once again, in your switch statement you are checking for the full name
of the
month, but your query will be returning the month number.  Since you
don't have a default case on your switch statement, $return is never
being set, so  $day = $this-determineDay();  is not setting
$month to anything, which is why you are getting error messages.

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

Brady

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



Re: [PHP] mysql_fecth_array() and function call as parameter

2006-03-27 Thread Paul Goepfert
according to my SQL the month name ois going to be returned not the
month number.

m_id is the number equivlent to the month.
months is the full name of the month.

In my month method I did not change the case values to the month
number and the function returns correctly.  All I had to do was add
the column name to $query1_data[] or $query2_data[]  But in this
method it didn't work.  I can't figure it out.  I've even checked my
column name to be sure I spelled it right.  It was.



On 3/27/06, Brady Mitchell [EMAIL PROTECTED] wrote:
  -Original Message-
  I finally got the function to work.  However I have a problem with
  another function.  It is almost exactly like the origional function
  but in this function I am determining the days instead of the month.
  I made the same changes to the days function as I did to the month
  function.  However no value is being set to be returned. I can't find
  my error. My function is below:

 snip

switch ($query1_data[months])
{
case January:
case March:
case May:
case July:
case August:
case October:
case December:

 Once again, in your switch statement you are checking for the full name
 of the
 month, but your query will be returning the month number.  Since you
 don't have a default case on your switch statement, $return is never
 being set, so  $day = $this-determineDay();  is not setting
 $month to anything, which is why you are getting error messages.

 http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

 Brady


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



Re: [PHP] mysql_fecth_array() and function call as parameter

2006-03-26 Thread Chris

Paul Goepfert wrote:

Hi all,

I have wriiten a function that determines whether tomorrows date is
the first of the month or not then returns a SQL string based on
whether its the first of the month or not.  According to my apache
error logs I get an error that says:

[Sun Mar 26 21:43:14 2006] [error] [client 192.168.0.2] PHP Warning: 
mysql_fetch_array(): supplied argument is not a valid MySQL result

resource in C:\\Program Files\\Apache
Group\\Apache2\\htdocs\\validation.php on line 331

I understand that this is a warning but I believe that it has
something to do with the fact that no output is being displayed.  All
other mysql database outputs work fine.

This is the code that sets the query in the mysql_query parameter

$Month_query = mysql_query($this-determineMonth());


Add this after your month_query call:

echo mysql_error() . br/;

It will tell you what's wrong with the query. I'd probably also print 
out the query:


$qry = $this-determineMonth();
echo $qry . br/;

and run it manually (if something does get returned).

--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP] mysql_fecth_array() and function call as parameter

2006-03-26 Thread Paul Goepfert
I placed the echo statements in my code and I found out that my query
was empty.  I also went a step further and tested if I was getting the
correct outputs from the queries that initially do at the beginning of
the method.  Instead of getting an output like March I got an output
that says Resource id#9.  I don't get it.  I tested the sql
statement in MySQL that I have on my computer.  It worked,  Why
wouldn't it give the same output through mysql_query()?

Paul

On 3/26/06, Chris [EMAIL PROTECTED] wrote:
 Paul Goepfert wrote:
  Hi all,
 
  I have wriiten a function that determines whether tomorrows date is
  the first of the month or not then returns a SQL string based on
  whether its the first of the month or not.  According to my apache
  error logs I get an error that says:
 
  [Sun Mar 26 21:43:14 2006] [error] [client 192.168.0.2] PHP Warning:
  mysql_fetch_array(): supplied argument is not a valid MySQL result
  resource in C:\\Program Files\\Apache
  Group\\Apache2\\htdocs\\validation.php on line 331
 
  I understand that this is a warning but I believe that it has
  something to do with the fact that no output is being displayed.  All
  other mysql database outputs work fine.
 
  This is the code that sets the query in the mysql_query parameter
 
  $Month_query = mysql_query($this-determineMonth());

 Add this after your month_query call:

 echo mysql_error() . br/;

 It will tell you what's wrong with the query. I'd probably also print
 out the query:

 $qry = $this-determineMonth();
 echo $qry . br/;

 and run it manually (if something does get returned).

 --
 Postgresql  php tutorials
 http://www.designmagick.com/


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



Re: [PHP] mysql_fecth_array() and function call as parameter

2006-03-26 Thread Chris

Paul Goepfert wrote:

I placed the echo statements in my code and I found out that my query
was empty.  I also went a step further and tested if I was getting the
correct outputs from the queries that initially do at the beginning of
the method.  Instead of getting an output like March I got an output
that says Resource id#9.  I don't get it.  I tested the sql
statement in MySQL that I have on my computer.  It worked,  Why
wouldn't it give the same output through mysql_query()?


Ahh, didn't notice that.


$query1 = mysql_query(SELECT months FROM Month WHERE m_id =
month(curdate()));

$query2 = mysql_query(SELECT dayNum FROM Days WHERE dayNum =
day(curdate()));

$query3 = mysql_query(SELECT year FROM Year WHERE year = year(curdate()));


These return result resources (kinda like '$fp = fopen' doesn't return 
the file - it returns a handle only), not the results. You need to do:


$query1_data = mysql_fetch_assoc($query1, 0, 0);

then

switch($query1_data) {

}

see http://www.php.net/mysql_query and 
http://www.php.net/mysql_fetch_assoc for more info.




On 3/26/06, Chris [EMAIL PROTECTED] wrote:


Paul Goepfert wrote:


Hi all,

I have wriiten a function that determines whether tomorrows date is
the first of the month or not then returns a SQL string based on
whether its the first of the month or not.  According to my apache
error logs I get an error that says:

[Sun Mar 26 21:43:14 2006] [error] [client 192.168.0.2] PHP Warning:
mysql_fetch_array(): supplied argument is not a valid MySQL result
resource in C:\\Program Files\\Apache
Group\\Apache2\\htdocs\\validation.php on line 331

I understand that this is a warning but I believe that it has
something to do with the fact that no output is being displayed.  All
other mysql database outputs work fine.

This is the code that sets the query in the mysql_query parameter

$Month_query = mysql_query($this-determineMonth());


Add this after your month_query call:

echo mysql_error() . br/;

It will tell you what's wrong with the query. I'd probably also print
out the query:

$qry = $this-determineMonth();
echo $qry . br/;

and run it manually (if something does get returned).

--
Postgresql  php tutorials
http://www.designmagick.com/







--
Postgresql  php tutorials
http://www.designmagick.com/

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