[PHP] A better solution?

2003-08-04 Thread Ryan A
Hi,
I have a table called the_slave where i am entering differient types of data
and 5 specific types, to get a count of each of the types i used:

$tt = SELECT ptype, count(*) FROM the_slave WHERE ptype IN ('1', '2',
'3','4','5')  and user='.$user.' and no='.$no.' GROUP BY ptype;

then to dump them into variables that I could use anywhere in the page, i
used:

if($res = mysql_query($tt))
{
  $x = 1;
  while($row = mysql_fetch_row($res))
  { $var[$x++] = $row[1]; }
}

In this way I could use it like: Hello and welcome, you have: $var[1] of
type 1 etc

now i am facing a new problem, I need to do the same as above but from 5
differient tables (tabl1,tabl2,tabl3,tabl4 and tabl5) I can of course run 5
select/count queries but is there a way to run just one and get the same
effect? I will need to dump it into an arrar and use it the way i used
$var[]

Any ideas?

Thanks,
-Ryan





We will slaughter you all! - The Iraqi (Dis)information ministers site
http://MrSahaf.com



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



Re: [PHP] A better solution?

2003-08-04 Thread Marek Kilimajer


Ryan A wrote:

Hi,
I have a table called the_slave where i am entering differient types of data
and 5 specific types, to get a count of each of the types i used:
$tt = SELECT ptype, count(*) FROM the_slave WHERE ptype IN ('1', '2',
'3','4','5')  and user='.$user.' and no='.$no.' GROUP BY ptype;
then to dump them into variables that I could use anywhere in the page, i
used:
if($res = mysql_query($tt))
{
  $x = 1;
  while($row = mysql_fetch_row($res))
I would not be so sure the rows are in the right order here, use
{ $var[$row[0]] = $row[1]; }
instead of
  { $var[$x++] = $row[1]; }
}
In this way I could use it like: Hello and welcome, you have: $var[1] of
type 1 etc
now i am facing a new problem, I need to do the same as above but from 5
differient tables (tabl1,tabl2,tabl3,tabl4 and tabl5) I can of course run 5
select/count queries but is there a way to run just one and get the same
effect? I will need to dump it into an arrar and use it the way i used
$var[]
Any ideas?

Thanks,
-Ryan




We will slaughter you all! - The Iraqi (Dis)information ministers site
http://MrSahaf.com




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


Re: [PHP] A better solution?

2003-08-04 Thread Curt Zirzow
* Thus wrote Ryan A ([EMAIL PROTECTED]):
 Hi,
 I have a table called the_slave where i am entering differient types of data
 and 5 specific types, to get a count of each of the types i used:
 
 $tt = SELECT ptype, count(*) FROM the_slave WHERE ptype IN ('1', '2',
 '3','4','5')  and user='.$user.' and no='.$no.' GROUP BY ptype;
 
 then to dump them into variables that I could use anywhere in the page, i
 used:
 
 if($res = mysql_query($tt))
 {
   $x = 1;
   while($row = mysql_fetch_row($res))
   { $var[$x++] = $row[1]; }
 }
 
 In this way I could use it like: Hello and welcome, you have: $var[1] of
 type 1 etc

$var[1] isn't guaranteed to be of ptype '1' I would suggest to use
  $var[$row[0]] = $row[1];

 
 now i am facing a new problem, I need to do the same as above but from 5
 differient tables (tabl1,tabl2,tabl3,tabl4 and tabl5) I can of course run 5
 select/count queries but is there a way to run just one and get the same
 effect? I will need to dump it into an arrar and use it the way i used
 $var[]
 
 Any ideas?

You can use the union statement to achieve this
select ptype, count(*), 'the_slave' from the_slave where ...
union
select ptype, count(*), 'table1' from table1 where ...
...

http://www.mysql.com/doc/en/UNION.html


Curt
-- 
I used to think I was indecisive, but now I'm not so sure.

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



[PHP] need better solution...

2001-05-14 Thread Christian Dechery

In most of my scripts there are always headers and footers to html outputs...
like logos, images, and on the bottom some links and stuff like that... 
that should always apear...

the most basic is:

