php-general Digest 6 Apr 2012 12:34:03 -0000 Issue 7763

Topics (messages 317462 through 317473):

foreach
        317462 by: Ethan Rosenberg
        317463 by: Jim Giner
        317465 by: Al

Re: [PHP-DB] Re: foreach
        317464 by: Karl DeSaulniers
        317466 by: Kris Carlson

image inventoryer
        317467 by: Kirk Bailey
        317468 by: Tommy Pham
        317469 by: Jim Giner
        317470 by: Kirk Bailey
        317471 by: Kirk Bailey
        317472 by: Tommy Pham
        317473 by: Jim Giner

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
Dear Lists -

I know I am missing something fundamental - but I have no idea where to start to look.

Here are code snippets:

I have truncated the allowed_fields to make it easier to debug.

$allowed_fields = array( 'Site' =>'POST[Site]', 'MedRec' => '$_POST[MedRec]', 'Fname' => '$_POST[Fname]' );
 echo "post #1\n";
 print_r($_POST);

RESPONSE:

 post #1
Array
(
    [Site] => AA
    [MedRec] => 10002
    [Fname] =>
    [Lname] =>
    [Phone] =>
    [Height] =>
    [welcome_already_seen] => already_seen
    [next_step] => step10
)



// $allowed_fields = array("Site", "MedRec", "Fname", "Lname", // previous statement of $allowed_fields
  //                      "Phone", "Sex", "Height");



Key Site, Value POST[Site]
Key MedRec, Value $_POST[MedRec]
Key Fname, Value $_POST[Fname]



foreach ($allowed_fields as $key => $val) {
    print "Key $key, Value $val\n";
}


        if(isset($_Request['Sex'])&& trim($_POST['Sex']) != '' )
        {
                if ($_REQUEST['Sex'] === "0")
                {
                        $sex = 'Male';
                }
                else
                {
                        $sex = 'Female';
                }
        }
 }
                echo "Post#2";
                print_r($_POST);
                   if(empty($allowed_fields))
//RESPONSE

Post#2Array
(
    [Site] => AA
    [MedRec] => 10002
    [Fname] =>
    [Lname] =>
    [Phone] =>
    [Height] =>
    [welcome_already_seen] => already_seen
    [next_step] => step10
)



   {
     echo "ouch";
   }

foreach ( $allowed_fields as $key => $val ) //This is line 198
{
        if ( ! empty( $_POST['val'] ) )
        {
                print "Key $key, Value $val\n";
                        $cxn = mysqli_connect($host,$user,$password,$db);
                $value = mysql_real_escape_string( $_POST[$fld] );
                $query .= " AND $fld = '$_POST[value]' ";
               echo "#1 $query"; //never echos the query
        }
}

These are the messages I receive on execution of the script:

Notice: Undefined variable: allowed_fields in /var/www/srchrhsptl5.php on line 198 Warning: Invalid argument supplied for foreach() in /var/www/srchrhsptl5.php on line 198

Advice and help, please.

Thank you.

Ethan Rosenberg




--- End Message ---
--- Begin Message ---
I don't know about others, but I can't make sense of this - way too much 
presented with no idea of what I am looking at - code or output.

One thing:  $_Request is not the same var as $_REQUEST. 



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


On 4/5/2012 4:15 PM, Ethan Rosenberg wrote:
Dear Lists -

I know I am missing something fundamental - but I have no idea where to start to
look.

Here are code snippets:

I have truncated the allowed_fields to make it easier to debug.

$allowed_fields = array( 'Site' =>'POST[Site]', 'MedRec' => '$_POST[MedRec]',
'Fname' => '$_POST[Fname]' );
echo "post #1\n";
print_r($_POST);

RESPONSE:

post #1
Array
(
[Site] => AA
[MedRec] => 10002
[Fname] =>
[Lname] =>
[Phone] =>
[Height] =>
[welcome_already_seen] => already_seen
[next_step] => step10
)



// $allowed_fields = array("Site", "MedRec", "Fname", "Lname", // previous
statement of $allowed_fields
// "Phone", "Sex", "Height");



Key Site, Value POST[Site]
Key MedRec, Value $_POST[MedRec]
Key Fname, Value $_POST[Fname]



foreach ($allowed_fields as $key => $val) {
print "Key $key, Value $val\n";
}


