php-general Digest 30 Oct 2006 12:14:15 -0000 Issue 4430

Topics (messages 243852 through 243878):

Re: Decide witch table within a union
        243852 by: Chris
        243853 by: Ed Lazor
        243858 by: Paul Novitski
        243860 by: Ed Lazor
        243861 by: Richard Lynch
        243867 by: Paul Novitski
        243872 by: Ed Lazor

socket_recv
        243854 by: Eric
        243856 by: Ed Lazor

Re: IMAP functions for NNTP
        243855 by: Chris

array, classes and values
        243857 by: martin
        243869 by: Chris

Re: Is there such a thing?
        243859 by: Chris
        243866 by: Richard Lynch

Re: strange problem with count()
        243862 by: Richard Lynch

Re: Query question
        243863 by: Richard Lynch
        243875 by: Ivo F.A.C. Fokkema

Re: A general UL script
        243864 by: Richard Lynch
        243878 by: Børge Holen

Re: Uploading files.
        243865 by: Richard Lynch

Re: How do I get ini_set('output_handler', '') to work?!
        243868 by: Richard Lynch

Re: Non-blocking sockets
        243870 by: Richard Lynch

Re: counting records in db
        243871 by: Richard Lynch
        243873 by: Richard Lynch
        243874 by: Ivo F.A.C. Fokkema
        243877 by: Robin Vickery

Imagecopyresampled creates black pictures
        243876 by: Martin Hochreiter

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 ---
Børge Holen wrote:
Ok.

Would you suggest to use a extra field to hold the table name as default?

Why do you need to know which table it's in? What are you going to use it for in the next step? I see you're passing it in:

echo "<a href=\"index.php?table=$table_nr">page</a>";

but what are you going to do with it?

I think if you explain what you're trying to achieve as an end result, people might be able to give you better options.

Basically php can't give you extra information than the query itself does.. whatever the query does in mysql, is exactly what it will do when run through php.

--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message --- Definitely not. Review your design. If you need to know which table data comes from, then perform table specific queries. If you need to combine data from more than one table, code your application to respond accordingly. You may also need to review your database schema design in order that it best meet your needs.

On Oct 29, 2006, at 2:00 PM, Børge Holen wrote:

Would you suggest to use a extra field to hold the table name as default?


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

On Oct 29, 2006, at 2:00 PM, Børge Holen wrote:

Would you suggest to use a extra field to hold the table name as
default?

At 10/29/2006 04:16 PM, Ed Lazor wrote:
Definitely not.  Review your design.  If you need to know which table
data comes from, then perform table specific queries.  If you need to
combine data from more than one table, code your application to
respond accordingly.  You may also need to review your database
schema design in order that it best meet your needs.


That seems unreasonably harsh. What in your view is wrong with a union query that preserves an indicator of which component table a particular record comes from?

I can easily imagine a circumstance in which this could be valuable, say the union of several mailing lists that are in separate tables simply because they originate from different sources. We union them to print a single alphabetical list, for example, but we want an indicator as to the source of each record.

I can imagine modifying the OP's query to read:

$sql=" (select '1' as tableId, * from table_1 WHERE pid='0' order by id desc limit 10) union (select '2' as tableId, * from table_2 WHERE pid='0' order by id desc limit 10) union (select '3' as tableId, * from table_3 WHERE pid='0' order by id desc limit 10) union (select '4' as tableId, * from table_4 WHERE pid='0' order by id desc limit 10)
        order by date desc limit 10     ";

Would this be so egregious? and if so why?

You say,
If you need to combine data from more than one table,
code your application to respond accordingly.

What does this mean, exactly? Surely you're not suggesting that we code an application to somehow divine the source of a record in a union query when the query itself could simply supply that datum easily.

Curiously,
Paul

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

That seems unreasonably harsh.

I can see what you mean, but don't take it that way. I was trying to help.


What in your view is wrong with a union query that preserves an indicator of which component table a particular record comes from?

Read earlier in the thread. He's talking about adding a field to the table and that the value of this field in every single record will be the name of the table the record belongs to. I said I would definitely not recommend doing that.

