RE: [PHP] Re: Storing indefinite arrays in database

2011-05-11 Thread Jasper Mulder


> Date: Wed, 11 May 2011 22:15:21 +0200
> From: benedikt.vo...@web.de
> To: nos...@mckenzies.net
> CC: php-general@lists.php.net
> Subject: Re: [PHP] Re: Storing indefinite arrays in database
>
> Thanks Shawn,
>
> yes, your second idea works for me. The first one not, as I need to
> search and join on it.
> To continue your second idea with your example:
>
> Arguments:
> id results_id variable value
> 1 1 1 800
> 2 1 2 999
> 3 1 3 3.14
>
> Results:
> id result
> 1 50
> 2 99
>
> The Arguments and Results table would be filled dynamically by user content.
> In order to run a function, I have to do N times a join, whereas N is the 
> number of arguments:
>
> select result
> from Results join Arguments as A1 join Arguments as A2 join Arguments as A3
> on Results.id=A1.results_id and
> on Results.id=A2.results_id and
> on Results.id=A3.results_id and
> where
> A1.variable=1 and A1.value=800 and
> A2.variable=2 and A2.value=999 and
> A3.variable=3 and A3.value=3.14 and
> A1.results_id=Results.results_id and
> A2.results_id=Results.results_id and
> A3.results_id=Results.results_id
>
> Theoretically this works, but how good will be the performance if there are 
> Thousands of entries?
> Anyway, I will try out.
> Thanks again,
> Ben
>
Dear Ben,

Firstly, as this is my first post to this list I apologize for any etiquette 
mistakes.

I would like to suggest to you a different approach, which would be more 
dynamical:
First, you would have a table which stores the number of arguments of a certain 
entry, something like

   record_id   num_of_arg

You would store the num_of_arg entry in a PHP variable, say $num.
Then you would proceed to use 

  "CREATE TABLE IF NOT EXISTS \'entries_".$num."\' ...some more code..." 

to create a table which can store precisely $num arguments per record.
Then you add it to that table using standard MySQL.
Effectively this groups all records into tables according to $num.

The only thing here is that you probably need to call the database two times:
 - first to get num_of_arg to be able to call onto the right table
 - second to get the data

But as the number of arguments would go into the thousands, no huge join would 
be necessary.
Only thing is, that you would have very wide tables (I don't know how wide 
MySQL can go).

Creating tables on-the-fly as necessary seems to be something you could 
consider,
but again I stress that I don't know performance details. There might be 
something quicker.

So far for my 2c. Hopefully, it is of some help.

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



RE: [PHP] mysql problems [SOLVED]

2011-05-14 Thread Jasper Mulder

>[SNIP]
> added and else clause.
> while ($_parent != 0)
> {
>   if
> ($num_rows > 0)
>{
>
> perform some action
>}
>else
>{
>  $_parent =
> "0";
>}
> }
>
> and that solved the
> problem.
>
> Thank you, everyone for your help.
>
> Curtis

A small remark:
I think it is good programming practice to place such static if-clauses before 
the while statement.
This prevents a lot of redundant checks and thus saves time.

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



RE: [PHP] A Review Request

2011-05-18 Thread Jasper Mulder

