php-general Digest 18 Jan 2004 10:23:07 -0000 Issue 2537

Topics (messages 174938 through 174962):

Re: Thumbnails in database
        174938 by: Peter Vertes
        174939 by: Toby Irmer
        174940 by: Jason Sheets

Win32 Getting username from windows
        174941 by: Gastovski \(James\)
        174944 by: John W. Holmes

Re: Thumbnails in database - SOLUTION
        174942 by: Kevin Waterson

Re: Image Header Issues
        174943 by: Larry Brown
        174953 by: Bob Eldred
        174957 by: Larry Brown
        174960 by: Toby Irmer

Re: alternative to protecting files through http auth.
        174945 by: Jason Wong

Re: Justin is a genius
        174946 by: Justin French
        174956 by: Ryan A

POST method for hyperlink
        174947 by: Joe Harman
        174951 by: Richard Davey
        174952 by: Joe Harman

help with form
        174948 by: eawilkes
        174949 by: daniel.electroteque.org
        174950 by: Justin French

Troubles Accessing Global Variables
        174954 by: Adelaide Yip
        174955 by: Adelaide Yip

Drop down lists
        174958 by: BigMark
        174959 by: Peter Vertes
        174961 by: Toby Irmer

Is this possible ?
        174962 by: Dave Carrera

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 --- On Sat, 2004-01-17 at 16:44, Kevin Waterson wrote:

> Why create thumnails?  You can resize the images on
> the fly when needed.

This would be too expensive.

I need to store the thumbnails in the database.
So, I need to resize the image at the same time as I store it.

I can do this and save the thumbnail in the file system, but
cannot save the thumbnail in the database.

Kevin,

    I'm working on a web based photo gallery site which stores images in a MySQL database so you and I are working on something pretty similar.  Like you I'm storing both the thumbnail (150x150) and a full sized image (768x512 or 512x768 depending on image orientation) in the database.  You you could only store the full sized images in a database and resize them to thumbnails when they are needed but when you have 25 or more thumbnails to display on the same page resizing them on the fly pegs the CPU at 100% and if you have any other sites running on that same box they will experience a slow down too so that is why I opted to store the thumbnails in the database also.  Disk space is very cheap and the thumbnails don't take too much space.  Worse case scenario you can add another drive to the machine you are hosting the site on and presto, you have more disk space.
    In my web application I create the thumbnail and the full sized image all in one pass when a user uploads an image though a web page.  Creating both the thumbnail and the full size images doesn't take that much CPU time.  If I load in an image from my 2 megapixel digital camera (1600x1200) it will take 0.3 seconds on my 1.8GHz P4 to resize the image to a thumbnail and to a full sized image to be displayed in my web gallery.
    I don't know how to create an image in memory and write that to the database so I'm writing both the thumbnail and the full sized image out to my /tmp directory and then re-reading them into the database.  At first I thought it might seem to be a bit inefficient but with this method I'm getting the 0.3s time to read in the original file, create a thumbnail, write it out to disk, read it into the database, create a full sized image, write it out to disk, read it into the database so I'm pretty happy with it.  The code goes something like this:

---

// read in the image file from the disk that needs to be resized and uploaded
$image_original = ImageCreateFromJpeg($path_to_image_file_on_disk);

// allocate memory for the thumbnail image
$image_thumbnail = ImageCreateTrueColor($thumbnail_width, $thumbnail_height);

// copy and resize the original image into the thumbnail memory we have allocated
ImageCopyResized($image_thumbnail, $image_original, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, imagesx($image_original), imagesy($image_original));

// save the newly created thumbnail to disk
ImageJpeg($image_thumbnail, $path_to_save_thumbnail_image, 100);

// open up the thumbnail file for reading and then encode it with MIME Base64
$thumbnail_contents = base64_encode(fread(fopen($path_to_read_thumbnail_from, "rb"), filesize($path_to_read_thumbnail_from)));

// delete the thumbnail file from the disk
unlink($path_to_read_thumbnail_from);

// deallocate memory used to create our original and thumbnail images
ImageDestory($image_original);
ImageDestory($image_thumbnail);