I can easily imagine a circumstance in which this could be valuable, say the union of several mailing lists that are in separate tables simply because they originate from different sources. We union them to print a single alphabetical list, for example, but we want an indicator as to the source of each record.

I can imagine modifying the OP's query to read:

$sql=" (select '1' as tableId, * from table_1 WHERE pid='0' order by id desc limit 10) union (select '2' as tableId, * from table_2 WHERE pid='0' order by id desc limit 10) union (select '3' as tableId, * from table_3 WHERE pid='0' order by id desc limit 10) union (select '4' as tableId, * from table_4 WHERE pid='0' order by id desc limit 10)
        order by date desc limit 10     ";

Would this be so egregious? and if so why?

I think this is a great solution, wish I'd thought of it.  =)


You say,
If you need to combine data from more than one table,
code your application to respond accordingly.

What does this mean, exactly?

I'm just talking about intelligent programming.

Surely you're not suggesting that we code an application to somehow divine the source of a record in a union query when the query itself could simply supply that datum easily.

Of course not. Honestly, I think you're just being critical of what I said, because you thought I was being harsh and unfair when I wasn't actually trying to be.

-Ed

--- End Message ---
--- Begin Message ---
On Sun, October 29, 2006 3:34 pm, Børge Holen wrote:
> Hi.
> I got this working (almost)
> How do I decide (inside?) the whileloop the table_nr, 1 to 4 witch the
> link is
> echo'ed from.
>
> I could add another field in each table telling witch table it is.
> Easy
> solution, but feels like polluting the db.
>
> Also I could do another loop to check another of the printed fields up
> agains
> witch table is used, but that adding to the slowness of this union
> stuff, it
> would take forever, if the union in itself is slow or the fact that
> I'm
> cutting the message field after 100 characters I dunno.
>
> This is anyway the main code wherein the problem lies:
>
> $sql="        (select * from table_1 WHERE pid='0' order by id desc limit 10)

select *, 'table_1' from table_1 ...

> union
>               (select * from table_2 WHERE pid='0' order by id desc limit 10)

select *, 'table_2' from table_2 ...

This gives you an extra field with the table name in it.

You may not be able to use * any more, and have to name all the fields
you actually want.

Which is a better practice anyway.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

--- End Message ---
--- Begin Message ---
At 10/29/2006 08:04 PM, Ed Lazor wrote:

That seems unreasonably harsh.

I can see what you mean, but don't take it that way.  I was trying to
help.

Sorry, Ed, I had intended my reply to be friendly as well. I'm allergic to smiley-face icons, but I should have tried harder to convey my tone. Dang this poker-faced email!


What in your view is wrong with a union query that preserves an
indicator of which component table a particular record comes from?

Read earlier in the thread.  He's talking about adding a field to the
table and that the value of this field in every single record will be
the name of the table the record belongs to.  I said I would
definitely not recommend doing that.

Me neither. You're right. I was only referencing his next email in which he said,
Would you suggest to use a extra field to hold the table name as default?
which I thought was a great idea, but only because I thought he meant the query.

Warm regards,
Paul
--- End Message ---
--- Begin Message ---

Sorry, Ed, I had intended my reply to be friendly as well. I'm allergic to smiley-face icons, but I should have tried harder to convey my tone. Dang this poker-faced email!

No worries.  It's all good :)

-Ed

--- End Message ---
--- Begin Message --- Is there a reccomended size of data to pull in with socket_recv (Such as 1024) or can I pull in 981132487 and it wont make a difference? Thanks in advance.
--- End Message ---
--- Begin Message --- Depends on the volume and type of data that you're working with. It also depends on the type of connection between the server and client. Slower connections, unreliable connections, or general data, use smaller packets. Reliable connection or higher volumes of data, use larger packets. Think of it this way, the entire packet of data gets resent if there's an error and this could be costly time-wise if your packets are huge.



On Oct 29, 2006, at 4:41 PM, Eric wrote:

Is there a reccomended size of data to pull in with socket_recv (Such as 1024) or can I pull in 981132487 and it wont make a difference? Thanks in advance.

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