if(isset($_Request['Sex'])&& trim($_POST['Sex']) != '' )
{
if ($_REQUEST['Sex'] === "0")
{
$sex = 'Male';
}
else
{
$sex = 'Female';
}
}
}
echo "Post#2";
print_r($_POST);
if(empty($allowed_fields))
//RESPONSE

Post#2Array
(
[Site] => AA
[MedRec] => 10002
[Fname] =>
[Lname] =>
[Phone] =>
[Height] =>
[welcome_already_seen] => already_seen
[next_step] => step10
)



{
echo "ouch";
}

foreach ( $allowed_fields as $key => $val ) //This is line 198
{
if ( ! empty( $_POST['val'] ) )
{
print "Key $key, Value $val\n";
$cxn = mysqli_connect($host,$user,$password,$db);
$value = mysql_real_escape_string( $_POST[$fld] );
$query .= " AND $fld = '$_POST[value]' ";
echo "#1 $query"; //never echos the query
}
}

These are the messages I receive on execution of the script:

Notice: Undefined variable: allowed_fields in /var/www/srchrhsptl5.php on line 
198
Warning: Invalid argument supplied for foreach() in /var/www/srchrhsptl5.php on
line 198

Advice and help, please.

Thank you.

Ethan Rosenberg


Break down you code into workable segments and test each one individually. If you have a problem with a small segment, ask for help about it specifically.

Folks don't have time to digest and critique your whole code.


--- End Message ---
--- Begin Message ---
And POST[] is not the same as $_POST[]

Karl

Sent from losPhone

On Apr 5, 2012, at 3:24 PM, "Jim Giner" <jim.gi...@albanyhandball.com> wrote:

> I don't know about others, but I can't make sense of this - way too much 
> presented with no idea of what I am looking at - code or output.
> 
> One thing:  $_Request is not the same var as $_REQUEST. 
> 
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

--- End Message ---
--- Begin Message ---
Send the code around line 198, say 170 to 210.

On Apr 5, 2012, at 8:42 PM, Al wrote:

> 
> 
> On 4/5/2012 4:15 PM, Ethan Rosenberg wrote:
>> Dear Lists -
>> 
>> I know I am missing something fundamental - but I have no idea where to 
>> start to
>> look.
>> 
>> Here are code snippets:
>> 
>> I have truncated the allowed_fields to make it easier to debug.
>> 
>> $allowed_fields = array( 'Site' =>'POST[Site]', 'MedRec' => '$_POST[MedRec]',
>> 'Fname' => '$_POST[Fname]' );
>> echo "post #1\n";
>> print_r($_POST);
>> 
>> RESPONSE:
>> 
>> post #1
>> Array
>> (
>> [Site] => AA
>> [MedRec] => 10002
>> [Fname] =>
>> [Lname] =>
>> [Phone] =>
>> [Height] =>
>> [welcome_already_seen] => already_seen
>> [next_step] => step10
>> )
>> 
>> 
>> 
>> // $allowed_fields = array("Site", "MedRec", "Fname", "Lname", // previous
>> statement of $allowed_fields
>> // "Phone", "Sex", "Height");
>> 
>> 
>> 
>> Key Site, Value POST[Site]
>> Key MedRec, Value $_POST[MedRec]
>> Key Fname, Value $_POST[Fname]
>> 
>> 
>> 
>> foreach ($allowed_fields as $key => $val) {
>> print "Key $key, Value $val\n";
>> }
>> 
>> 
>> if(isset($_Request['Sex'])&& trim($_POST['Sex']) != '' )
>> {
>> if ($_REQUEST['Sex'] === "0")
>> {
>> $sex = 'Male';
>> }
>> else
>> {
>> $sex = 'Female';
>> }
>> }
>> }
>> echo "Post#2";
>> print_r($_POST);
>> if(empty($allowed_fields))
>> //RESPONSE
>> 
>> Post#2Array
>> (
>> [Site] => AA
>> [MedRec] => 10002
>> [Fname] =>
>> [Lname] =>
>> [Phone] =>
>> [Height] =>
>> [welcome_already_seen] => already_seen
>> [next_step] => step10
>> )
>> 
>> 
>> 
>> {
>> echo "ouch";
>> }
>> 
>> foreach ( $allowed_fields as $key => $val ) //This is line 198
>> {
>> if ( ! empty( $_POST['val'] ) )
>> {
>> print "Key $key, Value $val\n";
>> $cxn = mysqli_connect($host,$user,$password,$db);
>> $value = mysql_real_escape_string( $_POST[$fld] );
>> $query .= " AND $fld = '$_POST[value]' ";
>> echo "#1 $query"; //never echos the query
>> }
>> }
>> 
>> These are the messages I receive on execution of the script:
>> 
>> Notice: Undefined variable: allowed_fields in /var/www/srchrhsptl5.php on 
>> line 198
>> Warning: Invalid argument supplied for foreach() in /var/www/srchrhsptl5.php 
>> on
>> line 198
>> 
>> Advice and help, please.
>> 
>> Thank you.
>> 
>> Ethan Rosenberg
>> 
> 
> Break down you code into workable segments and test each one individually. If 
> you have a problem with a small segment, ask for help about it specifically.
> 
> Folks don't have time to digest and critique your whole code.
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


