php-general Digest 13 Oct 2003 06:55:39 -0000 Issue 2352

Topics (messages 165917 through 165929):

Call object reference and member function in 1 step
        165917 by: sturgis III

PHP uninstall/reinstall
        165918 by: Benjamin Howarth
        165922 by: Shadow

Re: Can't find oci.h
        165919 by: Paul Gregg

Re: Oracle - Win32
        165920 by: Paul Gregg

Re: mail() php in message
        165921 by: Onno Kuipers
        165924 by: Chris Hayes

Re: Age from date field?
        165923 by: Eugene Lee

Re: newbie question
        165925 by: Eugene Lee

Re: awful newbie question
        165926 by: Eugene Lee

Re: levenshtein - comparing strings?
        165927 by: Duncan

Fixed problem with a script, but need to understand why it happened
        165928 by: Mary D. Taffet

Working with external images
        165929 by: Voodoo

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 ---
I'm reading the References Explained section of php doc, and am a little
confused on the Returning References section.  I was wondering why you
cannot get a reference to an object and call a member function all in one
step like so:

$result=(&$bar->getObj())->foo();


I've tried this in code, and get a parse error.

--- End Message ---
--- Begin Message ---
Hi all, am a newbie to PHP so please spell your answers to my questions out
in words of one syllable or less...

I recently had PHP 4.2.1 installed on Windows 98 SE, then it suddenly
stopped working for some reason  - I don't know why or how, but I kept
getting SErver 500 errors. Having tried to remove all traces of PHP from the
Windows OS and tried to install the latest version (4.3.3), both with the
ZIP manual installation and the EXE self-install program, I still get
problems. Can anyone please please help, cause I really need PHP on my PC to
finish development of my local dramatics society's website and the
intermediary between me and the Society will puncture my jugular if I can't
get it working within the next week.

Ben Howarth

P.S. Am running PWS/IIS 3

--- End Message ---
--- Begin Message ---
I don't remember much about IIS 3/4 but here are the instruction for
installing under
windows......http://www.php.net/manual/en/install.windows.php
Shadow

--- End Message ---
--- Begin Message ---
In mail.php.general, Donahue, Peter <[EMAIL PROTECTED]> wrote:
> I'm building Php (4.3.3) on Solaris and am including oci8 support.
> Configure works fine. When I try to build, I get an error on the compilation
> of ext/oci8/oci8.c - it can't find oci.h, and then I get tons of errors,
> I suppose all stemming from this.

