Re: [PHP] can't output sql query with php code.

2006-02-06 Thread Sumeet

Paul Goepfert wrote:

This is the full code for the code that doesn't work.

?php
echo 'select name=month \n';
$month_query = mysql_query(SELECT m_id, months FROM Month);
while ($r = mysql_fetch_array($month_query));
{
$v = $r[m_id];
$out = $r[months];  
echo option value=$v$out/option\n;
}
echo '/select\n';
?


dear sir,

overall, i can see no visible error. but u must debug the process.

1. please add print_r($r) within the while loop to see the contents.
2. check the num of rows returned by mysql_query.
3. check it mysql_query is not returning an error.


--
Sumeet Shroff
http://www.prateeksha.com
Web Design and Ecommerce Development, Mumbai India

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



RE: [PHP] can't output sql query with php code.

2006-02-06 Thread Brady Mitchell
 ?php
 echo 'select name=month \n';
 $month_query = mysql_query(SELECT m_id, months FROM Month);
 while ($r = mysql_fetch_array($month_query));

 
Remove the semi-colon at the end of the above line and it works like a charm.
 
 {
 $v = $r[m_id];
 $out = $r[months];   
 echo option value=$v$out/option\n;
 }
 echo '/select\n';
 ?

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



Re: [PHP] can't output sql query with php code.

2006-02-06 Thread Paul Goepfert
Thanks everyone for your help.  I should have seen the semi-colon at
the end of the while loop.  I must have looked at the code 20 times
and I can't believe I missed it.

Paul
On 2/6/06, Brady Mitchell [EMAIL PROTECTED] wrote:
  ?php
  echo 'select name=month \n';
  $month_query = mysql_query(SELECT m_id, months FROM Month);
  while ($r = mysql_fetch_array($month_query));


 Remove the semi-colon at the end of the above line and it works like a charm.

  {
  $v = $r[m_id];
  $out = $r[months];
  echo option value=$v$out/option\n;
  }
  echo '/select\n';
  ?



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



Re: [PHP] can't output sql query with php code.

2006-02-06 Thread Jay Paulson
It always helps to have a different point of view to look at code sometimes.
Else you'll go bonkers looking for that stupid semi-colon! :)




On 2/6/06 2:18 AM, Paul Goepfert [EMAIL PROTECTED] wrote:

 Thanks everyone for your help.  I should have seen the semi-colon at
 the end of the while loop.  I must have looked at the code 20 times
 and I can't believe I missed it.
 
 Paul
 On 2/6/06, Brady Mitchell [EMAIL PROTECTED] wrote:
 ?php
 echo 'select name=month \n';
 $month_query = mysql_query(SELECT m_id, months FROM Month);
 while ($r = mysql_fetch_array($month_query));
 
 
 Remove the semi-colon at the end of the above line and it works like a charm.
 
 {
 $v = $r[m_id];
 $out = $r[months];
 echo option value=$v$out/option\n;
 }
 echo '/select\n';
 ?
 
 
 
 --
 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] can't output sql query with php code.

2006-02-05 Thread Chris

Hi Paul,

If equip contains a space it will probably break the dropdown.

Change it to:

echo option value=' . htmlspecialchars($val) . '$val/option\n;

in case it has quotes, spaces,  or  in it.

Paul Goepfert wrote:

Hi all,

I have a mysql database setup to use with my php web page.  I have
been able to access the database and get values into my drop down
menus.  However when I tried to output the contents into two two
diferent variables the code does not work.  To be more specific I will
show you the code both the one that works and the one that doesn't

Doesn't work
-
?php
$month_query = mysql_query(SELECT m_id, months FROM Month);
while ($row = mysql_fetch_array($month_query))
{
 $val = $row[m_id];
 $out = $row[months];
 echo option value=$val$out/option;
}
?

-
Code that works
-
?php

echo '  select name=equipment size=1 id=equip 
onChange=addRow()';
$Equip_query = mysql_query(SELECT equip FROM Equipment ORDER BY
equip ASC);

while ($r = mysql_fetch_array($Equip_query))
{
 $val = $r[equip];
 echo option value=$val$val/option\n;
}
echo /select/td;
?

Also I should tell you that the code that works comes after the code
that doesn't work in my web page.

Oh for the values that are outputted in the code that doesn't work are
val is numeric and out is a string.

I know my sql query works because I tested it in mysql.

Thanks for the help

Paul



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



RE: [PHP] can't output sql query with php code.

2006-02-05 Thread Brady Mitchell
 Doesn't work
 -
 ?php
 $month_query = mysql_query(SELECT m_id, months FROM Month);
 while ($row = mysql_fetch_array($month_query))
 {
  $val = $row[m_id];
  $out = $row[months];
  echo option value=$val$out/option;
 }
 ?

You're missing the select tags.

 while ($r = mysql_fetch_array($Equip_query))
 {
  $val = $r[equip];
  echo option value=$val$val/option\n;
 }

On a seperate note, if all you are doing with the $val variable is using it to 
echo, it's not needed.  Put brackets { } around the var to echo ie: 
{$r[equip]} - makes it easier to read later when you come back to tweak your 
code.

Brady

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



Re: [PHP] can't output sql query with php code.

2006-02-05 Thread Paul Goepfert
This is the full code for the code that doesn't work.

?php
echo 'select name=month \n';
$month_query = mysql_query(SELECT m_id, months FROM Month);
while ($r = mysql_fetch_array($month_query));
{
$v = $r[m_id];
$out = $r[months];
echo option value=$v$out/option\n;
}
echo '/select\n';
?

On 2/6/06, Brady Mitchell [EMAIL PROTECTED] wrote:
  Doesn't work
  -
  ?php
  $month_query = mysql_query(SELECT m_id, months FROM Month);
  while ($row = mysql_fetch_array($month_query))
  {
   $val = $row[m_id];
   $out = $row[months];
   echo option value=$val$out/option;
  }
  ?

 You're missing the select tags.

  while ($r = mysql_fetch_array($Equip_query))
  {
   $val = $r[equip];
   echo option value=$val$val/option\n;
  }

 On a seperate note, if all you are doing with the $val variable is using it 
 to echo, it's not needed.  Put brackets { } around the var to echo ie: 
 {$r[equip]} - makes it easier to read later when you come back to tweak your 
 code.

 Brady







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