php-general Digest 24 Jul 2006 18:33:46 -0000 Issue 4256

Topics (messages 239719 through 239735):

select option and php
        239719 by: weetat
        239723 by: Jay Blanchard

Re: Step by step code running
        239720 by: weetat
        239725 by: Jochem Maas
        239728 by: Mariano Guadagnini
        239729 by: Ryan A
        239730 by: Ryan A

Checking $_POST var and stripping
        239721 by: Chris Grigor
        239722 by: Jay Blanchard

Re: Help with dynamic radio buttons
        239724 by: Dimiter Ivanov

Re: Stumped! 4.x to 5.1 problem!!
        239726 by: markw.mohawksoft.com
        239727 by: Jochem Maas

Comparing Strings
        239731 by: Nils Holland
        239734 by: Adam Zey

database connections
        239732 by: Ryan A
        239733 by: Robert Cummings
        239735 by: Ryan A

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:
        php-general@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
Hi all ,

 I have a code below :

 function goToPageSelect($selectname,$totalItems){

  $_logger = new Log4jLogger();
  $_logger->logdebug("starting ..goToPageSelect()");
  $_logger->logdebug("starting ..goToPageSelect()", $totalItems);

$selecthtml = "Go to Page:<select name=\"$selectname\" class=\"inputfield\" onchange=\"javascript:gotoPage()\">";
  for ($index=0;$index<$totalItems;$index++){
    $value = $value + 1;
    $selecthtml .= "<option value=\"$value\">$value</option>";
  }
  $selecthtml .= "</select>";
  return $selecthtml;
}

It will produce the html tag as shown below:
<script language="JavaScript">
function gotoPage(){

 var urlpath = "../listflag.php?start=&pageID="+3;
 document.forms['listfrm'].method = 'post';
 document.forms['listfrm'].action = urlpath;
 document.forms['listfrm'].submit;

}
</script>

<form name="listfrm">
Go to Page:<select name="pageid" class="inputfield" onchange="javascript:gotoPage()">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select> 
</form>   


I tried using onchange in the select tag,but it did not work. It go to the javascript but the form is not submitted .

Anyideas why?

--- End Message ---
--- Begin Message ---
[snip]
It will produce the html tag as shown below:
<script language="JavaScript">
function gotoPage(){

  var urlpath = "../listflag.php?start=&pageID="+3;
  document.forms['listfrm'].method = 'post';
  document.forms['listfrm'].action = urlpath;
  document.forms['listfrm'].submit;

}
</script>

<form name="listfrm">
Go to Page:<select name="pageid" class="inputfield" 
onchange="javascript:gotoPage()">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>       
</form> 


I tried using onchange in the select tag,but it did not work. It go to 
the javascript but the form is not submitted .

Anyideas why?
[/snip]

In gotoPage() you're not referencing the value of pageid
(document.forms['listfrm'].pageid.value). More of a JavaScript question,
are you a member of a JavaScript list?

--- End Message ---
--- Begin Message ---
Hi Ryan,

  I use Log4jPhp to log any debug value.
  I think it is better than using echo or print method.

Thanks

- weetat

Ryan A wrote:
Hi,

I need to explain a script to a pal of mine but either
i cant explain it properly or he just cant get the
concept being new to php's slightly "advanced stuff"
(OO and classes, mind you...i ain't no expert myself
in this, more like Jochem's(from this list) field of
expertise)

I remember in my old C++ days we used to use something
that basically showed how the code executed, line by
line, running in the loops etc

anything like that for PHP?

Personally I use EditPlus and a lot of echo/print
statements when I debug, I try to keep things simple.

Thanks!

------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

--- End Message ---
--- Begin Message ---
Ryan A wrote:
> Hi,
> 
> I need to explain a script to a pal of mine but either
> i cant explain it properly or he just cant get the
> concept being new to php's slightly "advanced stuff"
> (OO and classes, mind you...i ain't no expert myself
> in this, more like Jochem's(from this list) field of
> expertise)

