Re: [PHP] SQL Join query

2004-08-08 Thread Lenar Lõhmus
Mattias Thorslund wrote:

> Though, (regardless of SQL database platform) in a case like this, it
> MAY be both more straightforward and efficient to use two separate
> queries for the pictures and comments, given the one-to-many cardinality
> between them.  The above statement causes redundant data to be returned
> - it duplicates the pics record for each new comment.  If there are many
> large columns in the pics table and many comments to each record there's
> a lot of redundant data in a query like that.

No, I think you are wrong. There was GROUP BY pics.id so it won't return
duplicate data. And probable overhead is eliminated too I think - DBserver
will optimize and will join data from pic_comments only once for each
unique pics.id.

Lenar

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



Re: [PHP] SQL Join query

2004-08-07 Thread Lenar Lõhmus
Raditha Dissanayake wrote:

> try postgres instead http://www.postgresql.org/

It's the most helpful comment I've seen for a long time.
You know, it won't work in Postgre too probably. If you like Postgre - 
use it and don't force others to use it (for wrong reasons nevertheless).
Everyone should pick his/her own tools...

Anyway, instead of writing this:

SELECT pics.*, pic_comments.*, count(*) AS num_comments FROM pics, 
pic_comments WHERE pics.category = 1 AND pics.id = pic_comments.pic_id GROUP 
BY pic_comments.pic_id;

Write this:

SELECT pics.*, pic_comments.*, count(*) AS num_comments 
FROM pics
LEFT JOIN pic_comments ON (pic_comments.pic_id = pics.id)
WHERE pics.category = 1
GROUP BY pics.pic_id;

Lenar

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



RE: [PHP] html form question

2001-07-26 Thread Lenar Lõhmus



On Thu, 26 Jul 2001, Seb Frost wrote:

> OK so how would that look if I'd done SELECT * instead of SELECT eventName?
> I'm guessing I have two nested while loops then?
> 
> I'm guessing something like this.?  Or is it not possible and I have to
> go back to mysql_result?

Nope, instead you can do smething like this:

$colval\n";
?>

Lenar

> 
>  mysql_connect("db", $user, $password);
> $result = mysql_query( "SELECT * FROM $table");
> 
> while(list($field) = mysql_fetch_column($result))
> {
> while(list($value) = mysql_fetch_row($result))
> echo "$value\n";
> }
> ?>
> 
> - seb
> 
> -Original Message-
> From: Lenar [mailto:[EMAIL PROTECTED]]
> Sent: 26 July 2001 13:16
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] html form question
> 
> 
> > Funny you should ask - just done it myself:
> 
> Why you use mysql_result function?
> 
> This can be done a bit simpler way (and more effective):
> 
>  mysql_connect("db", $user, $password);
> $result = mysql_query( "SELECT eventName FROM $table");
> while(list($event) = mysql_fetch_row($result))
> echo "$event\n";
> ?>
> 
> Lenar
> 
> >
> >  >   $table="shoots";
> >   require ("connect.php4");
> >   $result=MYSQL_QUERY( "SELECT eventName FROM $table");
> >   $num_rows = mysql_num_rows($result);
> >
> >   for ($i=0;$i<$num_rows;$i++)
> >   {
> >   echo "";
> >   echo mysql_result($result,$i,"eventName");
> >   echo "";
> >   }
> >
> >
> >   MYSQL_CLOSE();
> > ?>
> >
> > - seb
> 
> 
> 
> --
> 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] setcookie() woes

2001-06-20 Thread Lenar Lõhmus

In my experience the understanding of SetCookie header differs form browser
to browser so much that it's horrible.
As far as I remember IE5.5 handled it correctly. IE5.0 didn't. Netscape I
think did (not completely sure).
In any case .. session-based cookies seem to work in all of them. just call
setcookie($name, $value) and nothing more.
If you can't live without permament cookies you have to somehow (via
$USER_AGENT for example) differ the browsers and upon that
use setcookie the way that specific browser expects (you still have to find
out how each of them works and there are many more than just IE or Netscape
and their fifferent versions). I remember for example that one browser
needed domain name to work and other didn't want it all to work. Or
something like that.