html
... header here ...
?php
lots of code
?
... footer here ...
/html

but sometimes I want something like this:
?php
 session_start(); // for instance
 code code code
 if(something)
 print error message and terminate script;
?
html
sadasdsa
/html

what do I do in this case??? I've tried all kinds of programing 
techniques... but none of them seems to fit here.


. Christian Dechery (lemming)
. http://www.tanamesa.com.br
. Gaita-L Owner / Web Developer



Re: [PHP] need better solution...

2001-05-14 Thread CC Zona

In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] (Christian Dechery) wrote:

 html
 ... header here ...
 ?php
 lots of code
 ?
 ... footer here ...
 /html
 
 but sometimes I want something like this:
 ?php
  session_start(); // for instance
  code code code
  if(something)
  print error message and terminate script;
 ?
 html
 sadasdsa
 /html

http://php.net/manual/en/ref.outcontrol.php

-- 
CC

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] need better solution...

2001-05-14 Thread James Atkinson

I would suggest some sort of Templating solution. Take a look at Smarty,
PHPLib, or FastTemplates.

- James

 -Original Message-
 From: Christian Dechery [mailto:[EMAIL PROTECTED]]
 Sent: May 14, 2001 5:11 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] need better solution...


 In most of my scripts there are always headers and footers to html
 outputs...
 like logos, images, and on the bottom some links and stuff like that...
 that should always apear...

 the most basic is:

 html
 ... header here ...
 ?php
 lots of code
 ?
 ... footer here ...
 /html

 but sometimes I want something like this:
 ?php
  session_start(); // for instance
  code code code
  if(something)
  print error message and terminate script;
 ?
 html
 sadasdsa
 /html

 what do I do in this case??? I've tried all kinds of programing
 techniques... but none of them seems to fit here.

 
 . Christian Dechery (lemming)
 . http://www.tanamesa.com.br
 . Gaita-L Owner / Web Developer



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] need better solution...

2001-05-14 Thread Jason Brooke

 but sometimes I want something like this:
 ?php
  session_start(); // for instance
  code code code
  if(something)
  print error message and terminate script;
 ?
 html
 sadasdsa
 /html

 what do I do in this case??? I've tried all kinds of programing
 techniques... but none of them seems to fit here.

I don't understand why you're asking what to do in that case - what exactly is
the problem there?

jason





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] need better solution...

2001-05-14 Thread David Robley

On Tue, 15 May 2001 09:40, Christian Dechery wrote:
 In most of my scripts there are always headers and footers to html
 outputs... like logos, images, and on the bottom some links and stuff
 like that... that should always apear...

 the most basic is:

 html
 ... header here ...
 ?php
 lots of code
 ?
 ... footer here ...
 /html

 but sometimes I want something like this:
 ?php
  session_start(); // for instance
  code code code
  if(something)
  print error message and terminate script;
 ?
 html
 sadasdsa
 /html

 what do I do in this case??? I've tried all kinds of programing
 techniques... but none of them seems to fit here.

exit or die are probably the tools you want.

-- 
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA  

   Blessed are the censors; they shall inhibit the earth.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] need better solution...

2001-05-14 Thread Christian Dechery

At 10:35 15/5/2001 +0930, David Robley wrote:
On Tue, 15 May 2001 09:40, Christian Dechery wrote:
  In most of my scripts there are always headers and footers to html
  outputs... like logos, images, and on the bottom some links and stuff
  like that... that should always apear...
 
  the most basic is:
 
  html
  ... header here ...
  ?php
  lots of code
  ?
  ... footer here ...
  /html
 
  but sometimes I want something like this:
  ?php
   session_start(); // for instance
   code code code
   if(something)
   print error message and terminate script;
  ?
  html
  sadasdsa
  /html
 
  what do I do in this case??? I've tried all kinds of programing
  techniques... but none of them seems to fit here.

exit or die are probably the tools you want.

yeah... that's what I use... but then the footer isn't going to be displayed...


. Christian Dechery (lemming)
. http://www.tanamesa.com.br
. Gaita-L Owner / Web Developer


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] need better solution...

2001-05-14 Thread Christian Dechery