--- End Message ---
--- Begin Message ---
Eric wrote:
How would I go about listing all newsgroups via the IMAP functions?

Maybe http://www.php.net/manual/en/function.imap-list.php ?

It mentions "mailboxes" but the imap functions work for news & imap accounts.
--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
hello,

New to oop i'm really strugling to find a way to read a specified MYSQL 
database and tabel in order to determine the number of records, the number 
of fields in each record and convert the data into their labels and values.

Please give me some hints or code...

Thanks,

Martin 

--- End Message ---
--- Begin Message ---
martin wrote:
hello,

New to oop i'm really strugling to find a way to read a specified MYSQL database and tabel in order to determine the number of records, the number of fields in each record and convert the data into their labels and values.

I suggest you search for "php mysql tutorial" in your favourite search engine. There are tons of resources out there to help you with this stuff.

--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
Tom Atkinson wrote:
http://gtk.php.net/

Integz wrote:
http://www.evilbitz.com/2006/10/27/local-php-standalone-binaries-2/



Another interesting one is http://winbinder.org/ but it's windows only.

--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
On Fri, October 27, 2006 5:46 pm, Integz wrote:
> http://www.evilbitz.com/2006/10/27/local-php-standalone-binaries-2/

I responded in that forum.

Short Version:

No.

Check out:
http://gtk.php.net/

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

--- End Message ---
--- Begin Message ---
On Sun, October 29, 2006 6:27 am, Gunnar Beushausen wrote:
> I've a strange problem with count. I wrote a routine to jump to the
> last
> position of an array.

You mean kind of like this one?
http://php.net/end
:-)

I also suspect you are not doing count() on the right thing...

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

--- End Message ---
--- Begin Message ---
On Sun, October 29, 2006 2:06 am, Beauford wrote:
> This is how I get the data and I have no control over the actual
> layout of
> the database. So I have to work with what I have.

When you say it's "how you get the data" are they handing you a MySQL
database that is this badly-constructed?

Or are you importing data whose dates are in 'mm/dd/yyyy' format, and
failing to realize that you CAN and SHOULD convert those to date as
part of your import process.

> LOL, I don't know either. The format is - 01/01/2006. When I first did
> it I
> used 7, which should be right, but I ended up getting /2002 /2003,
> etc. So I
> went to 8 and all was well. Beats me.....

Dollars to donuts says your 'date' (which is really a string) has some
leading spaces which is messing up your count...

Of course, after you fix the import process to have an actual DATE in
your DB, this will be a non-issue...

Short-term, you should probably at least trim() the data so that your
offset of 8 is the number you would expect...

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

--- End Message ---
--- Begin Message ---
On Sun, 29 Oct 2006 23:04:27 -0600, Richard Lynch wrote:
> On Sun, October 29, 2006 2:06 am, Beauford wrote:
>> LOL, I don't know either. The format is - 01/01/2006. When I first did
>> it I
>> used 7, which should be right, but I ended up getting /2002 /2003,
>> etc. So I
>> went to 8 and all was well. Beats me.....
> 
> Dollars to donuts says your 'date' (which is really a string) has some
> leading spaces which is messing up your count...
> 
> Of course, after you fix the import process to have an actual DATE in
> your DB, this will be a non-issue...
> 
> Short-term, you should probably at least trim() the data so that your
> offset of 8 is the number you would expect...

Or, you use RIGHT(date, 4) as I believe MySQL always automatically removes
trailing spaces in VARCHAR columns. It will save you the use of one
additional function and RIGHT() may even be faster than SUBSTRING()
because it doesn't need to go through the entire string. But that's just
guessing and I think you probably won't even notice this in microseconds :)

Ivo

--- End Message ---
--- Begin Message ---
On Sat, October 28, 2006 4:06 pm, Børge Holen wrote:
> I'm trying to validate wether or not to run the image check script.
> however empty the file field(s) are This script is started... how do I
> tell it
> there is nothing here, go do other stuff.
> for both multiupload forms and single upload forms since they're
> supposed to
> share this script. My logic tells me there should be something like
> this if
> statements, but then again, I'm more of a copy paster rather than a
> expert.