Hope this helps.

lenar.

ps. I think setcookie() itself doesn't woe, just our great programmers at
netsacpe and microsoft can't correctly read and understand that short and
simple specification of cookies.

"Chris" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi all,
>
> I have a login script that works on one of my machines but not
> another, and I've determined the problem has to do with setcookie().
> One machine is using IE 5.50 and another is using 5.00, and I assume
> therein lies the problem.
>
> I've tried to plow through the dozens (hundreds?) of followups on the
> manual page for setcookie(). Most of the interesting ones seem to
> involve using header("SetCookie  . . .") instead of the setcookie()
> function. I tried a few, including the
> pass-every-parameter-to-setcookie-even-if-you're-not-really-using-them
> workaround, to no avail.
>
> Is this a well known problem, with a well known solution?
>
> Thanks,
> Chris
>
>
> --
> 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] Trimming Array value

2001-06-20 Thread Lenar Lõhmus

something like this:

 $val)
$ar[$key] = is_array($val) ? recursive_rtrim($val) : rtrim($val);
return $ar;
}
?>

lenar.

""Reuben D Budiardja"" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...

I have a multi-dimensional array. I want to trim every values so that none
of
them have trailing space.

What is the most efficient way to do that ?
I don't necessaryly know the dimension of the array ahead of time, so the
function need to be able to handle it recursively.


Thanks
Reuben D. Budiardja

--
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] Parse PHP inside a variable

2001-06-20 Thread Lenar Lõhmus

maybe function eval()?

lenar.
"Claus Heiko Niesen" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hello
>
> I'm having a variable that contains HTML with embedded PHP code.  When I
> echo it then the PHP code does not get executed.  Is there a way I can
> parse/print the content of my variable?
>
> Thanks
>Claus
>
>
> --
> 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] Code check please

2001-06-20 Thread Lenar Lõhmus

UPDATE syntax for INSERT is allowed in MySQL, so that should not be the
problem as far as you include all fields not having default value, timestamp
type or auto_increment attribute in your statement. What's the error message
if there is any?

lenar

""Rich Cavanaugh"" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> You're using UPDATE syntax for your INSERT
>
> try:
>
> $sql = "INSERT INTO tabell (fornamn, efternamn, email) values
('{$fornamn}',
> '{$efternamn}', '{$email}')";
>
> Rich Cavanaugh
>
> -Original Message-
> From: Andreas Skarin [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, June 20, 2001 12:00 PM
> To: PHP General
> Subject: [PHP] Code check please
>
>
> I've tried to get this working for over an hour
> now, and it still won't. I don't even get an error
> message to help me find the problem so I was
> hoping that someone could check my code for me.
>
> I'm fooling around with a basic form that is
> supposed to send one's name, surname and e-mail
> address to "receive.php". "receive.php" is then
> supposed to take the information and add it to a
> table called "tabell" in a database called
> "databas", but it doesn't work. I think there
> might be something wrong with my MySQL query.
>
> - - - - - - - - - - - FORM - - - - - - - - - - - -
> - -
>
> 
> Förnamn:
>  size="25">
> Efternamn:
>  size="25">
> E-mailadress:
>  size="25">
>  value="Log in">
> 
>
> - - - - - - - - - - - - - - - - - - - - - - - - -
> - - -
>
> - - - - - - - - - - - RECEIVE.PHP - - - - - - - -
> - - -
>
> 
> // connection to MySQL
> $connection = mysql_connect("localhost",
> "username", "password");
> if (!$connection) {
> echo ("Unable to connect to the database
> server at this time." );
> exit();
> }
>
> //select database
> if (! @mysql_select_db("databas") ) {
> echo ("Unable to locate the database at
> this time.");
> exit();
> }
>
> // MySQL query
> $sql = "INSERT INTO tabell SET" .
> "fornamn ='$fornamn'," .
> "efternamn='$efternamn'," .
> "email='$email';";
> ?>
>
> - - - - - - - - - - - - - - - - - - - - - - - - -
> - - -
>
> Thanks in advance!
>
> // Andreas
>
>
> --
> 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] parent and grandparent member functions

2001-06-20 Thread Lenar Lõhmus

yes, you were right it works (when you said it works i tested your code out
and it definetly works). but this made me more confused than i was before.
i commented in the lines in my code that earlier didn't work (replaced them
sometime with class names hard coded solution) and it still did _not_ work.
ok, made copies of files in action and started to strip them down.

First, my stripped down code that works:
make("whatever");
?>

now, when i remove the definition of class 'a' to another file and include
the file like this:

file1.php:



file2.php:

make("whatever");
?>

then i get message 'Warning: Missing argument 1 for make()' ... the code is
same ... but working differently.at least with my php 4.0.5. so i think this
is a bug.

that include in our system is neccessary so to the point it works correctly,
i have to hardcode class names.

and thank you scott pointing me out (and getting me confused :) ).