Little late, I know - tho I just got it working myself (only to have to
reformat and drop from Redhat9 to 7.3, so I can use Oracle 8.1.7 client
instead of 9 - compat, etc :( )

You need to reinstall the Oracle client - but this time use the full
Administrative Install. Then when you get to check the installed components
look through and check "Oracle Call Interface".

Install will go as before and this time you'll find an oci.h lurking in
an obscure directory: find . -name oci.h -print   should let you know where
it is.

Hope this helps.

Paul.

--- End Message ---
--- Begin Message ---
In mail.php.general, imran <[EMAIL PROTECTED]> wrote:
[snip]
> format like such: php_xxx. For Oracle DD, you'll need php_oracle.dll.  Take
> the oracle dll.

Only use the oracle dll if you are using oracle 7 client libs.  If you are
using Oracle 8+ then you want the oci8 dll.  Do not copy the php_oracle.dll
and do not enable that extension in php.ini

> THAT's it!
> Save the php.ini.
> 
> Now you can call Oracle functions

You also have to ensure that you have installed the Oracle Client Library
software. All php does is to convert the oracle calls to oracle's api and
gets the Oracle client lib to do the work.  Without this, you won't get too
far.  You can download the oracle client libs at otn.oracle.com (create a
free account).

Hope this helps.

Paul.

--- End Message ---
--- Begin Message --- Matthias Wulkow wrote:
Hallo Onno,

am Sonntag, 12. Oktober 2003 um 20:07 hast Du Folgendes gekritzelt:

OK> Hi,

OK> is there a way to create a mail (with the mail() function) that contains OK> php in the message.

OK> Like:

OK> <?php
OK> $to  = "[EMAIL PROTECTED]";
OK> $subject = "a subject";
OK> $message = ????

OK> I WANT TO PUT SOME PHP IN HERE TO CREATE A TABLE IN THE MESSAGE:

OK> $columnbooks = mysql_list_fields($dbname,tmp,$mysql_link);
OK> $sqlbooks = "select isbn,books.title, writer, publisher from tmp,books OK> where tmp.user=books.user";
OK> $resultbooks = mysql_db_query($dbname,$sqlbooks);
?>>
OK> <table cellpadding="2" cellspacing="2" border="1" style="text-align: left; width: 100%;">>
OK> <?php
OK> while ($valuebooks = mysql_fetch_array($resultbooks))
OK> { print "<tr bgcolor=#ccf504>";
OK> for($i=0; $i< 4; $i++ )
OK> {
OK> $gebruikerbooks=$valuebooks[$i];
OK> print "<td> $gebruikerbooks </td>";
OK> }
OK> print "</tr>";
OK> }
OK> mysql_free_result($resultbooks);


OK> THIS SHOULD BE THE END OF THE MESSAGE


OK> HERE I WILL DO THE MAILING

OK> mail($to,$subject,$message);
?>>


You should know that php runs on a server, not on the client machine. So what do you want to do with php-code in a mail? You could put html (generated by php for example), so that the mail-reader can display a table.


That is exactly what I want to do. I've got a mysql database. I want to generate a table with data from the database into the message of the mail. I know how the to put html in the message:


$message = '
<html>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
 <tr>
  <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
 </tr>
 <tr>
  <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
 </tr>
 <tr>
  <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
 </tr>
</table>
</body>
</html>
';

but I want to know how to put html generated by php in the message.
--- End Message ---
--- Begin Message ---
message of the mail. I know how the to put html in the message:

$message = '

in stead of
print "<td> $gebruikerbooks </td>";

do


$message .= "<td> $gebruikerbooks </td>";


A little clarification:
* Just instead of echoing it directly to the browser, add it to your variable $message.
* "$message.='bla';" is a shortcut for "$message.=$message . 'bla'; "
* the . is the glue for strings.

--- End Message ---
--- Begin Message ---
On Sun, Oct 12, 2003 at 02:49:53PM +0000, Curt Zirzow wrote:
: * Thus wrote Eugene Lee ([EMAIL PROTECTED]):
: > On Sun, Oct 12, 2003 at 02:09:38AM +0200, DvDmanDT wrote:
: > : 
: > : Does anyone have a good solution on how to get the age of someone from a
: > : date column in mysql... This is what I have, but it's not really the
: > : truth... What's the right way to do it?
: > : 
: > : floor((time()-$a["born"])/(3600*24*365.25))
: > : 
: > : where $a["born"] is the timestamp of the birthdate... Current query:
: > 
: > This should work for well-formed timestamps, i.e. they are not in the
: > future:
: > 
: > function age($ts)
: > {
: >     list($y1, $m1, $d1) = explode(' ', date('Y m d', $ts));
: >     list($y2, $m2, $d2) = explode(' ', date('Y m d', time()));
: >     $age = $y2 - $y1 - ((($m2 < $m1) || ($d2 < $d1)) ? 1 : 0);
: 
: What happens if the month is the same but the day hasnt been
: reached?
: 
: Shouldnt this be:
:      $age = $y2 - $y1 - ((($m2 < $m1) || ($m2 == $m1 && $d2 < $d1)) ? 1 : 0);
: 
: To account for it being the same month but not yet the day.

You're right.  I got lost trying to short-circuit the expression and
forgot to explicitly test for same month.  :-)

--- End Message ---
--- Begin Message ---
On Mon, Oct 13, 2003 at 03:23:53AM +1000, Wang Feng wrote:
: 
:  "1. An optional padding specifier that says what character will be used for
: padding the results to the right string size. This may be a space character
: or a 0 (zero character). The default is to pad with spaces. An alternate
: padding character can be specified by prefixing it with a single quote (').
: See the examples below."
: "3. An optional number, a width specifier that says how many characters
: (minimum) this conversion should result in."
: ---- http://au.php.net/manual/en/function.sprintf.php
: 
: Assume that $price=.65; then the "%0.2f" yields 0.65.
: 
: If we follow what the manual says, then can you tell me what the 0 is used
: for? Is it a (optional) paddinng spcifier OR is it a (optional) width
: specifier OR both? And why does it yiled 0.65 rather than .65?
: 
: (The manual doesn't explain things clear, man.)

The PHP manual is vague in several sections.  I wonder how bug reports
get submitted for it?

The optional specifiers to the left of the decimal place have a psuedo
last-to-first precedence.  For example:

        $price = .65;

        printf("'%8.2f'\n", $price);
        -> '       0.65'

This shows that there are 8 characters reserved for the number to the
left of the decimal.  Therefore, '8' is the width specifier.

        printf("'%-8.2f'\n", $price);
        -> '0.65       '

        printf("'%08.2f'\n", $price);
        -> '00000000.65'

        printf("'%0-8.2f'\n", $price);
        -> '0.650000000'

--- End Message ---
--- Begin Message ---
On Sun, Oct 12, 2003 at 07:09:32PM +0200, Marek Kilimajer wrote:
: 
: Paul Freedman wrote:
: >
: >In the php statement
: >$q->qzml();
: >what is the symbol '->' called? What does it mean?
:
: It calls *member* function of object $q.
[...]
: >I have also come across the symbol '=>'. I assume it is not the same 
: >symbol. What is it, and what does it mean?
: 
: It is used to assign values to keys in array() construct:
: http://sk.php.net/manual/en/function.array.php

But as for the first question, I don't know if '->' or '=>' have any
specific *names* in PHP.

--- End Message ---
--- Begin Message ---
Actually I found out that php.net offers the source code for that part :)
here it is: http://ca.php.net/source.php?url=/quickref.php

...and I was able to use it as a basis to fit my need.

Duncan

 Burhan Khalid wrote:

  Duncan wrote: 


    Hi, 

    I am trying to add a function to my template system where the script will output a 
similar name to the one entered, e.g.: 
    array('main','page1','testing','main_info'); 
    user input: 'mai' 
    then it should return 'main' & 'main_info' from the array as possible matches. 
(Ok, easy example, but it's supposed to work as well with worse typos) 

    Anyway, so I stumbled upon the levenshtein funtion which seems to be the right 
thing to use for s.th. like that. 

    However, how does on php.net the "search function" do it? Does it use a database 
match checking, or are they using some php function(s) to display matching function 
names? 


  I don't know how the search function (or google for that matter) do it, but a way to 
do it via SQL is "WHERE field LIKE mai%" 

  which will match main, mainly, mainstay, etc. 

  I would sure like to know how google does it. Maybe they use aspell? 


--- End Message ---
--- Begin Message ---
Hello,

I am a brand new subscriber to this list, and am fairly new to PHP as
well.  I started using it back in June to put together an online survey
for my dissertation.

Though I learned a few things the hard way, I have done mostly OK since
then, until I changed an increasingly complex script to using
functions.  That's when my big problem started.

Yes, I eventually figured out that global variables aren't accessible
inside a function unless they are declared as such.  Everything I have
read tells me that $_SESSION is equally accessible both outside and
inside functions.  For a while today, I was beginning to doubt that, but
then I realized that the problem I was experiencing was due to the
placement of a particular statement within the script.

This particular script calls three other scripts.  One (background.php)
should be called the first time a survey participant logs on.  Whether
or not the background had been collected yet was stored in a mysql table
and was used to control whether background.php got called or not.

Before the script was changed to use functions, calling background.php
happened just as I expected, first thing each time a new user logged on.

But when I changed the script to use functions, I could no longer get
that background.php to get called -- UNLESS I placed echo statements
after it to show the values in $_SESSION -- then it worked EVERY TIME.

I spent countless hours today trying to figure out why the $_SESSION
value which was controlling the call to background.php was apparently
not accessible, only to realize that that wasn't the problem at all --
instead the problem was placement within the code of the call to
background.php.

Here's the basic question for those of you more experienced than I:

Why was I able to call background.php just as I wanted to when the
script didn't have functions, but not able to make the very same call
when the script was changed to use functions?

Some code snippets:

1) before code was changed to use functions (background.php was called
as expected):

        //include DB connection
        include('./db.php');

        //start session
        session_start();

        $_SESSION["session_uid"]=$uid;

        //what person name pair will this user judge?
        $query="SELECT * FROM diss_pretesters WHERE
uid='".$_SESSION["session_uid"]."'";
        $result=mysql_db_query("$db","$query") or die(query_fail("$query"));

        //assign values from query to session variables
        $data=mysql_fetch_array($result);
        $_SESSION["session_set"]=$data['setid'];
        $_SESSION["session_sets_array_member"]=$data['last_setid'];
        $_SESSION["session_curr_array_member"]=$data['last_said_member_eval'];

$_SESSION["session_background_info_recorded"]=$data['background_info_recorded'];
        $_SESSION["session_sets_assigned"]=$data['sets_assigned'];

        if($_SESSION["session_background_info_recorded"]=='N')
        {
                header("location: background.php");     //collect background 
information
before any arrays are advanced
        }

        //create current array member
        if($_SESSION["session_curr_array_member"]=='')
        {
                $_SESSION["session_curr_array_member"]=0;
        }
        else
        {
                $_SESSION["session_curr_array_member"]++;
        }

        [snip some intervening code where some of the below values were set]

        $current_said_field = $_SESSION["session_curr_array_member"]+1;
        $current_said_fieldname = "said".$current_said_field;

        //Retrieve current said value from the randomized table
        $query="SELECT $current_said_fieldname FROM diss_user_set_randomize
WHERE uid='$uid' AND setid='".$_SESSION["session_set"]."'";
        //echo "QUERY: $query";
        $result=mysql_db_query("$db","$query") or die(query_fail("$query"));

        //assign values from query to session variables
        $data=mysql_fetch_array($result);
        $current_said=$data[$current_said_fieldname];

        $_SESSION["session_current_said"]=$current_said;



if($_SESSION["session_curr_array_member"]<$_SESSION["session_set_size"])
        {
                header("location: judgeFrameset.php");                          //send 
user to relevant
frameset
        }
        else
        {
                header("location: posttask.php");
        }


2) Code from initial stab at functions, which didn't work in that
background.php was never called -- unless followed immediately by
uncommented echo statements; instead either judgeFrameset.php or
posttask.php were called:


/////////////////////////////////////////////////////////////////////////////////////////////
        function GetBasicInfo ()
        {
                global $db, $uid;

                $query="SELECT * FROM diss_pretesters WHERE uid='$uid'";
                $result=mysql_db_query("$db","$query") or die(query_fail("$query"));
                $data=mysql_fetch_array($result);
                $_SESSION["session_set"]=$data['setid'];
                $temp_setid = $_SESSION["session_set"];
                $_SESSION["session_sets_array_member"]=$data['last_setid'];
                $_SESSION["session_curr_array_member"]=$data['last_said_member_eval'];
        
$_SESSION["session_background_info_recorded"]=$data['background_info_recorded'];
                $_SESSION["session_sets_assigned"]=$data['sets_assigned'];

                if ($temp_setid!='')
                {
                        $query="SELECT * FROM diss_users_assign WHERE uid='$uid' AND
setid='$temp_setid'";
                        $result=mysql_db_query("$db","$query") or 
die(query_fail("$query"));
                        $data=mysql_fetch_array($result);
                        $_SESSION["session_set_shuffled"]=$data['Shuffled'];
                        $_SESSION["session_set_completed"]=$data['Completed'];
                }

                return 0;
        }


/////////////////////////////////////////////////////////////////////////////////////////////

[some more functions]

        //include DB connection
        include('./db.php');

        //start session
        session_start();

        $_SESSION["session_uid"]=$uid;

        $dummy = GetBasicInfo();

        if($_SESSION["session_background_info_recorded"]=='N')
        {
                header("location: background.php");     //collect background 
information
before doing anything else
        }

        //Set assignment
        if($_SESSION["session_sets_assigned"]=='N')
        {
            // first time through for this user
                $dummy = FindNewSet();
                $dummy = GetSets();
                $dummy = GetBasicInfo();
        }
        elseif($_SESSION["session_set_completed"]=='Y')
        {
            // user just finished last set; need to start a new one
                $dummy = FindNewSet();
                $dummy = GetSets();
                $dummy = StartNewSet();
                $dummy = GetBasicInfo();
        }

    // first time through only; randomize the order of name pairs shown
to the participant

        if ($_SESSION["session_set_shuffled"]=='N')
        {
                $dummy = RandomizeSet();
        }

        //create current array member
        if($_SESSION["session_curr_array_member"]=='')
        {
                $_SESSION["session_curr_array_member"]=0;
        }
        else
        {
                $_SESSION["session_curr_array_member"]++;
        }

        $current_said_field = $_SESSION["session_curr_array_member"]+1;
        $current_said_fieldname = "said".$current_said_field;

        //Retrieve current said value from the randomized table
        $query="SELECT $current_said_fieldname FROM diss_user_set_randomize
WHERE uid='$uid' AND setid='".$_SESSION["session_set"]."'";
        $result=mysql_db_query("$db","$query") or die(query_fail("$query"));
        $data=mysql_fetch_array($result);
        $current_said=$data[$current_said_fieldname];

        $_SESSION["session_current_said"]=$current_said;

        if($_SESSION["session_curr_array_member"] < 15)
        {
                header("location: judgeFrameset.php");                          //send 
user to relevant
frameset
        }
        else
        {
                header("location: posttask.php");
        }


3) Code after changing the location within the script of the call to
background.php (finally works!):


