php-general Digest 11 Dec 2008 14:57:01 -0000 Issue 5839
Topics (messages 284450 through 284475):
Re: converting a vid with ffmpeg - howto do progress bars?
284450 by: Rene Veerman
284454 by: German Geek
284456 by: Rene Veerman
284457 by: German Geek
Re: Can GD make a JPG thumbnail of a PDF?
284451 by: Stephen Johnson
284452 by: Tim | iHostNZ
284453 by: German Geek
Re: how to not show login info in the url ...what am I looking for?
284455 by: Stut
Re: array_intersect question
284458 by: German Geek
Re: usort for sorting an array of objects
284459 by: Robert Cummings
Need help on MySQL query
284460 by: Rahat Bashir
284461 by: German Geek
284462 by: Andrew Ballard
284463 by: Carlos Medina
284465 by: clive
Re: Dates and Mysql
284464 by: Kevin Waterson
Variable name for constants?
284466 by: Anders Norrbring
284467 by: clive
284468 by: clive
284469 by: Sándor Tamás (HostWare Kft.)
284470 by: Anders Norrbring
284471 by: Anders Norrbring
PECL JSON package
284472 by: Phil Ewington - iModel
284473 by: Phil Ewington - iModel
284474 by: Eric Butera
Poll of Sorts: Application Frameworks--Zend, Cake etc
284475 by: Terion Miller
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
Colin Guthrie wrote:
'Twas brillig, and Rene Veerman at 10/12/08 23:03 did gyre and gimble:
Well, nowhere can i find the frame count being printed, but there
_is_ a duration: hh:mm:ss:ms field outputted, and the updating line
displays a time=seconds.ms (the time in the movie where the encoder
is at).
The question remains how to get at that updating output, with exec()
you get the output after it's done completely.
And there's no way to do partial conversions with ffmpeg, it's all in
one or nothing..
IIRC you can use popen and just read the output into PHP.
http://uk.php.net/manual/en/function.popen.php
That said, if I were you I'd do this system slightly differently. I'd
do the submissions via the web, but then do the encoding as a kind of
daemon process/cron job that runs on the server. This cron job would
do the encoding and update a db table periodically with progress. That
way you can have a page the user goes to that sees their "job progress".
This way the user's browser will not time out and you wont use up
apache connections waiting for encodings and also you wont kill your
server by performing multiple encodes at the same time - with the cron
job/daemon approach you can control how many jobs are performed at the
same time and thus limit the load.
Just some thoughts.
Col
Yep, this is already how it works.. Cron calls a php controller daemon
script (if it aint runnin yet), which reads the various open tasks, and
executes one task step (convert & import a single media file) at a time
for each open task.
It terminates after no more tasks have steps to do.
The scripts executing the task update a status JSON file in the tasks'
working directory, which is the only thing being read by the browser
after it's kicked off the import process by calling the daemon server
with the list of files to import.
i've taken a look at popen() and think i can indeed get it to work with
that..
i'll let you all know in this thread where to view a demo, when it works :)
--- End Message ---
--- Begin Message ---
On Thu, Dec 11, 2008 at 1:53 PM, Rene Veerman <[EMAIL PROTECTED]> wrote:
> Colin Guthrie wrote:
>
>> 'Twas brillig, and Rene Veerman at 10/12/08 23:03 did gyre and gimble:
>>
>>> Well, nowhere can i find the frame count being printed, but there _is_ a
>>> duration: hh:mm:ss:ms field outputted, and the updating line displays a
>>> time=seconds.ms (the time in the movie where the encoder is at).
>>>
>>> The question remains how to get at that updating output, with exec() you
>>> get the output after it's done completely.
>>> And there's no way to do partial conversions with ffmpeg, it's all in one
>>> or nothing..
>>>
>>
>> IIRC you can use popen and just read the output into PHP.
>>
>> http://uk.php.net/manual/en/function.popen.php
>>
>> That said, if I were you I'd do this system slightly differently. I'd do
>> the submissions via the web, but then do the encoding as a kind of daemon
>> process/cron job that runs on the server. This cron job would do the
>> encoding and update a db table periodically with progress. That way you can
>> have a page the user goes to that sees their "job progress".
>>
>> This way the user's browser will not time out and you wont use up apache
>> connections waiting for encodings and also you wont kill your server by
>> performing multiple encodes at the same time - with the cron job/daemon
>> approach you can control how many jobs are performed at the same time and
>> thus limit the load.
>>
>> Just some thoughts.
>>
>> Col
>>
>>
> Yep, this is already how it works.. Cron calls a php controller daemon
> script (if it aint runnin yet), which reads the various open tasks, and
> executes one task step (convert & import a single media file) at a time for
> each open task.
> It terminates after no more tasks have steps to do.
> The scripts executing the task update a status JSON file in the tasks'
> working directory, which is the only thing being read by the browser after
> it's kicked off the import process by calling the daemon server with the
> list of files to import.
>
> i've taken a look at popen() and think i can indeed get it to work with
> that..
> i'll let you all know in this thread where to view a demo, when it works :)
>
Cool, would like to see it in action.
In case you haven't thought of this and it's relevant:
If ffmpeg is writing out a file and you can estimate the final size, you
could check the file size, if it's growing that is, and compare it to the
estimated final size to show the progress. Maybe not the best solution but
if there is nothing else.
If you don't mind, i would like to know some good parameters for ffmpeg to
convert video files to flv format. Might use it in the future.
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Tim-Hinnerk Heuer
http://www.ihostnz.com
--- End Message ---
--- Begin Message ---
German Geek wrote:
On Thu, Dec 11, 2008 at 1:53 PM, Rene Veerman <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>> wrote:
Colin Guthrie wrote:
'Twas brillig, and Rene Veerman at 10/12/08 23:03 did gyre and
gimble:
Well, nowhere can i find the frame count being printed,
but there _is_ a duration: hh:mm:ss:ms field outputted,
and the updating line displays a time=seconds.ms
<http://seconds.ms> (the time in the movie where the
encoder is at).
The question remains how to get at that updating output,
with exec() you get the output after it's done completely.
And there's no way to do partial conversions with ffmpeg,
it's all in one or nothing..
IIRC you can use popen and just read the output into PHP.
http://uk.php.net/manual/en/function.popen.php
That said, if I were you I'd do this system slightly
differently. I'd do the submissions via the web, but then do
the encoding as a kind of daemon process/cron job that runs on
the server. This cron job would do the encoding and update a
db table periodically with progress. That way you can have a
page the user goes to that sees their "job progress".
This way the user's browser will not time out and you wont use
up apache connections waiting for encodings and also you wont
kill your server by performing multiple encodes at the same
time - with the cron job/daemon approach you can control how
many jobs are performed at the same time and thus limit the load.
Just some thoughts.
Col
Yep, this is already how it works.. Cron calls a php controller
daemon script (if it aint runnin yet), which reads the various
open tasks, and executes one task step (convert & import a single
media file) at a time for each open task.
It terminates after no more tasks have steps to do.
The scripts executing the task update a status JSON file in the
tasks' working directory, which is the only thing being read by
the browser after it's kicked off the import process by calling
the daemon server with the list of files to import.
i've taken a look at popen() and think i can indeed get it to work
with that..
i'll let you all know in this thread where to view a demo, when it
works :)
Cool, would like to see it in action.
In case you haven't thought of this and it's relevant:
If ffmpeg is writing out a file and you can estimate the final size,
you could check the file size, if it's growing that is, and compare it
to the estimated final size to show the progress. Maybe not the best
solution but if there is nothing else.
i've thought of it, and considered it too random to even try to estimate ;)
If you don't mind, i would like to know some good parameters for
ffmpeg to convert video files to flv format. Might use it in the future.
$cmd = 'nice -n 19 ffmpeg -i "'.$sourcePath.'" -b 5000000 -acodec
mp3 -ab 192 -ar 22050 -y "'.$destination.'"';
that's what i'm using now. it spits out files larger than the divx
originals that i'm using for testing purposes.
-b <number> is used to set the quality and size of the output flv
usefull too;
http://www.catswhocode.com/blog/19-ffmpeg-commands-for-all-needs
--- End Message ---
--- Begin Message ---
On Thu, Dec 11, 2008 at 2:27 PM, Rene Veerman <[EMAIL PROTECTED]> wrote:
> German Geek wrote:
>
>> On Thu, Dec 11, 2008 at 1:53 PM, Rene Veerman <[EMAIL PROTECTED]<mailto:
>> [EMAIL PROTECTED]>> wrote:
>>
>> Colin Guthrie wrote:
>>
>> 'Twas brillig, and Rene Veerman at 10/12/08 23:03 did gyre and
>> gimble:
>>
>> Well, nowhere can i find the frame count being printed,
>> but there _is_ a duration: hh:mm:ss:ms field outputted,
>> and the updating line displays a time=seconds.ms
>> <http://seconds.ms> (the time in the movie where the
>>
>> encoder is at).
>>
>> The question remains how to get at that updating output,
>> with exec() you get the output after it's done completely.
>> And there's no way to do partial conversions with ffmpeg,
>> it's all in one or nothing..
>>
>>
>> IIRC you can use popen and just read the output into PHP.
>>
>> http://uk.php.net/manual/en/function.popen.php
>>
>> That said, if I were you I'd do this system slightly
>> differently. I'd do the submissions via the web, but then do
>> the encoding as a kind of daemon process/cron job that runs on
>> the server. This cron job would do the encoding and update a
>> db table periodically with progress. That way you can have a
>> page the user goes to that sees their "job progress".
>>
>> This way the user's browser will not time out and you wont use
>> up apache connections waiting for encodings and also you wont
>> kill your server by performing multiple encodes at the same
>> time - with the cron job/daemon approach you can control how
>> many jobs are performed at the same time and thus limit the load.
>>
>> Just some thoughts.
>>
>> Col
>>
>>
>> Yep, this is already how it works.. Cron calls a php controller
>> daemon script (if it aint runnin yet), which reads the various
>> open tasks, and executes one task step (convert & import a single
>> media file) at a time for each open task.
>> It terminates after no more tasks have steps to do.
>> The scripts executing the task update a status JSON file in the
>> tasks' working directory, which is the only thing being read by
>> the browser after it's kicked off the import process by calling
>> the daemon server with the list of files to import.
>>
>> i've taken a look at popen() and think i can indeed get it to work
>> with that..
>> i'll let you all know in this thread where to view a demo, when it
>> works :)
>>
>>
>> Cool, would like to see it in action.
>> In case you haven't thought of this and it's relevant:
>> If ffmpeg is writing out a file and you can estimate the final size, you
>> could check the file size, if it's growing that is, and compare it to the
>> estimated final size to show the progress. Maybe not the best solution but
>> if there is nothing else.
>>
>> i've thought of it, and considered it too random to even try to estimate
> ;)
OK. So you have tried converting a couple of vids and the resulting file
size is always random? Surely there must be some kind of relation to the
input file size, the transcode parameters and the output file size. Of
course it also depends on the nature of the video but you could also take
into account the file size and the time it took to get to that file size
(during the process) in relation to the input file size.
>
> If you don't mind, i would like to know some good parameters for ffmpeg to
>> convert video files to flv format. Might use it in the future.
>>
>>
>
> $cmd = 'nice -n 19 ffmpeg -i "'.$sourcePath.'" -b 5000000 -acodec mp3 -ab
> 192 -ar 22050 -y "'.$destination.'"';
>
> that's what i'm using now. it spits out files larger than the divx
> originals that i'm using for testing purposes.
> -b <number> is used to set the quality and size of the output flv
>
> usefull too;
> http://www.catswhocode.com/blog/19-ffmpeg-commands-for-all-needs
Thanks.
--
Tim-Hinnerk Heuer
http://www.ihostnz.com
--- End Message ---
--- Begin Message ---
I think you want something like this :
exec("convert -density 360x360 -enhance $pdfFile $pdfFile.gif");
On 12/10/08 4:48 PM, "Brian Dunning" <[EMAIL PROTECTED]> wrote:
> I've spent most of the last week trying to get ImageMagick working on
> my Windows PHP installation. I gather that since I'm going to be
> converting PDFs to JPEGs, I need Ghostscript.
>
> Well, I've got ImageMagick installed: http://printhq2.com/info.php
> I ran a Ghostscript installer, but it didn't seem to do very much.
>
> Some site advised me to test my installation like this:
> <?php
> echo "<pre>";
> system("convert -version");
> echo "</pre>";
> ?>
> But it just returns blank. Can anyone help me get ImageMagick working
> on my server?
>
>
> On Nov 20, 2008, at 4:41 PM, Stephen Johnson wrote:
>
>> No but you can use imagemagicks convert to convert the pdf to an
>> image and
>> then make a thumbnail of it.
>
--
Stephen Johnson
The Lone Coder
http://www.ouradoptionblog.com
*Join us on our adoption journey*
[EMAIL PROTECTED]
http://www.thelonecoder.com
*Continuing the struggle against bad code*
--
--- End Message ---
--- Begin Message ---
On Thu, Dec 11, 2008 at 1:59 PM, Stephen Johnson <[EMAIL PROTECTED]
> wrote:
> I think you want something like this :
> exec("convert -density 360x360 -enhance $pdfFile $pdfFile.gif");
Yes, that's how i did it here. Didn't find a better solution yet. Was
looking at the php module for imagemagick (imagick i believe), but that
seemed not quite there yet for deployment. Please advise if someone got that
working. Would prefer this over a shellexecute. You will need to install
imagemagick and i believe you also need ghostscript for this to work. You
can get both for linux and windows, free.
On debian and ubuntu and such:
apt-get install imagemagick gs
>
>
>
> On 12/10/08 4:48 PM, "Brian Dunning" <[EMAIL PROTECTED]> wrote:
>
> > I've spent most of the last week trying to get ImageMagick working on
> > my Windows PHP installation. I gather that since I'm going to be
> > converting PDFs to JPEGs, I need Ghostscript.
> >
> > Well, I've got ImageMagick installed: http://printhq2.com/info.php
> > I ran a Ghostscript installer, but it didn't seem to do very much.
> >
> > Some site advised me to test my installation like this:
> > <?php
> > echo "<pre>";
> > system("convert -version");
> > echo "</pre>";
> > ?>
> > But it just returns blank. Can anyone help me get ImageMagick working
> > on my server?
> >
> >
> > On Nov 20, 2008, at 4:41 PM, Stephen Johnson wrote:
> >
> >> No but you can use imagemagicks convert to convert the pdf to an
> >> image and
> >> then make a thumbnail of it.
> >
>
> --
> Stephen Johnson
> The Lone Coder
>
> http://www.ouradoptionblog.com
> *Join us on our adoption journey*
>
> [EMAIL PROTECTED]
> http://www.thelonecoder.com
>
> *Continuing the struggle against bad code*
> --
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Tim-Hinnerk Heuer
http://www.ihostnz.com
--- End Message ---
--- Begin Message ---
On Thu, Dec 11, 2008 at 1:59 PM, Stephen Johnson <[EMAIL PROTECTED]
> wrote:
> I think you want something like this :
> exec("convert -density 360x360 -enhance $pdfFile $pdfFile.gif");
>
Yes, that's how i did it here. Didn't find a better solution yet. Was
looking at the php module for imagemagick (imagick i believe), but that
seemed not quite there yet for deployment. Please advise if someone got that
working. Would prefer this over a shellexecute. You will need to install
imagemagick and i believe you also need ghostscript for this to work. You
can get both for linux and windows, free.
On debian and ubuntu and such:
apt-get install imagemagick gs
>
> On 12/10/08 4:48 PM, "Brian Dunning" <[EMAIL PROTECTED]> wrote:
>
> > I've spent most of the last week trying to get ImageMagick working on
> > my Windows PHP installation. I gather that since I'm going to be
> > converting PDFs to JPEGs, I need Ghostscript.
> >
> > Well, I've got ImageMagick installed: http://printhq2.com/info.php
> > I ran a Ghostscript installer, but it didn't seem to do very much.
> >
> > Some site advised me to test my installation like this:
> > <?php
> > echo "<pre>";
> > system("convert -version");
> > echo "</pre>";
> > ?>
> > But it just returns blank. Can anyone help me get ImageMagick working
> > on my server?
> >
> >
> > On Nov 20, 2008, at 4:41 PM, Stephen Johnson wrote:
> >
> >> No but you can use imagemagicks convert to convert the pdf to an
> >> image and
> >> then make a thumbnail of it.
> >
>
> --
> Stephen Johnson
> The Lone Coder
>
> http://www.ouradoptionblog.com
> *Join us on our adoption journey*
>
> [EMAIL PROTECTED]
> http://www.thelonecoder.com
>
> *Continuing the struggle against bad code*
> --
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Tim-Hinnerk Heuer
http://www.ihostnz.com
--- End Message ---
--- Begin Message ---
Please keep the discussion on the list, or offer me a contract.
On 10 Dec 2008, at 14:29, Terion Miller wrote:
On Tue, Dec 9, 2008 at 4:03 PM, Stut <[EMAIL PROTECTED]> wrote:
On 9 Dec 2008, at 21:54, Terion Miller wrote:
On Tue, Dec 9, 2008 at 3:49 PM, Stut <[EMAIL PROTECTED]> wrote:
On 9 Dec 2008, at 21:41, Terion Miller wrote:
So I have this login information passing parameters in the url to
the next
page (this is on a intranet app) which I thought was no big deal
until a
wise crack graphics guy decided to hack it because he could by
changing the
?adminID= until he got one that worked...he didn't do anything
except alert
my boss so now I have to hide this info how does one do this? Once
again I
am not a programmer just inherited the job....and the code...
Here is the login page code:
<?php
if (isset($_POST['UserName'])) {$UserName = $_POST['UserName'];} else
{$UserName = '';}
if (isset($_POST['Password'])) {$Password = $_POST['Password'];} else
{$Password = '';}
$msg = '';
if (!empty($UserName)) {
$sql = "SELECT * FROM admin WHERE UserName='$UserName' and
Password='$Password'";
$result = mysql_query ($sql);
$row = mysql_fetch_object ($result);
If (mysql_num_rows($result) > 0) {
$_SESSION['AdminLogin'] = "OK";
header ("Location: Main.php?AdminID=". $row->AdminID);
} else {
$msg = "Invalid Login";
}
}
?>
No need to pass AdminID in the URL at all. Store that ID in the
AdminLogin session variable instead of "OK" and you can get it from
there on every subsequent page.
-Stut
--
http://stut.net/
How do I do that....I see where...but not getting how:
If (mysql_num_rows($result) > 0) {
$_SESSION['AdminLogin'] = "AdminID"; //<----thats where is
said "ok" before
header ("Location: Main.php?AdminID=". $row->AdminID); <----
not sure what to do here?
} else {
$msg = "Invalid Login";
}
Nope.
If (mysql_num_rows($result) > 0) {
$_SESSION['AdminLogin'] = $row->AdminID;
header ("Location: Main.php");
} else {
$msg = "Invalid Login";
}
But you then need to edit Main.php to change where it gets the
AdminID value from. Chances are it's coming from $_GET['AdminID'],
and simply needs changing to $_SESSION['AdminLogin'], but you need
to make sure session_start() has been called before you try to use it.
Worth noting that securing PHP scripts is not something that should
be approached lightly. If you really don't know what you're doing
you could make it even less secure than it already is, or at the
very least break it so it no longer does what it's supposed to.
Posting snippets of code for us to "fix" as and when you have
problems is not the way to do it and is fairly likely to lead to
more serious problems in the long run. If you need a PHP
developer... hire one!
-Stut
--
http://stut.net/
Ok here is the main.php page and from what little I know and can
tell the fact that he (last coder) is passing the adminID in the url
is not at all needed..right? It seems to be using sessions already...
<?php
include("inc/dbconn_open.php");
if (empty($_SESSION['AdminLogin']) OR $_SESSION['AdminLogin'] <>
'OK' ){
header ("Location: LogOut.php");
}
if (isset($_GET['AdminID']) && !empty($_GET['AdminID'])){
$AdminID = $_GET['AdminID'];
} else {
header ("Location: LogOut.php");
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Work Order System - Administrative Section</title>
</head>
<frameset cols="200,*" frameborder="NO" border="0" framespacing="0">
<frame src="Menu.php?AdminID=<?php echo $AdminID; ?>"
name="leftFrame" scrolling="auto" noresize>
<frame src="Welcome.php?AdminID=<?php echo $AdminID; ?>"
name="mainFrame">
</frameset>
<noframes><body>
</body></noframes>
</html>
That script doesn't use it except to pass it through to Menu.php and
Welcome.php.
-Stut
--
http://stut.net/
--- End Message ---
--- Begin Message ---
On Tue, Dec 2, 2008 at 11:06 PM, Andrej Kastrin <[EMAIL PROTECTED]>wrote:
> It works like a charm.
>
> Thanks, Andrej
>
> Tim | iHostNZ wrote:
>
>> I know there must be a more elegant way with array_reduce or something,
>> but
>> I would simply write a function called
>>
>> function array_intersect_m($m_array) {
>> $intersection = $m_array[0];
>> for ($i=1; $i < count($m_array); $i++) {
>> $intersection = array_intersect($m_array[$i], $intersection);
>> }
>> return $intersection;
>> }
>>
>> and put that into my library. O and while i'm at it, the array_reduce way
>> would prob be:
>> $m_array =
>> array(array("green","red","blue"),array("green","yellow","red"),array("green","red","purple"),array("green","red","yellow"));
>> array_reduce($m_array, 'array_intersect');
>>
>
I tried this now with array_reduce and it didn't work as i expected. Can
anyone tell me why?
It says argument #1 to array_intersect is not an array, although i have an
array of arrays. Also tried providing $arrayOfArrays[0] as the third
parameter to array_reduce which had the same error.
Thanks,
Tim
--- End Message ---
--- Begin Message ---
On Thu, 2008-12-11 at 11:44 +1300, German Geek wrote:
> On Thu, Dec 11, 2008 at 6:43 AM, Robert Cummings <[EMAIL PROTECTED]>wrote:
>
> > On Thu, 2008-12-11 at 01:31 +1300, German Geek wrote:
> > > On Wed, Dec 10, 2008 at 10:27 PM, Stut <[EMAIL PROTECTED]> wrote:
> > >
> > > > On 10 Dec 2008, at 04:15, German Geek wrote:
> > > >
> > > >> I need to sort an array of objects. I found this ( at a url that didnt
> > let
> > > >> me send this msg... ) and I would know how to do it, but I believe
> > there
> > > >> might be a cleaner, more elegant way to do it. In Java, you just need
> > to
> > > >> implement the interface Comparable and provide a method called
> > compareTo
> > > >> (as
> > > >> far as i remember) and then you can use one of the many sorting
> > algorithms
> > > >> generically on objects that are comparable...
> > > >>
> > > >> Anyway, I didn't find something like that for PHP. Since I'm using
> > > >> symfony,
> > > >> I had a bit of a play with the objects at hand and simply did a
> > > >> sort($arrayOfObjects) and it did sort them by the id. Just wondering
> > where
> > > >> it got the information on what to sort on (not quite) correctly for my
> > > >> case?
> > > >>
> > > >
> > > > I'm confused. The function you need is the one you mention in the
> > subject.
> > > > All you need to do is create a function that compares two of the
> > objects, in
> > > > whatever way you need it to, and returns -1, 0 or 1. The pass that to
> > the
> > > > usort function - it doesn't care what type of thing is in the array.
> > Full
> > > > details available at http://php.net/usort.
> > >
> > >
> > >
> > > I just ment to say it would be nice to have it like in Java or C# where
> > you
> > > can implement an interface, called Comparable and define a function in
> > the
> > > class called compareTo which returns an integer smaller, equal or greater
> > > than 0 by which elements can generically be sorted by in a collection.
> > Since
> > > PHP has arrays (hash maps) as the primary collection type, and they are
> > very
> > > good for storing sets or other collections, it would be nice to have a
> > sort
> > > function that would look, if the elements of the array have a compareTo
> > > method (implement the Comparable interface), and if they do, then sort
> > with
> > > that. I find it a bit surprising that such a well designed programming
> > > language doesn't have such a useful feature. I guess one could use one of
> > > the gazillion libraries out there to do the same thing. Also, one could
> > > argue that this further checking would slow down functions that are
> > > primarily used for sorting strings. However, the answer could be also in
> > the
> > > ArrayObject class which is in php natively. Only it should implement all
> > the
> > > array functions that are there anyway, which shouldnt be too hard to do
> > for
> > > the PHP PL developers. Some more in depth documentation of that class
> > would
> > > also be helpful.
> > >
> > > Anyway, I found a not perfect, but good enough solution:
> > >
> > > Implement a static compare function in the class of the object and put a
> > > function in my library, that is simply called myTools::sort that will get
> > > the object class of the first element of the array (if there is one) and
> > > sort according to the compare method implemented in that class (if it
> > > exists), otherwise just use sort. The compare method takes the parameters
> > as
> > > self:
> > >
> > > public class AClass { // implements Comparable {
> > > public static function compare(self $obj1, self $obj2) {
> > > return strcmp($obj1->prop1, $obj2->prop1); // e.g.
> > > }
> > > }
> > >
> > > That way I will get an exception if there is an object in the array which
> > > does not have that class, but i can live with that. At least i'll get an
> > > exception and not another funny error, because the parameters are self,
> > > right?
> > >
> > > It might be better to define an interface called Comparable with that
> > > method, but was not really necessary for my case.
> > >
> > > Just a few thoughts to maybe improve PHP in the future. Hopefully there
> > will
> > > be a lot of interfaces and objects for collection types at some stage in
> > PHP
> > > natively, although that might clutter the namespace and could be realised
> > > with libraries. What are your thoughts?
> >
> > You can already do what you want. Implement it yourself. Not everyone
> > wants this level of cruft and inefficiency.
>
>
> Inefficiency for me is when it takes longer to code. For one second of
> coding time I can waste 1000ms of processing time without any cost. Think
> about what a computer can do in 1000ms. Calling a function generically takes
> next to nothing in processing time (maybe 0.5ms or less. In fact some db
> queries take less than that in my experience...
Regardless of your personal implementation preferences, PHP offers a
sorting mechanism, it's up to you to massage it into your personal
paradigm of the day.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
Hi Experts,
EID Mubarak to all.
I need your help on writing a MySQL query.
Scenario:
CREATE TABLE transaction
(
`id` int NOT NULL ATUTO INCREMENT,
`date` datetime NOT NULL,
`withdrawn` double (12,2) NULL,
`deposit` double (12,2) NULL
);
SELECT * FROM transaction;
id date
withdrawn deposit
----- -----------------------------
--------------- --------------
1 2008-12-01 00:00:00
NULL 10000.00
2 2008-12-02 00:00:00 4000.00
NULL
3 2008-12-04 00:00:00 2000.00
NULL
4 2008-12-05 00:00:00
NULL 4500.00
5 2008-12-06 00:00:00 500.00
1500.00
The above is all I have. I want to make query which should output an extra
calculated column named "balance", something like following:
Expected output from query:
id date
withdrawn deposit balance
----- -----------------------------
--------------- -------------- -------------
1 2008-12-01 00:00:00
NULL 10000.00 10000.00
2 2008-12-02 00:00:00 4000.00
NULL 6000.00
3 2008-12-04 00:00:00 2000.00
NULL 4000.00
4 2008-12-05 00:00:00
NULL 4500.00 8500.00
5 2008-12-06 00:00:00 500.00
1500.00 9500.00
Thanks in advance
--
Rahat Bashir
Dhaka, Bangladesh
--- End Message ---
--- Begin Message ---
On Thu, Dec 11, 2008 at 4:52 PM, Rahat Bashir <[EMAIL PROTECTED]>wrote:
> Hi Experts,
>
> EID Mubarak to all.
>
> I need your help on writing a MySQL query.
>
> Scenario:
>
> CREATE TABLE transaction
> (
> `id` int NOT NULL ATUTO INCREMENT,
> `date` datetime NOT NULL,
> `withdrawn` double (12,2) NULL,
> `deposit` double (12,2) NULL
> );
>
> SELECT * FROM transaction;
SELECT *, deposit-withdrawn AS balance FROM transaction
Although i would suggest a transaction table to only have positive and
negative balances. Then you can do all sorts of things with it like get the
sum of all transactions a lot easier etc.
e.g.
SELECT SUM(balance) AS user_balance FROM transaction WHERE user_id=1
if you have a user id e.g. Are you working for a bank? :-)
>
>
> id date
> withdrawn deposit
> ----- -----------------------------
> --------------- --------------
> 1 2008-12-01 00:00:00
> NULL 10000.00
> 2 2008-12-02 00:00:00 4000.00
> NULL
> 3 2008-12-04 00:00:00 2000.00
> NULL
> 4 2008-12-05 00:00:00
> NULL 4500.00
> 5 2008-12-06 00:00:00 500.00
> 1500.00
>
> The above is all I have. I want to make query which should output an extra
> calculated column named "balance", something like following:
>
> Expected output from query:
> id date
> withdrawn deposit balance
> ----- -----------------------------
> --------------- -------------- -------------
> 1 2008-12-01 00:00:00
> NULL 10000.00 10000.00
> 2 2008-12-02 00:00:00 4000.00
> NULL 6000.00
> 3 2008-12-04 00:00:00 2000.00
> NULL 4000.00
> 4 2008-12-05 00:00:00
> NULL 4500.00 8500.00
> 5 2008-12-06 00:00:00 500.00
> 1500.00 9500.00
>
> Thanks in advance
>
>
> --
> Rahat Bashir
> Dhaka, Bangladesh
>
--- End Message ---
--- Begin Message ---
On Wed, Dec 10, 2008 at 10:52 PM, Rahat Bashir <[EMAIL PROTECTED]> wrote:
> Hi Experts,
>
> EID Mubarak to all.
>
> I need your help on writing a MySQL query.
>
> Scenario:
>
> CREATE TABLE transaction
> (
> `id` int NOT NULL ATUTO INCREMENT,
> `date` datetime NOT NULL,
> `withdrawn` double (12,2) NULL,
> `deposit` double (12,2) NULL
> );
>
> SELECT * FROM transaction;
>
> id date
> withdrawn deposit
> ----- -----------------------------
> --------------- --------------
> 1 2008-12-01 00:00:00
> NULL 10000.00
> 2 2008-12-02 00:00:00 4000.00
> NULL
> 3 2008-12-04 00:00:00 2000.00
> NULL
> 4 2008-12-05 00:00:00
> NULL 4500.00
> 5 2008-12-06 00:00:00 500.00
> 1500.00
>
> The above is all I have. I want to make query which should output an extra
> calculated column named "balance", something like following:
>
> Expected output from query:
> id date
> withdrawn deposit balance
> ----- -----------------------------
> --------------- -------------- -------------
> 1 2008-12-01 00:00:00
> NULL 10000.00 10000.00
> 2 2008-12-02 00:00:00 4000.00
> NULL 6000.00
> 3 2008-12-04 00:00:00 2000.00
> NULL 4000.00
> 4 2008-12-05 00:00:00
> NULL 4500.00 8500.00
> 5 2008-12-06 00:00:00 500.00
> 1500.00 9500.00
>
> Thanks in advance
>
>
> --
> Rahat Bashir
> Dhaka, Bangladesh
>
I would do the running sum in PHP rather than SQL. If your database
doesn't have an operator to perform running totals, it is possible but
the result usually involves correlated subqueries that usually result
in expensive triangular joins. (I think MySQL might have something
that will work, but I haven't tried it. STW for MySQL and running sum
and you'll find some discussion that should get you going.)
If you decide to do the calculation in SQL, you should modify your
table definition slightly:
CREATE TABLE transaction
(
`id` int NOT NULL AUTO INCREMENT,
`date` datetime NOT NULL,
`withdrawn` double (12,2) NOT NULL DEFAULT 0.0,
`deposit` double (12,2) NOT NULL DEFAULT 0.0
);
The value of `withdrawn` and `deposit` should never be NULL. The value
of NULL in SQL is essentially an UNKNOWN/MISSING value. That's why SQL
calculations that involve NULL yield a NULL value. With the example
you posted, it would be like saying "When I went to the bank December
1, I deposited 10000.00 but I don't know how much I withdrew." What
would you say the net value of such a transaction would be? In your
database, neither `withdrawn` nor `deposit` should be UNKNOWN/MISSING.
(At least I would hope not!)
Andrew
--- End Message ---
--- Begin Message ---
Rahat Bashir schrieb:
Hi Experts,
EID Mubarak to all.
I need your help on writing a MySQL query.
Scenario:
CREATE TABLE transaction
(
`id` int NOT NULL ATUTO INCREMENT,
`date` datetime NOT NULL,
`withdrawn` double (12,2) NULL,
`deposit` double (12,2) NULL
);
SELECT * FROM transaction;
id date
withdrawn deposit
----- -----------------------------
--------------- --------------
1 2008-12-01 00:00:00
NULL 10000.00
2 2008-12-02 00:00:00 4000.00
NULL
3 2008-12-04 00:00:00 2000.00
NULL
4 2008-12-05 00:00:00
NULL 4500.00
5 2008-12-06 00:00:00 500.00
1500.00
The above is all I have. I want to make query which should output an extra
calculated column named "balance", something like following:
Expected output from query:
id date
withdrawn deposit balance
----- -----------------------------
--------------- -------------- -------------
1 2008-12-01 00:00:00
NULL 10000.00 10000.00
2 2008-12-02 00:00:00 4000.00
NULL 6000.00
3 2008-12-04 00:00:00 2000.00
NULL 4000.00
4 2008-12-05 00:00:00
NULL 4500.00 8500.00
5 2008-12-06 00:00:00 500.00
1500.00 9500.00
Thanks in advance
Hi Rahat,
you can see more information about MySQL on www.mysql.com and show how
to build/make Queries well.
Regards
Carlos Medina
--- End Message ---
--- Begin Message ---
Rahat Bashir wrote:
I need your help on writing a MySQL query.
I see nothing php related in your question, try a mysql list.
--- End Message ---
--- Begin Message ---
This one time, at band camp, VamVan <[EMAIL PROTECTED]> wrote:
> I was wondering how is it possible for me to query the table to retrieve all
> the records that are one week less than the time stamp?
SELECT DATE_SUB(date_time_column, INTERVAL 1 WEEK) FROM your_table;
http://www.phpro.org/tutorials/Introduction-to-PHP-and-MySQL.html#45
Kevin
--- End Message ---
--- Begin Message ---
I've been experimenting with having a varaible constant name, but failed
miserably... Can I please have a pointer?
What I'm trying to do is something like this:
$name = "home";
Then read the constant IMG_HOME, like IMG_$name, I'm not sure I make myself
understood, but I hope so..
Anders.
--- End Message ---
--- Begin Message ---
Anders Norrbring wrote:
I've been experimenting with having a varaible constant name, but failed
miserably... Can I please have a pointer?
What I'm trying to do is something like this:
$name = "home";
Then read the constant IMG_HOME, like IMG_$name, I'm not sure I make myself
understood, but I hope so..
Anders.
I dont think you can do that with a constant, but you can do this a
normal variable:
$test = 'the value of test variable';
$var ='test';
echo $$var;
// will echo $test;
Clive
--- End Message ---
--- Begin Message ---
I dont think you can do that with a constant, but you can do this a
normal variable:
I stand under correction form my previous email, it can be done:
define('TEST', 'the value of constant TEST');
$var= 'TEST';
echo constant($var);
--- End Message ---
--- Begin Message ---
... and in that way, you can create the name of the constant as you please:
$VAR_IMG = 'HOME';
define('IMG_HOME', 'pic.jpg');
echo(constant('IMG_'.$VAR_IMG));
SanTa
----- Original Message -----
From: "clive" <[EMAIL PROTECTED]>
To: "PHP LIST" <[EMAIL PROTECTED]>
Sent: Thursday, December 11, 2008 9:18 AM
Subject: Re: [PHP] Variable name for constants?
I dont think you can do that with a constant, but you can do this a
normal variable:
I stand under correction form my previous email, it can be done:
define('TEST', 'the value of constant TEST');
$var= 'TEST';
echo constant($var);
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
> > I dont think you can do that with a constant, but you can do this a
> > normal variable:
> >
>
> I stand under correction form my previous email, it can be done:
>
> define('TEST', 'the value of constant TEST');
>
> $var= 'TEST';
>
> echo constant($var);
This may be too early in the morning for me, but I don't get it.. ;-)
Say I have these definitions;
define("IMG_HOME", "pic1.png");
define("IMG_AWAY", "pic2.png");
define("IMG_ELSE", "pic3.png");
Then a function should present the right image based on a variable
(pseudocode):
function show($name) {
present_img( IMG_$name );
}
If I understand right (probably not...), then I could concat and do like
this?
present_img( constant("IMG_" . $name) );
--- End Message ---
--- Begin Message ---
> ... and in that way, you can create the name of the constant as you
> please:
>
> $VAR_IMG = 'HOME';
> define('IMG_HOME', 'pic.jpg');
> echo(constant('IMG_'.$VAR_IMG));
>
> SanTa
>
> ----- Original Message -----
> From: "clive" <[EMAIL PROTECTED]>
> To: "PHP LIST" <[EMAIL PROTECTED]>
> Sent: Thursday, December 11, 2008 9:18 AM
> Subject: Re: [PHP] Variable name for constants?
>
>
> >
> >> I dont think you can do that with a constant, but you can do this a
> >> normal variable:
> >>
> >
> > I stand under correction form my previous email, it can be done:
> >
> > define('TEST', 'the value of constant TEST');
> >
> > $var= 'TEST';
> >
> > echo constant($var);
> >
Ah.. Seems like I figured it out right then with the hint from Clive.. ;-)
Thanks a lot guys! I'll out this to the test a little later!
Have a great weekend,
Anders.
--- End Message ---
--- Begin Message ---
Hi All,
I have just installed the PECL JSON package, or at least think I have!!
But how do I use it?? I was expecting /usr/share/pear/Services/JSON.php
to be found on my system for include but not so. My system tells me I
have 1.2.1 successfully installed but I cannot find any docs that tell
me how to make use of it. I am running PHP 5.1.6 at present.
TIA
Phil.
--- End Message ---
--- Begin Message ---
Phil Ewington - iModel wrote:
Hi All,
I have just installed the PECL JSON package, or at least think I
have!! But how do I use it?? I was expecting
/usr/share/pear/Services/JSON.php to be found on my system for include
but not so. My system tells me I have 1.2.1 successfully installed but
I cannot find any docs that tell me how to make use of it. I am
running PHP 5.1.6 at present.
TIA
Phil.
OK, seems I am confusing PECL and PEAR. Have now configured extension
using phpize and enabled in php.ini.
- Phil.
--- End Message ---
--- Begin Message ---
On Thu, Dec 11, 2008 at 5:43 AM, Phil Ewington - iModel
<[EMAIL PROTECTED]> wrote:
> Phil Ewington - iModel wrote:
>>
>> Hi All,
>>
>> I have just installed the PECL JSON package, or at least think I have!!
>> But how do I use it?? I was expecting /usr/share/pear/Services/JSON.php to
>> be found on my system for include but not so. My system tells me I have
>> 1.2.1 successfully installed but I cannot find any docs that tell me how to
>> make use of it. I am running PHP 5.1.6 at present.
>>
>> TIA
>>
>> Phil.
>>
> OK, seems I am confusing PECL and PEAR. Have now configured extension using
> phpize and enabled in php.ini.
>
> - Phil.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
If you're using the pecl version, it is json_encode().
If you're using the pear version you say
require_once 'Services/JSON.php';
$json = new Services_JSON();
$output = $json->encode($value);
If you're using php5, you should have json in the build unless it was
disabled for some reason. If you're going to be using it a lot,
you're really going to want the speed of the c version.
--- End Message ---
--- Begin Message ---
Hey Everyone, I am wondering if using a framework such as one of these may
make my life easier, which do any of you use and what has been your
experience with the learning curve of them?
I just put Cake on my local server, basically I want to know which is
easiest? LOL...
Terion
--- End Message ---