--- End Message ---
--- Begin Message --- I need a page that will live in a directory and list all image files in there. That is, the page has
<img src="./foo.type"><P>
tags emitted in it's structure, one per file in the directory with a saught file type- .png, .gif, .jpg, you get the idea. this should use relative addressing so once the tool is built I can use it in other directories as is.

Now ai am still a novice at p[hp, how can I do this ?

--
end

Very Truly yours,
                 - Kirk Bailey,
                   Largo Florida

                       kniht
                      +-----+
                      | BOX |
                      +-----+
                       think


--- End Message ---
--- Begin Message ---
On Thu, Apr 5, 2012 at 7:26 PM, Kirk Bailey <kbai...@howlermonkey.net> wrote:
>
> Now ai am still a novice at p[hp, how can I do this ?
>

Have you read any book on PHP?  even the official from PHP.net?  Learn
the tool so you know how to use it, efficiently.  Otherwise how do you
know if the tool can do what you want...  What you're asking for ATM
is someone to write the code for you which is not how it works.  You
need to provide some code, or even pseudo code at least...

HTH,
Tommy

--- End Message ---
--- Begin Message ---
As Tommy says - you sound like a total new user who doesn't know how to do 
it and furthermore doesn't know how many things you are going to have to 
pick up just to accomplish this task.

You have to:

determine the folder your script is running from
collect an array of  image file names from that directory
determine the size of each of these images so that you are not building some 
html that will try to display an unmanageable amount of data all at once. 
You may then have to learn how to create smaller images for your img tags, 
which is another learning process in itself
determine how many images you will display and decide again if you really 
can allow the user to make this kind of request.  This could also create 
another step in the process to keep track of what images have already been 
displayed so that when the screen comes back to your script you can pick up 
where you left off and display a second page.

THEN you can generate the html to produce a useful page of images.

At least that's how I would approach it. And I'm not an expert but simply a 
guy who has put in about a year's worth of effort into learning enough php 
to actually do something like this already, among other things. 



--- End Message ---
--- Begin Message ---
ok.
<?php
filelist=inventory all files in directory "./"

for file in filelist: // walk a listing of many items
    IF filetype in "gif, jpg, png" {
        echo '<img src="./'.file.'"><P>'
// notice that is a 'singlequote' immedately followed by a "doublequote".
?>

Something like this. In python I would write something like:

#!/usr/bin/python
import string, glob
files=glob.glob("./*.*") # files is a list variable (a 1 dimensional addressable array) for file in files: # for each cell in files do this doblock: if str.split(file,'.')[1] in "gif","jpg","png"): #if the file type is in a list of acceptable types, print '<img src="./'+file+'"><P>' # print out the material to return surrounding # the file name





On 4/5/2012 10:34 PM, Tommy Pham wrote:
On Thu, Apr 5, 2012 at 7:26 PM, Kirk Bailey<kbai...@howlermonkey.net>  wrote:
Now ai am still a novice at p[hp, how can I do this ?

Have you read any book on PHP?  even the official from PHP.net?  Learn
the tool so you know how to use it, efficiently.  Otherwise how do you
know if the tool can do what you want...  What you're asking for ATM
is someone to write the code for you which is not how it works.  You
need to provide some code, or even pseudo code at least...

HTH,
Tommy


--- End Message ---
--- Begin Message ---
jim, I am a novice at this language as I said.

On 4/5/2012 10:44 PM, Jim Giner wrote:
As Tommy says - you sound like a total new user who doesn't know how to do
it and furthermore doesn't know how many things you are going to have to
pick up just to accomplish this task.

You have to:

determine the folder your script is running from
collect an array of  image file names from that directory
determine the size of each of these images so that you are not building some
html that will try to display an unmanageable amount of data all at once.
You may then have to learn how to create smaller images for your img tags,
which is another learning process in itself
determine how many images you will display and decide again if you really
can allow the user to make this kind of request.  This could also create
another step in the process to keep track of what images have already been
displayed so that when the screen comes back to your script you can pick up
where you left off and display a second page.

THEN you can generate the html to produce a useful page of images.

At least that's how I would approach it. And I'm not an expert but simply a
guy who has put in about a year's worth of effort into learning enough php
to actually do something like this already, among other things.

And were people this nice to you when YOU asked beginner questions?


--- End Message ---
--- Begin Message ---
On Thu, Apr 5, 2012 at 8:02 PM, Kirk Bailey <kbai...@howlermonkey.net> wrote:

If you don't want to read the manual or a book, you could quickly do
some Google'ing as below:

> ok.
> <?php
> filelist=inventory all files in directory "./"
>
filesystem site:php.net

> for file in filelist: // walk a listing of many items

loop site:php.net

>    IF filetype in "gif, jpg, png" {

condition site:php.net

>        echo '<img src="./'.file.'"><P>'
> // notice that is a 'singlequote' immedately followed by a "doublequote".
> ?>

Or just look at the table of contents in the official manual to see
what PHP has to offer and see what you can do since you already have
some programming experience.

>
> Something like this. In python I would write something like:
>
> #!/usr/bin/python
> import string, glob
> files=glob.glob("./*.*")                             # files is a list
> variable (a 1 dimensional addressable array)
> for file in files:                                         # for each cell
> in files do this doblock:
>    if str.split(file,'.')[1] in "gif","jpg","png"): #if the file type is in
> a list of acceptable types,
>        print '<img src="./'+file+'"><P>'        # print out the material to
> return surrounding
>                                                             # the file name
>
>
>
>
>
>
> On 4/5/2012 10:34 PM, Tommy Pham wrote:
>>
>> On Thu, Apr 5, 2012 at 7:26 PM, Kirk Bailey<kbai...@howlermonkey.net>
>>  wrote:
>>>
>>> Now ai am still a novice at p[hp, how can I do this ?
>>>
>> Have you read any book on PHP?  even the official from PHP.net?  Learn
>> the tool so you know how to use it, efficiently.  Otherwise how do you
>> know if the tool can do what you want...  What you're asking for ATM
>> is someone to write the code for you which is not how it works.  You
>> need to provide some code, or even pseudo code at least...
>>
>> HTH,
>> Tommy
>>
>

PS:  don't top post since it's preferred on this list.  You can search
the archive for the discussion about it.

HTH,
Tommy

--- End Message ---
--- Begin Message ---
"Kirk Bailey" <kbai...@howlermonkey.net> wrote in message 
news:4f7e5d2f.3050...@howlermonkey.net...
> jim, I am a novice at this language as I said.
>

Then you are taking on too big of a task.

When I decided to pick up some web programming skills I bought a $50 
book/manual on learning PHP and another on MySQL.  I read them - cover to 
cover.  Then I made up simple tasks to develop in order to LEARN how it's 
actually done.  Sounds like you not only want someone to program it for you, 
but probably help you implement it too.  Sure - I or someone with time on 
their hands - could reply back with a couple hundred lines of code and give 
you your answer.  Then what would you have gained?

Hey - I gave you the outline of how this goal of yours could be 
accomplished.  No need for your own pseudo-code at this point.  Take mine 
and go do some research!  Have fun!  Then come back for clarification on 
what you're doing wrong once you have some actual code written.

>>
> And were people this nice to you when YOU asked beginner questions?
>>
When I asked beginner questions, it was AFTER I had written something and 
ran into a roadblock.  NOT before I had set pen to paper.  You're asking how 
to get to California without having consulted a map yet.  This site will be 
there for you when you have a problem - don't worry.  Me included, not that 
my input is that worthy. 



--- End Message ---

Reply via email to