At 11:02 15/5/2001 +1000, Jason Brooke wrote:
  but sometimes I want something like this:
  ?php
   session_start(); // for instance
   code code code
   if(something)
   print error message and terminate script;
  ?
  html
  sadasdsa
  /html
 
  what do I do in this case??? I've tried all kinds of programing
  techniques... but none of them seems to fit here.

I don't understand why you're asking what to do in that case - what exactly is
the problem there?


the problem is, if I terminate the script on that condition the footer 
won't be displayed...


. Christian Dechery (lemming)
. http://www.tanamesa.com.br
. Gaita-L Owner / Web Developer


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] need better solution...

2001-05-14 Thread Jason Brooke

 the problem is, if I terminate the script on that condition the footer
 won't be displayed...

Instant fix - include footer.inc; exit;

Better fix: decide your logical layout before you proceed and arrange if/else
blocks accordingly so you don't need to terminate the script to avoid showing a
page's contents.

ie: have your single template shell which includes a particular content
container if your code allows. here's one way

?
/*
protect yourself from people doing things like
http://your.domain/your/script?include=../../../../../../../../some/secret/file
*/
unset($include); // will do for the purpose of this example

if ($something)
$include = this_particular_content.inc;
else if ($something_else)
$include = this_other_content.inc;

include your_header.inc;

include $include;

include footer.inc;
?




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] need better solution

2001-02-15 Thread Christian Reiniger

On Thursday 15 February 2001 02:49, Christian Dechery wrote:

   that's kinda what I have here... but the line of code isn't being
   shown... and that is the problem... I for one, think that in an
   error message the line of code is crucial.
 
 Check the manual for set_error_handler ()

 well... that could help, but even than I'd have to call that
 error_handler everytime I execd a query and still would have to pass to
 it the __LINE__ of code...

Read that section again. That error handler is called automatically every 
time an error occurs, and __LINE__ is also passed automatically to it.

-- 
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)

I saw God - and she was black.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] need better solution

2001-02-15 Thread Maxim Maletsky

use 