lenar.

"scott [gts]"" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> it looks like your solution *is* elegant... i tried
> out your code, becuase i was astonished that such a
> simple thing allegedly wasn't working... and it
> did work.
>
> below is the exact code i had in my text editor,
> and it executed perfectly.
> when i called $c->make(), it printed "A:: MAKE".
>
> ..am i misunderstanding your problem?
>
>
> 
> class a {
> function make() {
> // some code
> print "A:: MAKE";
> }
> }
>
> class b extends a {
> function make() {
> // some code
> parent::make();
> }
> }
>
> class c extends b {
> function make() {
> // some code
> parent::make();
> }
> }
>
>
>
> $c = new c();
> $c->make();
>
> ?>
>
>
> > -Original Message-
> > From: Lenar Lõhmus [mailto:[EMAIL PROTECTED]]
> > Sent: 20 June 2001 09:01
> > To: [EMAIL PROTECTED]
> > Subject: [PHP] parent and grandparent member functions
> >
> >
> > Hello,
> >
> > I hit a wall. No offense, but this OO stuff in PHP is somehat weird, but
> > skip to the problem.
> > I have for example three classes:
> >
> > class a {
> > function make() {
> > // some code
> > }
> > }
> >
> > class b extends a {
> > function make() {
> > // some code
> > parent::make();
> > }
> > }
> >
> > class c extends b {
> > function make() {
> > // some code
> > parent::make();
> > }
> > }
> >
> > now the class 'c' is instantiated and the member function 'make' is
called.
> > All works up to the point where 'b'::make calls parent::make().
> > It seems to call itself :(. I can understand this is logical behaviour
since
> > it's still an instance of class c,
> > so parent:: is still b::, but how should I call that grandparent's
make()???
> > This doesn't seem like a good OOP.
> > For example delphi's 'inherited' works relative to the class it's used
in
> > and it is way more useful than php's way.
> >
> > is there any elegant soultion(s) to my problem?
> >
> > Lenar Lõhmus
>
>
> --
> 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] parent and grandparent member functions

2001-06-20 Thread Lenar Lõhmus

Hello,

I hit a wall. No offense, but this OO stuff in PHP is somehat weird, but
skip to the problem.
I have for example three classes:

class a {
function make() {
// some code
}
}

class b extends a {
function make() {
// some code
parent::make();
}
}

class c extends b {
function make() {
// some code
parent::make();
}
}

now the class 'c' is instantiated and the member function 'make' is called.
All works up to the point where 'b'::make calls parent::make().
It seems to call itself :(. I can understand this is logical behaviour since
it's still an instance of class c,
so parent:: is still b::, but how should I call that grandparent's make()???
This doesn't seem like a good OOP.
For example delphi's 'inherited' works relative to the class it's used in
and it is way more useful than php's way.

is there any elegant soultion(s) to my problem?

Lenar Lõhmus