I'm pretty good at abusing php's OO if thats what you mean ;-)

> 
> I remember in my old C++ days we used to use something
> that basically showed how the code executed, line by
> line, running in the loops etc
> 
> anything like that for PHP?

a debugger would be needed to single step through the code,
although how much help a debugger will be if someone doesn't
understand php's OO principles [very well] is questionable,
generally one has to have a good idea of what the code is meant to
be doing in order to make head/tails of the debuggers output.

maybe we can help in explaining what your script does?

> 
> Personally I use EditPlus and a lot of echo/print
> statements when I debug, I try to keep things simple.
> 
> Thanks!
> 
> ------
> - The faulty interface lies between the chair and the keyboard.
> - Creativity is great, but plagiarism is faster!
> - Smile, everyone loves a moron. :-)
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> 

--- End Message ---
--- Begin Message --- Personally, i think the best one is Zend debugger. It's integrated on the Zend IDE, and let you debug remotely, from a server. The problem aside, is that is paid and closed source, neverthless is the best IMHO.
You may give it a try: www.zend.com/products/zend_studio
HTH,

Mariano.

weetat wrote:
Hi Ryan,

  I use Log4jPhp to log any debug value.
  I think it is better than using echo or print method.

Thanks

- weetat

Ryan A wrote:
Hi,

I need to explain a script to a pal of mine but either
i cant explain it properly or he just cant get the
concept being new to php's slightly "advanced stuff"
(OO and classes, mind you...i ain't no expert myself
in this, more like Jochem's(from this list) field of
expertise)

I remember in my old C++ days we used to use something
that basically showed how the code executed, line by
line, running in the loops etc

anything like that for PHP?

Personally I use EditPlus and a lot of echo/print
statements when I debug, I try to keep things simple.

Thanks!

------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com




--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.10.4/396 - Release Date: 24/07/2006

--- End Message ---
--- Begin Message ---
Hey,


> > I need to explain a script to a pal of mine but
> either
> > i cant explain it properly or he just cant get the
> > concept being new to php's slightly "advanced
> stuff"
> > (OO and classes, mind you...i ain't no expert
> myself
> > in this, more like Jochem's(from this list) field
> of
> > expertise)

 
> I'm pretty good at abusing php's OO if thats what
> you mean ;-)


:) Your name just came  to mind when I thought of OO
as I saw a few of your threads before bitching (no
disrespect meant) about PHP5's OO, and future
compatability 




> a debugger would be needed to single step through
> the code,
> although how much help a debugger will be if someone
> doesn't
> understand php's OO principles [very well] is
> questionable,

Hmmm, I dont think I myself qualify then!

> generally one has to have a good idea of what the
> code is meant to
> be doing in order to make head/tails of the
> debuggers output.