---

    You do the same thing for the full sized image you want to store in the database as well but you have to make sure you get the image's orientation right otherwise your resize will give you a hard time.  When it's time to insert the images into the database for the thumbnail you will insert $thumbnail_contents and whatever else variable you chose for the full sized image.  One thing to watch out for is that when you read the images from the database you want to use base64_decode() on them.  Hope this works out for you.  If you need more help give me a shout.

-Pete

-- 
perl -e 'print pack("H*", "70766572746573406E79632E72722E636F6D0A")'

Attachment: signature.asc
Description: This is a digitally signed message part


--- End Message ---
--- Begin Message ---
http://www.sum-it.nl/en200319.php3

<quote>
Create thumbnail
  a.. Cropping and scaling a photo is surprisingly easy with PHP.
  b.. Unfortunately the functions imagecreatetruecolor() and
imagecopyresampled() exist only since PHP 4.0.6 using GD 2.0.1. Older PHP
version supports the functions imagecreate() and imagecopyresized(), which
are good enough to do the job.
  c.. It is possible to generate a thumbnail on the fly, in RAM memory,
using ob_start() and ob_end_clean(). That saves unnecessary fumbling around
with temporary files.
  d.. ...

</quote>

hth

toby


> I am storing some images in a database. No problems there.
> But how can I create a thumbnail do store in the db also
> without having to create the thumbnail image on the
> file system first?
>
> Kind regards
> Kevin

--- End Message ---
--- Begin Message --- The latest version of GD adds support for opening an image from a pointer to the C/C++ API but that support is not in PHP.

It is recommended to create the thumbnail on file upload using the $_FILES array to get the temporary file name, if you need to create a thumbnail from a file only in the database you need to read it, write it to a temporary file and then resize it, then do your action with it.

Look at tempnam() , it will generate a temporary file name for you to open.

Jason

Kevin Waterson wrote:

I am storing some images in a database. No problems there.
But how can I create a thumbnail do store in the db also
without having to create the thumbnail image on the file system first?

Kind regards
Kevin




--- End Message ---
--- Begin Message ---
I'm using the following code to extract the username running on the windows
machine:

[start code]
$api = new win32;
$api->registerfunction("long GetUserName (string &a, int &b) From
advapi32.dll");
$len = 255;
$name = str_repeat("\0", $len);
if ($api->GetUserName($name, $len) == 0)
{
   die("failed");
}
[end code]

However when I 'echo ($name);' I get the value SYSTEM. This is correct,
because advapi32.dll is probably being run by SYSTEM user on windows.
However I need to get the name of the person logged onto the computer, not
the SYSTEM running processes in the background. Is there any way of doing
this?

Many Thanks - James Gastovski

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.553 / Virus Database: 345 - Release Date: 18/12/2003
 

--- End Message ---
--- Begin Message --- Gastovski (James) wrote:

I'm using the following code to extract the username running on the windows
machine:

[start code]
$api = new win32;
$api->registerfunction("long GetUserName (string &a, int &b) From
advapi32.dll");
$len = 255;
$name = str_repeat("\0", $len);
if ($api->GetUserName($name, $len) == 0)
{
   die("failed");
}
[end code]

However when I 'echo ($name);' I get the value SYSTEM. This is correct,
because advapi32.dll is probably being run by SYSTEM user on windows.
However I need to get the name of the person logged onto the computer, not
the SYSTEM running processes in the background. Is there any way of doing
this?

Try $_SERVER['LOGON_USER']. With IIS, you will need to disable anonymous access.

--
---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com
--- End Message ---
--- Begin Message ---
This one time, at band camp, Kevin Waterson <[EMAIL PROTECTED]> wrote:

> I need to store the thumbnails in the database.
> So, I need to resize the image at the same time as I store it.

Ok, so the secret here is output buffering

         // prepare the image for insertion
         $imgData =addslashes (file_get_contents($_FILES['userfile']['tmp_name']));
         // do not use addslashes yet
        $thumbData = $_FILES['userfile']['tmp_name'];
        // get the image info..
        $size = getimagesize($_FILES['userfile']['tmp_name']);
        // database connection
        mysql_connect("localhost", "$dbusername", "$dbpassword") OR DIE 
(mysql_error());
        // select the db
        mysql_select_db ($dbname) OR DIE ("Unable to select db".mysql_error());

        // create the thumbnail
        $height   = '50';         // the height of the thumbnail
        $width    = '50';         // the width of the thumbnail
        // snarf the thumbdata
        $src = ImageCreateFromjpeg($thumbData);
        // create the thumbnail
        $destImage = ImageCreateTrueColor($height, $width);
        // copy the resize/resampled image to the destImage
        ImageCopyResampled($destImage, $src, 0,0,0,0, $width, $height, $size[0], 
$size[1]);
        // start the output buffering
        ob_start();
        // pretend to send the image to the browser
        imageJPEG($destImage);
        // stick the output buffer in a variable
        $photo_thumb = ob_get_contents();
        // now we can addslashes for inserting into the db
        $photo_thumb = addslashes($photo_thumb);
        // tidy up a little
        ob_end_clean();

       $sql = "INSERT INTO phototable ( photo_id, photo_cat, photo_type ,photo_thumb, 
photo_data, photo_size, photo_name) VALUES ('', 'cat', '{$size['mime']}', 
'{$photo_thumb}', '{$imgData}', '{$size[3]}', '{$_FILES['userfile']['name']}')";
                                                                                       
                              
        // insert the image
       mysql_query($sql)

Easy as that! You do not need to create the file on the filesystem as some have 
suggested,
or use ImageCreateFromString() and pull the original out of the db. It can all be done 
in
one dastardly sweep.

Thanks to all
Kevin

-- 
 ______                              
(_____ \                             
 _____) )  ____   ____   ____   ____ 