/////////////////////////////////////////////////////////////////////////////////////////////
        function GetBasicInfo ()
        {
                global $db, $uid;

                $query="SELECT * FROM diss_pretesters WHERE uid='$uid'";
                $result=mysql_db_query("$db","$query") or die(query_fail("$query"));
                $data=mysql_fetch_array($result);
                $_SESSION["session_set"]=$data['setid'];
                $temp_setid = $_SESSION["session_set"];
                $_SESSION["session_sets_array_member"]=$data['last_setid'];
                $_SESSION["session_curr_array_member"]=$data['last_said_member_eval'];
        
$_SESSION["session_background_info_recorded"]=$data['background_info_recorded'];
                $_SESSION["session_sets_assigned"]=$data['sets_assigned'];

                if ($temp_setid!='')
                {
                        $query="SELECT * FROM diss_users_assign WHERE uid='$uid' AND
setid='$temp_setid'";
                        $result=mysql_db_query("$db","$query") or 
die(query_fail("$query"));
                        $data=mysql_fetch_array($result);
                        $_SESSION["session_set_shuffled"]=$data['Shuffled'];
                        $_SESSION["session_set_completed"]=$data['Completed'];
                }

                return 0;
        }


/////////////////////////////////////////////////////////////////////////////////////////////

[some more functions]

        //include DB connection
        include('./db.php');

        //start session
        session_start();

        $_SESSION["session_uid"]=$uid;

        $dummy = GetBasicInfo();

        //Set assignment
        if($_SESSION["session_sets_assigned"]=='N')
        {
            // first time through for this user
                $dummy = FindNewSet();
                $dummy = GetSets();
                $dummy = GetBasicInfo();
        }
        elseif($_SESSION["session_set_completed"]=='Y')
        {
            // user just finished last set; need to start a new one
                $dummy = FindNewSet();
                $dummy = GetSets();
                $dummy = StartNewSet();
                $dummy = GetBasicInfo();
        }

    // first time through only; randomize the order of name pairs shown