mysql_query($. , ) or die(mysql_error() . ' oopps..   big time
')

Cheers,
Maxim Maletsky

-Original Message-
From: Christian Dechery [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 15, 2001 12:51 AM
To: [EMAIL PROTECTED]
Subject: [PHP] need better solution


I need a better solution for reporting SQL errors.

I'm used to work with ASP, and whenever a query has a syntax error, it stops
the script and reports the error as if it was a compile error. This is very
usefull, but int PHP it doesn't work like that, I know.

I came with a function query_error() that I call after each query, that
prints out the query, the error and the line... so I need to call it like
this.

if(!$rs) query_error($query,__LINE__);

but having to writ this down after EVERY single query, along with the
__LINE__
thing can get very boring, does anyone has a better solution?


. [ Christian Dechery  ]
. Webdeveloper @ T Na Mesa!
. Listmaster @ Gaita-L
. http://www.tanamesa.com.br



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] need better solution

2001-02-15 Thread Maxim Maletsky

yeah ... then at this point why not to use PHPLIB that has it built in
already...

phplib.netuse.de

a great thing ...

Cheers,
Maxim Maletsky



-Original Message-
From: Chris Lee [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 15, 2001 1:02 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] need better solution


works for me, just call it. change it to better match yours if you like.

 function check_db($query = 'Unavailble')
 {
  global $store_db;
  if ( mysql_errno() )
{
  echo "Error: Problem with DataBase : $store_dbbr\n";
  echo "Error: " . mysql_errno() . ':' . mysql_error() . "br\n";
  echo "Query: $querybr\n";
  exit();
}
 }

I havent played with a more automatic metod, ie. error_reporting();


--


Chris Lee
Mediawaveonline.com

em. [EMAIL PROTECTED]

ph. 250.377.1095
ph. 250.376.2690
fx. 250.554.1120



""Christian Dechery"" [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
I need a better solution for reporting SQL errors.

I'm used to work with ASP, and whenever a query has a syntax error, it stops
the script and reports the error as if it was a compile error. This is very
usefull, but int PHP it doesn't work like that, I know.

I came with a function query_error() that I call after each query, that
prints out the query, the error and the line... so I need to call it like
this.

if(!$rs) query_error($query,__LINE__);

but having to writ this down after EVERY single query, along with the
__LINE__
thing can get very boring, does anyone has a better solution?


. [ Christian Dechery  ]
. Webdeveloper @ T Na Mesa!
. Listmaster @ Gaita-L
. http://www.tanamesa.com.br



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] need better solution

2001-02-14 Thread Chris Lee

works for me, just call it. change it to better match yours if you like.

 function check_db($query = 'Unavailble')
 {
  global $store_db;
  if ( mysql_errno() )
{
  echo "Error: Problem with DataBase : $store_dbbr\n";
  echo "Error: " . mysql_errno() . ':' . mysql_error() . "br\n";
  echo "Query: $querybr\n";
  exit();
}
 }

I havent played with a more automatic metod, ie. error_reporting();


--


Chris Lee
Mediawaveonline.com

em. [EMAIL PROTECTED]

ph. 250.377.1095
ph. 250.376.2690
fx. 250.554.1120



""Christian Dechery"" [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
I need a better solution for reporting SQL errors.

I'm used to work with ASP, and whenever a query has a syntax error, it stops
the script and reports the error as if it was a compile error. This is very
usefull, but int PHP it doesn't work like that, I know.

I came with a function query_error() that I call after each query, that
prints out the query, the error and the line... so I need to call it like
this.

if(!$rs) query_error($query,__LINE__);

but having to writ this down after EVERY single query, along with the
__LINE__
thing can get very boring, does anyone has a better solution?


. [ Christian Dechery  ]
. Webdeveloper @ Tá Na Mesa!
. Listmaster @ Gaita-L
. http://www.tanamesa.com.br



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] need better solution

2001-02-14 Thread Michael Kimsal

What version of PHP are you using?  If there's a syntax error in our
statements, it stops execution, just like ASP.

There are error_reporting levels you can play with, and have errors trigger
certain functions to handle the errors gracefully.


Christian Dechery wrote:

 I need a better solution for reporting SQL errors.

 I'm used to work with ASP, and whenever a query has a syntax error, it stops
 the script and reports the error as if it was a compile error. This is very
 usefull, but int PHP it doesn't work like that, I know.

 I came with a function query_error() that I call after each query, that
 prints out the query, the error and the line... so I need to call it like
 this.

 if(!$rs) query_error($query,__LINE__);

 but having to writ this down after EVERY single query, along with the __LINE__
 thing can get very boring, does anyone has a better solution?

 . [ Christian Dechery  ]
 . Webdeveloper @ T Na Mesa!
 . Listmaster @ Gaita-L
 . http://www.tanamesa.com.br

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] need better solution

2001-02-14 Thread Christian Dechery

works for me, just call it. change it to better match yours if you like.

 function check_db($query = 'Unavailble')
 {
  global $store_db;
  if ( mysql_errno() )
{
  echo "Error: Problem with DataBase : $store_dbbr\n";
  echo "Error: " . mysql_errno() . ':' . mysql_error() . "br\n";
  echo "Query: $querybr\n";
  exit();
}
 }

that's kinda what I have here... but the line of code isn't being shown...
and that is the problem... I for one, think that in an error message the
line of code is crucial.



. [ Christian Dechery  ]
. Webdeveloper @ T Na Mesa!
. Listmaster @ Gaita-L
. http://www.tanamesa.com.br



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] need better solution

2001-02-14 Thread Christian Dechery

At 19:53 14/2/2001 +0100, Christian Reiniger wrote:
On Wednesday 14 February 2001 18:43, Christian Dechery wrote:
  that's kinda what I have here... but the line of code isn't being
  shown... and that is the problem... I for one, think that in an error
  message the line of code is crucial.

Check the manual for set_error_handler ()

well... that could help, but even than I'd have to call that error_handler 
everytime I execd a query and still would have to pass to it the __LINE__ 
of code...

so, I'd wouldn't exactly help...

. Christian Dechery (lemming)
. http://www.tanamesa.com.br
. Gaita-L Owner / Web Developer


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]