|  ____/  / _  ) / _  | / ___) / _  )
| |      ( (/ / ( ( | |( (___ ( (/ / 
|_|       \____) \_||_| \____) \____)
Kevin Waterson
Port Macquarie, Australia

--- End Message ---
--- Begin Message ---
Since putting .jpg solved the problem for me, I'm ok with that work around,
but you're right.  I'm using session_start() on all of my scripts.  That's
also good to know that it doesn't fail without that function so I have a
better idea of where to look, the next time I have header problems.

Thanks

Larry

-----Original Message-----
From: Toby Irmer [mailto:[EMAIL PROTECTED]
Sent: Saturday, January 17, 2004 5:12 PM
To: Larry Brown; Bob Eldred; PHP List
Subject: Re: [PHP] Image Header Issues


I have the same problem. Strange: I have a session_start(); before the
header... if I take that out, the image will download as a JPG... so maybe
if you find a way to do things in this script without starting the session
first...

toby


----- Original Message -----
From: "Larry Brown" <[EMAIL PROTECTED]>
To: "Bob Eldred" <[EMAIL PROTECTED]>; "PHP List"
<[EMAIL PROTECTED]>
Sent: Saturday, January 17, 2004 6:32 PM
Subject: RE: [PHP] Image Header Issues


> try adding showpicture.php?pid=111384&img=x.jpg to the end even though you
> aren't using that variable, IE may see that the type is jpg here.  I have
> this same problem/workaround in place right now for a script that wouldn't
> work with IE without it for downloading pdf. (pdf was generated on the
fly)
>
> -----Original Message-----
> From: Bob Eldred [mailto:[EMAIL PROTECTED]
> Sent: Saturday, January 17, 2004 12:00 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] Image Header Issues
>
>
> Again, it is *not* that known issue.  That's the very first thing I
checked.
> If that were the issue, jpgs from other sources would also not save
> properly.  But they do, as I've stated several times.
>
> Thanks, though.
>
> Bob
>
> ----- Original Message -----
> From: "Brian V Bonini" <[EMAIL PROTECTED]>
> To: "Bob Eldred" <[EMAIL PROTECTED]>
> Cc: "PHP Lists" <[EMAIL PROTECTED]>
> Sent: Saturday, January 17, 2004 7:28 AM
> Subject: Re: [PHP] Image Header Issues
>
> This is a known issue with IE. And it is in their knowledge base. If I
> recall the fix is to clear the cache, cookies, and broken/corrupt
> objects.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---
OK, that's it.  The session_start() is the issue.  Unfortunately, the
"&img=x.jpg" didn't help.

Now I've got to figure out some sorta security without using sessions.

Thanks, for at least pointing me in the right direction.  Now if we could
figure out why this would be happening, that would be great.

Bob

----- Original Message ----- 
From: "Toby Irmer" <[EMAIL PROTECTED]>
To: "Larry Brown" <[EMAIL PROTECTED]>; "Bob Eldred"
<[EMAIL PROTECTED]>; "PHP List" <[EMAIL PROTECTED]>
Sent: Saturday, January 17, 2004 2:11 PM
Subject: Re: [PHP] Image Header Issues


> I have the same problem. Strange: I have a session_start(); before the
> header... if I take that out, the image will download as a JPG... so maybe
> if you find a way to do things in this script without starting the session
> first...
>
> toby
>
>
> ----- Original Message -----
> From: "Larry Brown" <[EMAIL PROTECTED]>
> To: "Bob Eldred" <[EMAIL PROTECTED]>; "PHP List"
> <[EMAIL PROTECTED]>
> Sent: Saturday, January 17, 2004 6:32 PM
> Subject: RE: [PHP] Image Header Issues
>
>
> > try adding showpicture.php?pid=111384&img=x.jpg to the end even though
you
> > aren't using that variable, IE may see that the type is jpg here.  I
have
> > this same problem/workaround in place right now for a script that
wouldn't
> > work with IE without it for downloading pdf. (pdf was generated on the
> fly)
> >
> > -----Original Message-----
> > From: Bob Eldred [mailto:[EMAIL PROTECTED]
> > Sent: Saturday, January 17, 2004 12:00 PM
> > To: [EMAIL PROTECTED]
> > Subject: Re: [PHP] Image Header Issues
> >
> >
> > Again, it is *not* that known issue.  That's the very first thing I
> checked.
> > If that were the issue, jpgs from other sources would also not save
> > properly.  But they do, as I've stated several times.
> >
> > Thanks, though.
> >
> > Bob
> >
> > ----- Original Message -----
> > From: "Brian V Bonini" <[EMAIL PROTECTED]>
> > To: "Bob Eldred" <[EMAIL PROTECTED]>
> > Cc: "PHP Lists" <[EMAIL PROTECTED]>
> > Sent: Saturday, January 17, 2004 7:28 AM
> > Subject: Re: [PHP] Image Header Issues
> >
> > This is a known issue with IE. And it is in their knowledge base. If I
> > recall the fix is to clear the cache, cookies, and broken/corrupt
> > objects.
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
>

--- End Message ---
--- Begin Message ---
Giving up sessions for one simple issue sounds a bit drastic.  I'll dig up
the header information I'm sending that the x.pdf addition helped me with
and send them to you if you'd like.  I can't see anything as strong/secure
as sessions to manage authentication as well as a dozen other performance
benefits.

Larry.

-----Original Message-----
From: Bob Eldred [mailto:[EMAIL PROTECTED]
Sent: Saturday, January 17, 2004 11:30 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Image Header Issues


OK, that's it.  The session_start() is the issue.  Unfortunately, the
"&img=x.jpg" didn't help.

Now I've got to figure out some sorta security without using sessions.

Thanks, for at least pointing me in the right direction.  Now if we could
figure out why this would be happening, that would be great.

Bob

----- Original Message -----
From: "Toby Irmer" <[EMAIL PROTECTED]>
To: "Larry Brown" <[EMAIL PROTECTED]>; "Bob Eldred"
<[EMAIL PROTECTED]>; "PHP List" <[EMAIL PROTECTED]>
Sent: Saturday, January 17, 2004 2:11 PM
Subject: Re: [PHP] Image Header Issues


> I have the same problem. Strange: I have a session_start(); before the
> header... if I take that out, the image will download as a JPG... so maybe
> if you find a way to do things in this script without starting the session
> first...
>
> toby
>
>
> ----- Original Message -----
> From: "Larry Brown" <[EMAIL PROTECTED]>
> To: "Bob Eldred" <[EMAIL PROTECTED]>; "PHP List"
> <[EMAIL PROTECTED]>
> Sent: Saturday, January 17, 2004 6:32 PM
> Subject: RE: [PHP] Image Header Issues
>
>
> > try adding showpicture.php?pid=111384&img=x.jpg to the end even though
you
> > aren't using that variable, IE may see that the type is jpg here.  I
have
> > this same problem/workaround in place right now for a script that
wouldn't
> > work with IE without it for downloading pdf. (pdf was generated on the
> fly)
> >
> > -----Original Message-----
> > From: Bob Eldred [mailto:[EMAIL PROTECTED]
> > Sent: Saturday, January 17, 2004 12:00 PM
> > To: [EMAIL PROTECTED]
> > Subject: Re: [PHP] Image Header Issues
> >
> >
> > Again, it is *not* that known issue.  That's the very first thing I
> checked.
> > If that were the issue, jpgs from other sources would also not save
> > properly.  But they do, as I've stated several times.
> >
> > Thanks, though.
> >
> > Bob
> >
> > ----- Original Message -----
> > From: "Brian V Bonini" <[EMAIL PROTECTED]>
> > To: "Bob Eldred" <[EMAIL PROTECTED]>
> > Cc: "PHP Lists" <[EMAIL PROTECTED]>
> > Sent: Saturday, January 17, 2004 7:28 AM
> > Subject: Re: [PHP] Image Header Issues
> >
> > This is a known issue with IE. And it is in their knowledge base. If I
> > recall the fix is to clear the cache, cookies, and broken/corrupt
> > objects.
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
>

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

--- End Message ---
--- Begin Message ---
Hi Larry,

of course just having to give up sessions doesn't sound very attractive. I
tried adding &img=... to the url that calls the script. Only it didn't help.
If you would be so kind as to post your code, maybe I will be able to find
my error.
If not, I will just have to live without the session_start, and pass the
variables I need in the query string. It is not that you have to abolish
sessions altogether. Just in the one tiny script that displays the image.

toby
----- Original Message -----
From: "Larry Brown" <[EMAIL PROTECTED]>
To: "Bob Eldred" <[EMAIL PROTECTED]>; "PHP List"
<[EMAIL PROTECTED]>
Sent: Sunday, January 18, 2004 5:45 AM
Subject: RE: [PHP] Image Header Issues


> Giving up sessions for one simple issue sounds a bit drastic.  I'll dig up
> the header information I'm sending that the x.pdf addition helped me with
> and send them to you if you'd like.  I can't see anything as strong/secure
> as sessions to manage authentication as well as a dozen other performance
> benefits.
>
> Larry.
>
> -----Original Message-----
> From: Bob Eldred [mailto:[EMAIL PROTECTED]
> Sent: Saturday, January 17, 2004 11:30 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] Image Header Issues
>
>
> OK, that's it.  The session_start() is the issue.  Unfortunately, the
> "&img=x.jpg" didn't help.
>
> Now I've got to figure out some sorta security without using sessions.
>
> Thanks, for at least pointing me in the right direction.  Now if we could
> figure out why this would be happening, that would be great.
>
> Bob
>
> ----- Original Message -----
> From: "Toby Irmer" <[EMAIL PROTECTED]>
> To: "Larry Brown" <[EMAIL PROTECTED]>; "Bob Eldred"
> <[EMAIL PROTECTED]>; "PHP List" <[EMAIL PROTECTED]>
> Sent: Saturday, January 17, 2004 2:11 PM
> Subject: Re: [PHP] Image Header Issues
>
>
> > I have the same problem. Strange: I have a session_start(); before the
> > header... if I take that out, the image will download as a JPG... so
maybe
> > if you find a way to do things in this script without starting the
session
> > first...
> >
> > toby
> >
> >
> > ----- Original Message -----
> > From: "Larry Brown" <[EMAIL PROTECTED]>
> > To: "Bob Eldred" <[EMAIL PROTECTED]>; "PHP List"
> > <[EMAIL PROTECTED]>
> > Sent: Saturday, January 17, 2004 6:32 PM
> > Subject: RE: [PHP] Image Header Issues
> >
> >
> > > try adding showpicture.php?pid=111384&img=x.jpg to the end even though
> you
> > > aren't using that variable, IE may see that the type is jpg here.  I
> have
> > > this same problem/workaround in place right now for a script that
> wouldn't
> > > work with IE without it for downloading pdf. (pdf was generated on the
> > fly)
> > >
> > > -----Original Message-----
> > > From: Bob Eldred [mailto:[EMAIL PROTECTED]
> > > Sent: Saturday, January 17, 2004 12:00 PM
> > > To: [EMAIL PROTECTED]
> > > Subject: Re: [PHP] Image Header Issues
> > >
> > >
> > > Again, it is *not* that known issue.  That's the very first thing I
> > checked.
> > > If that were the issue, jpgs from other sources would also not save
> > > properly.  But they do, as I've stated several times.
> > >
> > > Thanks, though.
> > >
> > > Bob
> > >
> > > ----- Original Message -----
> > > From: "Brian V Bonini" <[EMAIL PROTECTED]>
> > > To: "Bob Eldred" <[EMAIL PROTECTED]>
> > > Cc: "PHP Lists" <[EMAIL PROTECTED]>
> > > Sent: Saturday, January 17, 2004 7:28 AM
> > > Subject: Re: [PHP] Image Header Issues
> > >
> > > This is a known issue with IE. And it is in their knowledge base. If I
> > > recall the fix is to clear the cache, cookies, and broken/corrupt
> > > objects.
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> >
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---
On 星期日 18 [EMAIL PROTECTED] 2004 01:59, Scott Taylor wrote:

> Yes, sorry. Here is the code: $file =
> 'http://miningstocks.com/protected/archive/Dec03PostPress.pdf'; //now
> view the PDF file header("Content-Type: application/pdf");
> header("Accept-Ranges: bytes"); header("Content-Length:
> ".filesize($file)); readfile($file); I can send the rest if necessary.

You're telling PHP to get the file using HTTP, thus subjecting it to Apache's 
protection mechanism.

You need to get the file via the filesystem:

  readfile('/local/path/to/file.pdf');

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
/*
The absence of labels [in ECL] is probably a good thing.
                -- T. Cheatham
*/

--- End Message ---
--- Begin Message --- On Friday, January 16, 2004, at 11:57 PM, Robert Temple wrote:

In particular, Justin French solved the problem with just a few lines of code - the sign of a true genius. Thanks again, Justin!

LMFAO -- that's two compliments off this list in a few days... I should start a consultancy :P

Justin French
--- End Message ---
--- Begin Message ---
Hey,

Only problem with that idea is most of the people who ask for help here
are broke SOBs like me.... :-)

Cheers,
-Ryan

On 1/18/2004 4:11:21 AM, Justin French ([EMAIL PROTECTED]) wrote:
> On Friday, January 16, 2004, at 11:57  PM, Robert Temple wrote:
> 
> > In particular, Justin French solved the problem with just a few lines
> > of code - the sign of a true genius. Thanks again, Justin!
> 
> LMFAO -- that's two compliments off this list in a few days... I should
> start a consultancy :P
> 
> Justin French
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

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

I am curious if there is anyway to take a variable that is passed via a
URL by a reguler text hyperlink

Ex: http://localhost/Calendar/active_layout.php?d=2.1.2004

and hide it like you would do with the POST method using forms

Ex: http://localhost/Calendar/active_layout.php

Hidden or POSTed part: d=2.1.2004

It seems like I saw some WML code that did something like this

Thanks in advance,
Joe

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

Sunday, January 18, 2004, 3:26:18 AM, you wrote:

JH> I am curious if there is anyway to take a variable that is passed via a
JH> URL by a reguler text hyperlink

JH> Ex: http://localhost/Calendar/active_layout.php?d=2.1.2004

JH> and hide it like you would do with the POST method using forms

Not really, no. One solution might be to use mod_rewrite on Apache so
at least it could look like:

http://localhost/Calendar/active_layout/d/2.1.2004

(or something like that).

-- 
Best regards,
 Richard                            mailto:[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
Thanks Richard... I will do some erading on that

Cheers!
Joe

-----Original Message-----
From: Richard Davey [mailto:[EMAIL PROTECTED] 
Sent: Saturday, January 17, 2004 11:08 PM
To: Joe Harman
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] POST method for hyperlink


Hello Joe,

Sunday, January 18, 2004, 3:26:18 AM, you wrote:

JH> I am curious if there is anyway to take a variable that is passed 
JH> via a URL by a reguler text hyperlink

JH> Ex: http://localhost/Calendar/active_layout.php?d=2.1.2004

JH> and hide it like you would do with the POST method using forms

Not really, no. One solution might be to use mod_rewrite on Apache so at
least it could look like:

http://localhost/Calendar/active_layout/d/2.1.2004

(or something like that).

-- 
Best regards,
 Richard                            mailto:[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
I'm creating a form that puts data into two different tables in the
database.  I was wondering how to get the "ID" from the first table and, in
the "background", associate it with the second table?

any help is GREATLY appreciated!

--- End Message ---
--- Begin Message ---
> I'm creating a form that puts data into two different tables in the
> database.  I was wondering how to get the "ID" from the first table
> and, in the "background", associate it with the second table?
>
> any help is GREATLY appreciated!
>

Firstly you never said which db ? I'll assume mysql, check out
mysql_insert_id


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

--- End Message ---
--- Begin Message --- On Sunday, January 18, 2004, at 01:39 PM, eawilkes wrote:

I'm creating a form that puts data into two different tables in the
database. I was wondering how to get the "ID" from the first table and, in
the "background", associate it with the second table?

any help is GREATLY appreciated!

Check out mysql_insert_id() -- there's an example in the manual of how to determine what was the ID of the row you just inserted.

http://www.php.net/mysql_insert_id

FYI, this page was easy to find searching the PHP manual functions for "mysql id" -- perhaps a timely reminder that you should search the manual before posting a question???

Come back if you need more help after that.

Justin French
--- End Message ---
--- Begin Message ---
> Hi,
>
> I'm having troubles accessing the global variables.  From my understanding
> of PHP, when you declare a variable 'global' it is no longer just in the
> local scope, but becomes known in the global scope of the program.
>
> In file, 'layout.php' ...
>     function top_sidebar_header() {
>         global $g_graphic;
>         echo $g_graphic;
>     }
>
> In file, 'body.php' ...
>     include_once( $GLOBALS["DOCUMENT_ROOT"] . "/include/layout.php" );
>     top_sidebar_header();        // function is called, but when "echo
> $g_graphic" is executed,
>                                             // nothing prints out because
> $g_graphic is empty or ""
>
> In file, 'about/index.php' ...
>     $g_graphic = "/media/image.jpg";
>     include_once( $GLOBALS["DOCUMENT_ROOT"] . "/body.php" );
>
> Have I overlooked something crucial?
>
> I haven't been able to find much documentation on this topic.  (Please
keep
> in mind that I am also a newbie at PHP.  :) )  ~ It'd be really great if
any
> of you have suggestions on this.
>
> Thanks in advance,
> Adelaide
>

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

I'm having troubles accessing the global variables.  From my understanding
of PHP, when you declare a variable 'global' it is no longer just in the
local scope, but becomes known in the global scope of the program.

In file, 'layout.php' ...
    function top_sidebar_header() {
        global $g_graphic;
        echo $g_graphic;
    }

In file, 'body.php' ...
    include_once( $GLOBALS["DOCUMENT_ROOT"] . "/include/layout.php" );
    top_sidebar_header();        // function is called, but when "echo
$g_graphic" is executed,
                                            // nothing prints out because
$g_graphic is empty or ""

In file, 'about/index.php' ...
    $g_graphic = "/media/image.jpg";
    include_once( $GLOBALS["DOCUMENT_ROOT"] . "/body.php" );

Have I overlooked something crucial?

I haven't been able to find much documentation on this topic.  (Please keep
in mind that I am also a newbie at PHP.  :) )  ~ It'd be really great if any
of you have suggestions on this.

Thanks in advance,
Adelaide

--- End Message ---
--- Begin Message ---
Is it possible to have usernames from my db populated  into a drop down
list.
If so What and where does it go to make it all work, ive tried everything i
know
( which is not much by the way).

Mark

--- End Message ---
--- Begin Message --- Yes it's possible.  I believe there's a way to do it with PEAR also but I've never done it that way before.  I always do:

---

<SELECT name = "username">
    <OPTION selected>--- Please Choose a Username ---</OPTION>

    <?php

        // retrieve a list of usernames from the DB
        $results = mysql_query("SELECT userID, username FROM users")
            or die ("could not perform requested query");

        // make sure we got a list of usernames back
        if (mysql_num_rows($results) != 0)
        {
            // process the returned results
            for ($i = 0; $i < mysql_num_rows($results); $i++)
            {
                // get a row of results back from the result set
                $row = mysql_fetch_array($results);

                // construct the dropdown menu item
                echo "<OPTION value = \"" . $row["userID"] . "\">" . $row["username"] . "</OPTION>";
            }
        }
        else
        {
            echo "No names in the database";
        }

    ?>

</SELECT>

    Of course you need to embed this within a <FORM> tag.

-Pete

---

On Sun, 2004-01-18 at 01:18, BigMark wrote:
Is it possible to have usernames from my db populated  into a drop down
list.
If so What and where does it go to make it all work, ive tried everything i
know
( which is not much by the way).

Mark
-- 
perl -e 'print pack("H*", "70766572746573406E79632E72722E636F6D0A")'

Attachment: signature.asc
Description: This is a digitally signed message part


--- End Message ---
--- Begin Message ---
if you say you don't know much, maybe you are looking for something like this ;)

hth

toby

<?
function formSelect($name, $options, $value)
{
      echo "<select name=\"$name\">\n";
      foreach($options AS $key => $display)
      {
           echo " <option value=\"$key\"";
           if($value == $key) echo " SELECTED";
           echo ">$display</option>\n";
      }
      echo "</select>\n";
}

//get users from db
$query = "     SELECT * FROM users";
$result = mysql_query($query);

while($line = mysql_fetch_array($result))
{
    $options[$line["id"]] = $line["name"];
}

//write select
formSelect("users", $options, $_REQUEST["users"]); 
?>

--- End Message ---
--- Begin Message ---
Hi List,

I have a function that makes a call to mysql based on certain vars.

---example----

Function MyFunc(){
 if(isset($_POST[var])){
 $sql = mysql_query("select * from table_name where field=\"$_POST[var]\"
");
 $returnsomething ="blah blah";
 }
 return $returnsomething;
}

And that all works fine no probs here but.....

I want to use a result somewhere in my script that is not returned by
return. Let me show you...

---example----

Function MyFunc(){
 if(isset($_POST[var])){
 $sql = mysql_query("select * from table_name where field=\"$_POST[var]\"
");

 $num = mysql_num_rows($sql); // I want to use this result outside this
function.

$returnsomething ="blah blah";
 }
 return $returnsomething;
}

So $num contains a number that I want to use outside the function which is
not covered by return.

I know return stops a script and returns what I want it to return but how do
I send out of the function the var I want.

I have tried $GLOBAL[var]=$num; but that don’t work, but I thought I
would'nt anyway just tried it and yes I know I have to declare it inside my
new function using global $var; to use it.

So I ask is this achiveable or how can I do this.

Thank you in advance

Dave C


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.560 / Virus Database: 352 - Release Date: 08/01/2004
 


--- End Message ---

Reply via email to