Read the documentation about what will and won't happen if the user
does or doesn't fill in one or more FILE inputs:
http://us3.php.net/manual/en/features.file-upload.php

There is nothing at all tricky in this, really, if you read the docs...

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

--- End Message ---
--- Begin Message ---
On Monday 30 October 2006 06:08, Richard Lynch wrote:
> On Sat, October 28, 2006 4:06 pm, Børge Holen wrote:
> > I'm trying to validate wether or not to run the image check script.
> > however empty the file field(s) are This script is started... how do I
> > tell it
> > there is nothing here, go do other stuff.
> > for both multiupload forms and single upload forms since they're
> > supposed to
> > share this script. My logic tells me there should be something like
> > this if
> > statements, but then again, I'm more of a copy paster rather than a
> > expert.
>
> Read the documentation about what will and won't happen if the user
> does or doesn't fill in one or more FILE inputs:
> http://us3.php.net/manual/en/features.file-upload.php
>
> There is nothing at all tricky in this, really, if you read the docs...

Well... I've made one from that page, read all 'bout it.
See, the problem lies in the multifile uploader form;

* First it insert an empty file field (hidden).
* Second, I  rename all files to an md5 hash.
* Third, The md5 hash makes legal filenames witch enables my toolset to modify 
modify/validate my jpg.
* Forth and last moves them into my webtree.

The problem I seem to be getting at is this; How do I remove, lets say, file 
nr 3 of 6. The input fields can easily (because fields is removed and added 
dynamicly) be named everything from 'file_1' to 'file_20'. I only want jpg's
, so that gif in nr 3 has to be removed before the md5 hash rename. 

I could use splice_array to get at it just as I do with the first empty one, 
but then again, how do I count down the fields to get to the non valid file 
types.

I got some functions I found somewhere, that actually does this whole thing... 
except the md5, witch leads to some filename corruptions 'cus of the 
characters we have here in norway/sweden/denmark, the famous øæå.
It handles both the filename extension(if not containong æøå) and empty 
fields.
But I rather build something from ground up so I can learn it well, instead of 
using code I've not put together myself.

>
> --
> Some people have a "gift" link here.
> Know what I want?
> I want you to buy a CD from some starving artist.
> http://cdbaby.com/browse/from/lynch
> Yeah, I get a buck. So?

-- 
---
Børge
Kennel Arivene 
http://www.arivene.net
---

--- End Message ---
--- Begin Message ---
On Sat, October 28, 2006 11:47 am, João Cândido de Souza Neto wrote:
> I´m in a big doubt about uploading files ins a safe way.
>
> I wont give permission for the web server user to write in some folder
> of my
> system and then use move_uploaded_file function in order to keep it
> secure.

The upload directory should NOT be in your web tree.

*BEFORE* you use move_uploaded_file() to put a file into your web
tree, you should run every reasonable check you can to prove to
yourself that the file is valid format and has content you actually
want.

If you are on a shared server and don't want PHP to have write access
to a directory in your web tree, then don't -- Just
move_uploaded_file() to another non web tree directory, and then write
a PHP script with http://php.net/readfile or http://php.net/fopen and
friends to serve up the files.  You can also keep a record in your DB
of which files were uploaded, along with some meta-data, so that you
can be sure your script only serves up the files you have already
vetted.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

--- End Message ---
--- Begin Message ---
On Fri, October 27, 2006 3:46 pm, Daevid Vincent wrote:
> What am I doing wrong...
>
> In my php.ini I have this for my web pages (and I want it):
>
>   output_handler = ob_gzhandler
>
> But this causes my command line script to not show output until the
> very
> end.
>
> I thought I could disable it at the top of a script, but it's not
> working!?!
>
> #!/usr/bin/php -q
> <?php
>   ini_set('output_handler', 'mb_output_handler');

TOO LATE!

The ob_start() has already kicked in by this point.

ob_flush() until there are no more buffers.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