to the participant

        if ($_SESSION["session_set_shuffled"]=='N')
        {
                $dummy = RandomizeSet();
        }

        //create current array member
        if($_SESSION["session_curr_array_member"]=='')
        {
                $_SESSION["session_curr_array_member"]=0;
        }
        else
        {
                $_SESSION["session_curr_array_member"]++;
        }

        $current_said_field = $_SESSION["session_curr_array_member"]+1;
        $current_said_fieldname = "said".$current_said_field;

        //Retrieve current said value from the randomized table
        $query="SELECT $current_said_fieldname FROM diss_user_set_randomize
WHERE uid='$uid' AND setid='".$_SESSION["session_set"]."'";
        $result=mysql_db_query("$db","$query") or die(query_fail("$query"));
        $data=mysql_fetch_array($result);
        $current_said=$data[$current_said_fieldname];

        $_SESSION["session_current_said"]=$current_said;

        if($_SESSION["session_background_info_recorded"]=='N')
        {
                header("location: background.php");     //collect background 
information
before doing anything else
        }
        elseif($_SESSION["session_curr_array_member"] < 15)
        {
                header("location: judgeFrameset.php");                          //send 
user to relevant
frameset
        }
        else
        {
                header("location: posttask.php");
        }



***************************************************************

Before I figured this out, I was going to write and ask why the h*** PHP
couldn't access the value of
$_SESSION["session_background_info_recorded"].

Now that I know this is not the problem, my question becomes why does it
matter where in the code the call to background.php is placed?  Why does
it work in the top of the script before using functions, and cease to
work at the top of the non-function part of the script after adding
functions?  I'm at a loss to understand why.

-- Mary Taffet

--- End Message ---
--- Begin Message ---
I'm trying to write a script that can work with images as google does. I've
got an image with some unknown width and height, and I want to be able to
get this properties and use them to create a dynamic page with new size
attributes.

For example, if the image has 400x600 px, I want to display the line

<img src="someImage" width="40" height="60">

even if the script wasn't previosly told the image was 400x600 px. If the
image is 500x800, I want to change it to 50x80.

Can I do that with php?

Regards,

Voodoo

--- End Message ---

Reply via email to