> Joshua's style (Allman) also lines up. I also find tedd's particular
> bracing style disconcerting. I always brace myself for it when I visit
> his site (sorry couldn't resist ;)
>
> I'm also in the Allman camp :)
>
> Cheers,
> Rob.

IMO, the style used by tedd just wastes one tabulation index (the zeroth).
Moreover, since I mostly endow myself with the luxury of Komodo or Eclipse
for finding closing braces, I have been teaching myself nothing but K&R for
the last few years. I like it's efficiency.

To put something useful in this post:
Please correct 
  This Authorization Proceedure
to 
  This authorization procedure
or, if you must,
  This Authorization Procedure
Otherwise I can only encourage such an initiative because it can help out
and save time.

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



[PHP] Need experience with OOPHP

2011-05-20 Thread Jasper Mulder

Just the short week that I have been subscribed to this list, I have
encountered numerous code examples using the new OOPHP. A bit of a
culture shock, but since I also code in Java regularly, no conceptual
difficulties occur.

Only thing is now, that I would like to improve my OOPHP skill by
writing some useful classes; I don't see any possibilities in my current
ensemble of projects and therefore was wondering if anyone had some
small project for me, which I would then try to implement. Preferably, I
would get some response afterwards on where to improve, thus making me a
better programmer. I stress I have quite some experience with the old,
procedural PHP.

Anybody interested?

Best regards,
Jasper Mulder


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



RE: [PHP] Urgent help - Token Generation code!

2011-05-27 Thread Jasper Mulder


> From: lord_fa...@hotmail.com
> To: shreya...@gmail.com
> Subject: RE: [PHP] Urgent help - Token Generation code!
> Date: Sat, 28 May 2011 00:41:02 +0200
>
>
> 
> > Date: Sat, 28 May 2011 03:56:26 +0530
> > From: shreya...@gmail.com
> > To: php-general@lists.php.net
> > Subject: [PHP] Urgent help - Token Generation code!
> >
> > I am re-visiting the world of PHP after a really big hiatus and I am finding
> > things veryslippery. Can someone please help me with the below code and let
> > me know how I can print the token that is getting generated?
> >
> > I am using EasyPHP and I am trying to echo the $token but it wouldn't print
> > anything. I am trying it as : http://localhost/token/URLToken.php. May I
> > know where all I am going wrong here in my approach?
> >
> > >
> > $sUrl = "/tstd_c_b1@s54782";
> > $sParam = "primaryToken";
> > $nTime = time();
> > $nEventDuration = 86400;
> > $nWindow = $nTime + $nEventDuration;
> > $sSalt = "akamai123!";
> > $sExtract = ""; // optional
> >
> >
> > function urlauth_gen_url($sUrl, $sParam, $nWindow,
> > $sSalt, $sExtract, $nTime) {
> >
> >
> >
> > $sToken = urlauth_gen_token($sUrl, $nWindow, $sSalt,
> > $sExtract, $nTime);
> > echo $token;
>
> There are two cases:
> 1. You made a typo and meant 'echo $sToken;' on the above line instead
> 2. You omitted the part where $token is defined and used
>
> > [More code that seemed fine]
> >
> > --
> > Regards,
> > Shreyas Agasthya
>
> Best regards,
> Jasper Mulder
>

I forgot to hit Reply All instead of Reply.
I am deeply sorry for such a careless omission.

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



RE: [PHP] Urgent help - Token Generation code!

2011-05-27 Thread Jasper Mulder


> From: shreya...@gmail.com
> To: lord_fa...@hotmail.com
> Subject: Re: [PHP] Urgent help - Token Generation code!
> Date: Sat, 28 May 2011 04:15:59 +0530
>
> Jasper,
>
> Tried echoing $sToken but wouldn't work.
>
> Regards,
> Shreyas
>
> On 28-May-2011, at 4:11 AM, Jasper Mulder 
> wrote:
>
> >
> > 
> >> Date: Sat, 28 May 2011 03:56:26 +0530
> >> From: shreya...@gmail.com
> >> To: php-general@lists.php.net
> >> Subject: [PHP] Urgent help - Token Generation code!
> >>
> >> I am re-visiting the world of PHP after a really big hiatus and I
> >> am finding
> >> things veryslippery. Can someone please help me with the below code
> >> and let
> >> me know how I can print the token that is getting generated?
> >>
> >> I am using EasyPHP and I am trying to echo the $token but it
> >> wouldn't print
> >> anything. I am trying it as : http://localhost/token/URLToken.php.
> >> May I
> >> know where all I am going wrong here in my approach?
> >>
> >>>
> >> $sUrl = "/tstd_c_b1@s54782";
> >> $sParam = "primaryToken";
> >> $nTime = time();
> >> $nEventDuration = 86400;
> >> $nWindow = $nTime + $nEventDuration;
> >> $sSalt = "akamai123!";
> >> $sExtract = ""; // optional
> >>

As a second try, what happens if you add right here the line

$sGen = urlauth_gen_url($sUrl, $sParam, $nWindow, $sSalt, $sExtract, $nTime);

Because it seems as though you just declare three functions in the code
without calling them...

> >>
> >> function urlauth_gen_url($sUrl, $sParam, $nWindow,
> >> $sSalt, $sExtract, $nTime) {
> >>
> >>
> >>
> >> $sToken = urlauth_gen_token($sUrl, $nWindow, $sSalt,
> >> $sExtract, $nTime);
> >> echo $token;
> >
> > There are two cases:
> > 1. You made a typo and meant 'echo $sToken;' on the above line instead
> > 2. You omitted the part where $token is defined and used
> >
> >> [More code that seemed fine]
> >>
> >> --
> >> Regards,
> >> Shreyas Agasthya
> >

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



RE: [PHP] how to use echo checkboxes in php when i don't have access to $_POST

2011-05-28 Thread Jasper Mulder


> Date: Sat, 28 May 2011 16:39:13 +0430
> From: nickpa...@gmail.com
> To: l...@mit-web.dk
> CC: php-general@lists.php.net
> Subject: Re: [PHP] how to use echo checkboxes in php when i don't have access 
> to $_POST
>
> because when the name is in echo it can't access to $_POST
> 4 example $_POST['p$i']
> it tells me undefined variable p$i
>
> when in html we write it in form because it has post method it can set
> $_POST but here in php i just echo it and i can't access it
> maybe i am wrong but how can i correct it?

In PHP, single quotes do not allow in-line variable substitution.
My guess is that it will work if you use $_POST['p'.$i] or $_POST["p$i"] 
instead.

Further, please mind your punctuation and language use - here I also refer to 
the 
other posts you made. As was stated before, people may be offended and thus it 
makes
the chances of you solving your problem fast smaller.
As a last, please refrain from bombarding the list with small posts. Please 
think a bit
before posting your questions. Thanks in advance.

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



RE: [PHP] phpsadness

2011-06-03 Thread Jasper Mulder

> Stuart Dallas wrote:
> 
> [SNIP]
>
> And this is where we disagree. Everyone is entitled to an opinion, and
> they're also entitled to express that opinion, whether through humour or
> simple statement. 

Somehow in your response I taste that you don't like people, whose opinion 
is that not everybody has the right to express their opinion, expressing
their opinion. Which is an annoying fact about most free speech defenders 
and liberals. 

> [SNIP]
> I repeat that tedd did
> not say anything about the religion, he simply referenced factual events.
> [SNIP]

Whilst you may have a point here, I still think that we should be cautious
with saying what somebody else meant. After all, this is how misconceptions
and rumours are spread every day.

As a last, I must say that I liked this thread better when it considered PHP
only; though being aware that this post has only extended the list by one.
Let us get over it and get back to discussing what we all *do* like: PHP.

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



RE: [PHP] advice on how to build this array from an array.

2011-06-07 Thread Jasper Mulder


> From: a...@blueyonder.co.uk
> Date: Tue, 7 Jun 2011 21:50:27 +0100
> To: php-general@lists.php.net
> Subject: [PHP] advice on how to build this array from an array.
>
> hi all,
>
> please forgive me if i do not make sense, ill try my best to explain.
>
>
> i have this array or arrays.
>
> Array ( [name] => super duplex stainless steels [id] => 30 [page_cat_id] => 
> 10 [main_nav] => true [cat_name] => material range )
> Array ( [name] => standard stainless steels [id] => 31 [page_cat_id] => 10 
> [main_nav] => true [cat_name] => material range )
> Array ( [name] => non ferrous [id] => 32 [page_cat_id] => 10 [main_nav] => 
> true [cat_name] => material range )
> Array ( [name] => carbon based steels [id] => 33 [page_cat_id] => 10 
> [main_nav] => true [cat_name] => material range )
>
> is it possible to build an array and use the [cat_name] as the key and assign 
> all the pages to that cat_name?
>
> what im trying to achieve is a category of pages but i want the cat_name as 
> the key to all the pages associated to it
>
> hope i make sense
>
> kind regards
>
> Adam

Suppose that $arrays is your array of arrays.
Then is 
$res = array();
foreach($arrays as $item){
  $res[$item['cat_name']][] = $item;
}
what you are looking for?

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



RE: [PHP] I want to use POST when redirect via PHP Header function.

2011-06-30 Thread Jasper Mulder

> To: php-general@lists.php.net
> From: jim.gi...@albanyhandball.com
> Date: Thu, 30 Jun 2011 09:12:45 -0400
> Subject: Re: [PHP] I want to use POST when redirect via PHP Header function.
> 
> Just as bottom posting (I know, it's in da rules) makes it rather difficult 
> for humans to read thru a topic, scrolling thru ever-longer messages to get 
> to the 'new' content.
> 
> Let's solve it for all by only posting your own content and let the sum of 
> all the messages equate to the topic.  :)

In fact, the posting rules state that one should only quote those parts of a 
message that are relevant for the post. Unfortunately, many people decide
that everything is relevant, even for a long thread. Still, this should not mean
we have to flee to the opposite of no quoting. You will agree that quoting 
your message above will be clearer than just replying without quote.

Personally, I think that incorrect spelling is far more annoying than
the quoting; that is, if it does not originate from incapability due to English
(whether it be British or American) being not the native language, as
opposed to spelling errors because of vapidity.

As for the readers of this list, I am sorry to go into this non-PHP subject, 
but I couldn't really let this pass.

Best regards,
Jasper
  

RE: [PHP] How to sum monetary variables

2011-07-18 Thread Jasper Mulder

> Date: Mon, 18 Jul 2011 19:00:52 -0300
> From: martin.marq...@gmail.com
> To: php-general@lists.php.net
> Subject: [PHP] How to sum monetary variables
> 
> I'm building a table (which is a report that has to be printed) with a
> bunch of items (up to 300 in some cases) that have unitary price
> (stored in a numeric(9,2) field), how many there are, and the total
> price for each item. At the end of the table there is a total of all
> the items.
> 
> The app is running on PHP and PostgreSQL is the backend.
> 
> The question is, how do I get the total of everything?
> 
> Running it on PHP gives one value, doing a sum() on the backend gives
> another, and I'm starting to notice that even using python as a
> calculator gives me errors (big ones). Right now I'm doing the maths
> by hand to find out who has the biggest error, or if any is 100%
> accurate.
> 
> Any ideas?

According to the postgreSQL docs, there might occur an error as the sum()
 output is coerced to have a 9 digit precision (so at most 999,99 as a 
value), and as this is different from the PHP float interpretation, they might
yield different results in case of overflow. However as python supports
arbitrary integer arithmetic, overflows should not occur.

At the moment, still overflow errors seem the most likely explanation. Does
your table consist of very large values (occasionally perhaps)?

Could you give us an example?

Best regards,
Jasper
  

RE: [PHP] Tree menu list in php

2011-07-26 Thread Jasper Mulder

> From: alekto.antarct...@gmail.com
> Date: Tue, 26 Jul 2011 19:20:58 +0200
> To: php-general@lists.php.net
> Subject: [PHP] Tree menu list in php
> 
> Hi,
> is there a way to create a tree menu list only by using php/html/css?
> I found some, but they are all in JavaScript, do I have to make them by using 
> JavaScript or is there a way in php as well?
> 
> This is how I imagine the tree menu should look like:
> 
> 
> v First level
>> Second level
>> Second level
>v Second level
>   > Third level
>   > Third level
>   > Third level
>   > Second level
>   > Second level
> 
> ( > = menu is closed, v  = menu is open )
> 
> 
> Cheers!
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

This appears like a typical JavaScript thing to me. If you insist on not using 
JS, you could probably use AJAX+PHP to do it.
However, JavaScript appears to me as the more convenient method.

Regards,
Jasper
  

RE: [PHP] pass text variables to next page

2011-08-09 Thread Jasper Mulder

> Date: Tue, 9 Aug 2011 07:30:47 -0500
> From: chrisstinem...@gmail.com
> To: tamouse.li...@gmail.com
> CC: php-general@lists.php.net
> Subject: Re: [PHP] pass text variables to next page
> 
> Thank you Tamara.
> 
> Not sure if I am doing it right. It looks like the last single quote
> is being escaped.
> [SNIP]
> The query:
> 
> $sql = "SELECT store_id, store_subject
>   FROM stores
>   WHERE store_subject = '" . mysql_real_escape_string($_GET['id']."'");
> 
> 
> Thank you,
> 
> Chris
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
The problem is with the mysql_real_escape_string closing parenthesis position, 
instead of
  ($_GET['id']."'");
it should be
  ($_GET['id'])."'";

HTH,
Jasper