--- End Message ---
--- Begin Message ---
On Fri, October 27, 2006 3:23 pm, Eric wrote:
> When I create a socket/stream that connects to a news sever and try to
> recv data from the socket when there is nothing there (Like if the
> server sends one line and I call recv twice) the socket freezes. I
> assume this is because using socket_create or fsockopen creates a
> blocking TCP/Stream socket by default. When I call
> socket_set_nonblock()
> and the socket_connect I get "A non-blocking operation could not be
> completed immediately". Could someone show me exactly how to create a
> non-blocking TCP/Stream socket? Thanks in advance.

First, to make the initial socket creation/connection not block, you use:
http://php.net/ini_set
on that one socket connection timeout thingie in php.ini I can't
remember right now.

*THEN* after you have the socket up and running, you use:
http://php.net/socket_set_block

At least, that's the way I remember it from the last time I played
this game...

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

--- End Message ---
--- Begin Message ---
On Fri, October 27, 2006 12:14 pm, [EMAIL PROTECTED] wrote:
>> And the header("Location: ...") requires a full URL.
> Why?

Because the docs say so?

Because some user agents will not do what you want them to if you don't?

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

--- End Message ---
--- Begin Message ---
On Fri, October 27, 2006 4:53 pm, Børge Holen wrote:
> On Friday 27 October 2006 19:34, Richard Lynch wrote:
>> And the header("Location: ...") requires a full URL.
>
> No it doesn't. but he's missing an ' at first glance

Yes, it does:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30

Note the use of 'absolute' within that section.

You can argue that they shouldn't have designed the spec that way.

You can argue that it "works" in all popular browsers.

But there ain't much to argue about what the spec says...

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

--- End Message ---
--- Begin Message ---
On Sun, 29 Oct 2006 23:40:47 -0600, Richard Lynch wrote:

> On Fri, October 27, 2006 4:53 pm, Børge Holen wrote:
>> On Friday 27 October 2006 19:34, Richard Lynch wrote:
>>> And the header("Location: ...") requires a full URL.
>>
>> No it doesn't. but he's missing an ' at first glance
> 
> Yes, it does:
> http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30
> 
> Note the use of 'absolute' within that section.

Although I always use a full URL as well, doesn't absolute just mean
non-relative? As in:
Location: /Protocols/rfc2616/rfc2616-sec14.html#sec14.30
(absolute URI)

Location: ./rfc2616-sec14.html#sec14.30
(relative URI)


> You can argue that they shouldn't have designed the spec that way.
> 
> You can argue that it "works" in all popular browsers.
> 
> But there ain't much to argue about what the spec says...

Agreed. One should always follow the spec.

--- End Message ---
--- Begin Message ---
On 30/10/06, Ivo F.A.C. Fokkema <[EMAIL PROTECTED]> wrote:
On Sun, 29 Oct 2006 23:40:47 -0600, Richard Lynch wrote:

> On Fri, October 27, 2006 4:53 pm, Børge Holen wrote:
>> On Friday 27 October 2006 19:34, Richard Lynch wrote:
>>> And the header("Location: ...") requires a full URL.
>>
>> No it doesn't. but he's missing an ' at first glance
>
> Yes, it does:
> http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30
>
> Note the use of 'absolute' within that section.

Although I always use a full URL as well, doesn't absolute just mean
non-relative? As in:
Location: /Protocols/rfc2616/rfc2616-sec14.html#sec14.30
(absolute URI)

Location: ./rfc2616-sec14.html#sec14.30
(relative URI)

If you need contextual information to make sense of the URI (such as
the server name from a previous request) then it's not absolute.

RFC 2396: Uniform Resource Identifiers

"An absolute identifier refers to a resource independent of the
context in which the identifier is used. In contrast, a relative
identifier refers to a resource by describing the difference within a
hierarchical namespace between the current context and an absolute
identifier of the resource."

-robin

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

I'm using imagecopyresampled to create thumbnails of
various pictures.

That works well except some pictures that imagecopyresampled
converts to small black thumbnails (although it converts it correctly
to a bigger size)

What is wrong here?

lg
Martin

(Suse Linux 10.1, Apache 2.2, gd 2.0.32, php 5.1)

--- End Message ---

Reply via email to