Well, the script runs without a problem, so he can see
what the output is and what it is accomplishing, I
guess he just needs to hit the books a bit harder.
I learnt (brushed up) OO/class programming via an
online PHP site, they had some really good articles,
but just cant remember the site name :(

 
> maybe we can help in explaining what your script
> does?

Trust me, it would take longer for me to write down
the whole thing than actually show the guy's mum and
make her understand!
Writing descriptions for a script is always a PITA.


Cheers!
Ryan

------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--- End Message ---
--- Begin Message ---
Thanks Rob, will check it out!


> You're looking for a debugger. There's a whole
> thread on the go right
> now for "PHP Debugger Recommendations". Personally I
> prefer the
> echo/print_r method that you're probably already
> using... but as you say
> you're trying to demonstrate so that's a bit
> different.
> 
> Cheers,
> Rob.
> -- 
>
.------------------------------------------------------------.
> | InterJinn Application Framework -
> http://www.interjinn.com |
>
:------------------------------------------------------------:
> | An application and templating framework for PHP.
> Boasting  |
> | a powerful, scalable system for accessing system
> services  |
> | such as forms, properties, sessions, and caches.
> InterJinn |
> | also provides an extremely flexible architecture
> for       |
> | creating re-usable components quickly and easily. 
>         |
>
`------------------------------------------------------------'
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--- End Message ---
--- Begin Message ---
Hi

Can anyone help with this ? its checking the $_POST and seeing if any of the
items begin with answer_,
if the do it should remove it from the beginning and place it into
$value_new.. does not seem to work though...



foreach($_POST as $qid => $value) {

$findme = 'answer_';
     if(stripos($value, $findme)) {
         $value_new = ltrim($value);
         print "$value_new<br>";
     }

}

Thanks

Chris

--- End Message ---
--- Begin Message ---
[snip]
Can anyone help with this ? its checking the $_POST and seeing if any of
the
items begin with answer_,
if the do it should remove it from the beginning and place it into
$value_new.. does not seem to work though...

foreach($_POST as $qid => $value) {

$findme = 'answer_';
     if(stripos($value, $findme)) {
         $value_new = ltrim($value);
         print "$value_new<br>";
     }

}
[/snip]

stripos should be strops and would look for a numeric value, not what
you want. You want strstr I believe

foreach($_POST as $qid => $value) {

$findme = 'answer_';
     if(strstr($value, $findme)) {
         $value_new = ltrim($value);
         print "$value_new<br>";
     }

}

--- End Message ---
--- Begin Message ---
On 7/22/06, Chris Grigor <[EMAIL PROTECTED]> wrote:
Afternoon all

I need some help here with a problem on dynamic radio buttons.

I have a script that calls a database for a list of questions. The questions
are returned and each question needs to have 5
radio buttons assigned to it. The radio buttons are a score of 1 - 5 (1
being bad, 5 being good)

For example

1 . How would you rate your vacation?    1 2 3 4 5 <--- those are the radio
buttons.
2. How would you rate your dining at the resort? 1 2 3 4 5


Ok so I have all the questions being returned, I was thinking when creating
the radio buttons as follows

<input name="<?php echo $row_get_question_list['id']?>" type="radio"
value="1" />
<input name="<?php echo $row_get_question_list['id']?>" type="radio"
value="2" />
<input name="<?php echo $row_get_question_list['id']?>" type="radio"
value="3" />
<input name="<?php echo $row_get_question_list['id']?>" type="radio"
value="4" />
<input name="<?php echo $row_get_question_list['id']?>" type="radio"
value="5" />

The input name for each radio group is the questions id from the database.
If there are 50 questions you would have 50 radio button answers submitted.
How are you going to identify the radio buttons being submitted as they are
dynamic? and also I would need to be stored in the
session data as they might want to go back / forward a page.

So basically I need to go through each $_GET item, identify it as a radio
submission and put it into an array.

Has anyone done anything similar before / or can point me in the right
direction??

Kind regards
Chris




You won't get all the radio buttons sumbitted.
You will have only the checked buttons.
So for every question's ID you will have the radio button that was checked.

Just do some testing.
Try echoing the $_POST array after you submit the form.
var_dump($_POST);

--- End Message ---
--- Begin Message ---
[snip]
>
> seems the perceived problem is being caused by something else?
>

Sorry, I have to respectfully disagree.

I was converting all indexes to string indexes, and simply using
"zend_hash_update" to re-constitute the objects and they simply did not
work. When I scanned indexes strings to test for purely numeric content,
and when true, used "zend_hash_index_update" instead, it worked.

This behavior appears different in 5.1.X from 4.x, I can't explain it
100%, but I know that this change fixed the problem I was seeing.

--- End Message ---
--- Begin Message ---
Mark wrote:
> Mark wrote:
> 
>> I have an extension that seems to create PHP variables correctly, and
>> var_dump() doesn't seem to have a problem. but upon moving to 5.1.x it
>> fails.
>>
>> Anyone have a suggestion?
> 
> Well, it is fixed. Evidently, PHP 5.1 sees a difference between $var["0"]
> and $var[0]. It never did before.

a quick test on 5.1.1 shows this not to be the case
(at least at the userland level):

# php -v
PHP 5.1.1 (cli) (built: Jan 18 2006 17:41:38)
Copyright (c) 1997-2005 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2005 Zend Technologies

# php -r '$r = array();$r[0] = "test";var_dump($r[0],$r["0"]);$r["0"] = 
"test2";var_dump($r[0],$r["0"]);'
string(4) "test"
string(4) "test"
string(5) "test2"
string(5) "test2"

seems the perceived problem is being caused by something else?

> 
> BTW: this behavior is almost certainly in wddx.
> 

--- End Message ---
--- Begin Message ---
Hi folks,

well, I have a really dumb question:

I have the following script at http://www.tisys.org/misc/test.php:

<?php
echo $_GET['license'];
?>

Now I call it like this:

http://www.tisys.org/misc/test.php? license=0701770160811371731660412452242420381052542100071831272071031621 17160180165221170166096217228128

And in fact, it echos the whole, long GET-string!

Now i have the following script a tttp://www.tisys.org/misc/ ol_license.php:

<?php
if ($_GET['license'] == "07017701608113717316604124522424203810525421000718312720710316211716018 0165221170166096217228128")
{
    echo '1';
} else {
    echo '0';
}
?>

I launch it like:

http://www.tisys.org/misc/ol_license.php? license=0701770160811371731660412452242420381052542100071831272071031621 17160180165221170166096217228128

And it returns a 1, which means: The strings match. Now I call it like

http://www.tisys.org/misc/ol_license.php? license=1701770160811371731660412452242420381052542100071831272071031621 17160180165221170166096217228128

that is, I have changed the first number of my GET-String from a 0 to a 1 and indeed, the script returns 0, meaning: The scripts don't match. *HOWEVER*, no I call the script like:

http://www.tisys.org/misc/test.php? license=0701770160811371731660412452242420381052542100071831272071031621 17160180165221170166096217228129

that is, I have changed the last number of the GET-String from an 8 to a 9, and interestingly, it returns 1 this time, which means the strings do match, which, however, they don't.

My guess is that PHP only sees / compares the strings up to a certain position. Is this possible? And if so, is there any way around this, so that my whole string is seen?

Greetings and thanks in advance,
Nils

--- End Message ---
--- Begin Message ---
Nils Holland wrote:
Hi folks,

well, I have a really dumb question:

I have the following script at http://www.tisys.org/misc/test.php:

<?php
echo $_GET['license'];
?>

Now I call it like this:

http://www.tisys.org/misc/test.php?license=070177016081137173166041245224242038105254210007183127207103162117160180165221170166096217228128

And in fact, it echos the whole, long GET-string!

Now i have the following script a tttp://www.tisys.org/misc/ol_license.php:

<?php
if ($_GET['license'] == "070177016081137173166041245224242038105254210007183127207103162117160180165221170166096217228128")
{
    echo '1';
} else {
    echo '0';
}
?>

I launch it like:

http://www.tisys.org/misc/ol_license.php?license=070177016081137173166041245224242038105254210007183127207103162117160180165221170166096217228128

And it returns a 1, which means: The strings match. Now I call it like

http://www.tisys.org/misc/ol_license.php?license=170177016081137173166041245224242038105254210007183127207103162117160180165221170166096217228128

that is, I have changed the first number of my GET-String from a 0 to a 1 and indeed, the script returns 0, meaning: The scripts don't match. *HOWEVER*, no I call the script like:

http://www.tisys.org/misc/test.php?license=070177016081137173166041245224242038105254210007183127207103162117160180165221170166096217228129

that is, I have changed the last number of the GET-String from an 8 to a 9, and interestingly, it returns 1 this time, which means the strings do match, which, however, they don't.

My guess is that PHP only sees / compares the strings up to a certain position. Is this possible? And if so, is there any way around this, so that my whole string is seen?

Greetings and thanks in advance,
Nils

Maybe it's interpreting something as a number somewhere. Did you try using === instead of == for your comparisons?

Regards, Adam Zey.

PS: Why is your license key so insanely long, and why doesn't it use alphanumeric characters to reduce the length?
--- End Message ---
--- Begin Message ---
Hi,

This is not really a problem, more like a slightly OT
question.

Recently I have been testing some "CMS/carts/BB
boards" and other related software, sometimes at the
end of the page the software outputs the time it took
to generate the page and the number of database calls.

I have seen some scripts give the number of database
calls in the hundreds (from 100 - 400) just to
generate one single damn page.
Isnt that just too much?

Or am I blowing smoke and MySql can handle that
without a sweat on a shared hosting environment? (with
say....100 page requests per minute?)

Thanks!

------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--- End Message ---
--- Begin Message ---
On Mon, 2006-07-24 at 11:46, Ryan A wrote:
> Hi,
> 
> This is not really a problem, more like a slightly OT
> question.
> 
> Recently I have been testing some "CMS/carts/BB
> boards" and other related software, sometimes at the
> end of the page the software outputs the time it took
> to generate the page and the number of database calls.
> 
> I have seen some scripts give the number of database
> calls in the hundreds (from 100 - 400) just to
> generate one single damn page.
> Isnt that just too much?

It's usually a sign of poor programming and/or purist OOP programming.

When I say purist OOP programming some idiot retrieves X topic IDs from
the database in 1 query, then proceeds to execute X queries in the
constructor of the object to build the actual topic objects, then each
of these stupid constructors then proceed to build their children
objects (replies) which they do by doing a single query that returns Y
children IDs, and then it loops over these and builds the objects via
the constructor which again makes another Y queries, and of course those
stupid objects go and create their children. I saw one really retarded
implementation of this kind of system where an excess of 20000 queries
were issued to the database -- on a homepage nonetheless :/ I think it
was a testament to MySQLs speed that it performed within a reasonable
timeframe (under 3 seconds). Either way, such an application will never
be scalable such that the database server resides on a different
computer than the webserver (even over a LAN).

> Or am I blowing smoke and MySql can handle that
> without a sweat on a shared hosting environment? (with
> say....100 page requests per minute?)

MySQL can probably handle it. But try not to do programming like that
yourself. Stuff like that gives PHP a bad name.

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
Hey Rob,
Thanks for replying.


> It's usually a sign of poor programming and/or
> purist OOP programming.
> 
> When I say purist OOP programming...
> I saw
> one really retarded
> implementation of this kind of system where an
> excess of 20000 queries
> were issued to the database -- on a homepage
> nonetheless :/ 


That IS retarded, I wonder why someone would want to
do that.


> I think it
> was a testament to MySQLs speed that it performed
> within a reasonable
> timeframe (under 3 seconds). 

MySql is a workhorse... def one of my top 3 DBs (I
came into LAMP from Java/Oracle)

I see you have seen some of the apps I was talking
about, even though I have not mentioned any names to
offend anyone.

I was curious about this because I am working on a
project (with other team players) and we have a way of
building something with either lots more (complicated)
code and fewer database calls or less code and
multiple tables.

If we take the second option (multiple tables) I am
talking about maybe 15 database calls per page, and
the site will get around (i guess) 300-750 requests
for a page a minute at is peak.

The good thing is it will be running on a dedicated
server, sharing with around 5 of our other sites... no
exceptionally great traffic other than mentioned above
on the other sites either, plus most of the other
sites are plain html sites.


> > Or am I blowing smoke and MySql can handle that
> > without a sweat on a shared hosting environment?
> (with
> > say....100 page requests per minute?)
> 
> MySQL can probably handle it. But try not to do
> programming like that yourself. Stuff like that
gives PHP a bad name.


I wouldnt be going to those extremes, was thinking of
around 5-15 queries per page.



Think we'll have a problem?

Thanks!
Ryan

------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--- End Message ---

Reply via email to