php-general Digest 19 Aug 2007 11:43:44 -0000 Issue 4970
Topics (messages 261005 through 261013):
getting from one table listing from another
261005 by: Nate
261006 by: Stephen Johnson
261007 by: Jay Blanchard
Delete row in a lookup table
261008 by: nitrox .
261010 by: Larry Garfield
Re: Cookies and sent headers
261009 by: Kelvin Park
261011 by: Otto Wyss
Redirection with header (was Re: [PHP] Cookies and sent headers)
261012 by: Otto Wyss
Re: www.soongy.com
261013 by: Gevorg Harutyunyan
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 know this is kinda crazy but I need it :P
I have one table that lists name's
and I have another table that has the name's and points
I want to know how to list the name's of the first table by the points
of the second table
--- End Message ---
--- Begin Message ---
You might try sending this to a group that is more orientated towards data
basing.. Since that seems to be what your asking about...
On 8/18/07 3:53 PM, "Nate" <[EMAIL PROTECTED]> wrote:
> I know this is kinda crazy but I need it :P
> I have one table that lists name's
> and I have another table that has the name's and points
> I want to know how to list the name's of the first table by the points
> of the second table
--
Stephen Johnson
The Lone Coder
http://www.myonlinepros.com
*How can we help you today?*
[EMAIL PROTECTED]
http://www.thelonecoder.com
*Continuing the struggle against bad code*
--
--- End Message ---
--- Begin Message ---
[snip]
I know this is kinda crazy but I need it :P
I have one table that lists name's
and I have another table that has the name's and points
I want to know how to list the name's of the first table by the points
of the second table
[/snip]
Not crazy, pretty standard from a database point of view;
SELECT a.name, b.points
FROM table a LEFT OUTER JOIN table b
ON(a.name = b.name)
This only works if the name in table a matches a name in table b.
--- End Message ---
--- Begin Message ---
Hi all,
Is it not considered good practice to have a primary key on a lookup table for
a database?
I have 3 tables setup, games, memberleagues and members. The memberleagues
table holds the id of the games table and members table. The problem I have is
that Im not sure how to delete a row from the memberleagues table without a
primary key. If its not considered bad practice I could add a primary key to
the memberleagues table and be done. Anybody have any tutorials on how to write
the php for this?
_________________________________________________________________
Messenger Café — open for fun 24/7. Hot games, cool activities served daily.
Visit now.
http://cafemessenger.com?ocid=TXT_TAGLM_AugWLtagline
--- End Message ---
--- Begin Message ---
Whether or not it's good practice depends on who you ask. :-)
Every table should have a primary key. Primary keys, however, may span
multiple columns. That's perfectly legal. In some cases that primary key
may span every column, but generally that's a sign of bad design unless
you're talking about a table that just relates one table to another (many to
many relation).
The question is whether it's better to have a surrogate key[1]. That is, a
unique integer value that has no meaning itself beyond being a unique key.
For example, in pretty much any authentication system the username will be
unique, and therefore could easily be used as the primary key. Other tables,
then, would reference back to the user table using the username as the
foreign key.
There's pros and cons to surrogate keys over "natural" keys. See more links
below that I don't feel like repeating[2].
Personaly I tend toward surrogate keys in most cases for entities, but not for
relationships. In your case, then, no, I would not have a surrogate key on
the membersleagues table. Instead I'd define (game_id, member_id) as the
primary key. You can absolutely then DELETE from membersleagues WHERE
game_id=4 AND member_id=3. Or just delete by one or the other. You don't
have to have a primary key defined in order to be able to DELETE, it's just
frequently simpler if you do. You can write a WHERE clause on anything.
In practice, I generally find it easier to do a delete/rebuild than to try and
track an extra surrogate key. That is, I'd do something like:
$db->query("DELETE FROM foo WHERE thing_id=5");
foreach ($foo->things as $thing_id) {
$db->query("INSERT INTO foo (foo_id, thing_id) VALUES (5, $thing_id)");
}
(Actually I wouldn't do that. I'd use prepared statements because just
inserting the variable into the string like that is a security risk. Don't
do it. It's just easier to explain without the prepared statement for now.)
That should be fine unless $foo->things is rather large or is very frequently
edited (for some defintions of large and frequent).
Cheers.
[1] http://en.wikipedia.org/wiki/Surrogate_key
[2]
http://www.bcarter.com/intsurr1.htm
http://r937.com/20020620.html
http://articles.techrepublic.com.com/5100-22-1045050.html
On Saturday 18 August 2007, nitrox . wrote:
> Hi all,
> Is it not considered good practice to have a primary key on a lookup table
> for a database? I have 3 tables setup, games, memberleagues and members.
> The memberleagues table holds the id of the games table and members table.
> The problem I have is that Im not sure how to delete a row from the
> memberleagues table without a primary key. If its not considered bad
> practice I could add a primary key to the memberleagues table and be done.
> Anybody have any tutorials on how to write the php for this?
> _________________________________________________________________
> Messenger Café — open for fun 24/7. Hot games, cool activities served
> daily. Visit now. http://cafemessenger.com?ocid=TXT_TAGLM_AugWLtagline
--
Larry Garfield AIM: LOLG42
[EMAIL PROTECTED] ICQ: 6817012
"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson
--- End Message ---
--- Begin Message ---
---------- Forwarded message ----------
From: Kelvin Park <[EMAIL PROTECTED]>
Date: Aug 18, 2007 4:34 PM
Subject: Re: [PHP] Cookies and sent headers
To: "M. Sokolewicz" <[EMAIL PROTECTED]>
the javascript code can definitely change to head("location: whatever.php")
for redirection, if that's the solution, that would be the way to go, but if
you're encountering quite similar problems later you can try ob_start() or
whatever that was recommended in the comments before M. Sokolewicz's
bullshitting comment.
On 8/18/07, M. Sokolewicz <[EMAIL PROTECTED]> wrote:
>
> bullshit,
>
> what he sees is a warning emitted by PHP, his redirect is done using
> JavaScript (which is clientside and has no, 0.0 effect on what PHP
> emits). Now, I'm not going to go into how redirecting that way won't
> work (or at least shouldn't), but a hint would be to do it properly
> using header('Location: [...]') instead.
>
> - Tul
>
>
> Sanjeev N wrote:
> > Hi,
> > Its not the problem of cookies. Its problem of redirection or the
> > parent.location.replace function. I mean if you already output something
> on
> > the page and tries to redirect then this problem happens.
> >
> > Redirect before outputting anything on the page.. like space is also an
> > output.
> >
> > Warm Regards,
> > Sanjeev
> > http://www.sanchanworld.com/
> > http://webdirectory.sanchanworld.com - Submit your website URL
> > http://webhosting.sanchanworld.com - Choose your best web hosting plan
> > -----Original Message-----
> > From: Otto Wyss [mailto:[EMAIL PROTECTED]
> > Sent: Saturday, August 18, 2007 2:56 PM
> > To: [EMAIL PROTECTED]
> > Subject: [PHP] Cookies and sent headers
> >
> > If built a simple login page and store any information within
> > $_SESSION's. Yet I'd like to move these into cookies but I always get an
>
> > error about sent headers. Is there a way to circumvent this problem
> > without changing too much in the page?
> >
> > The setting of the cookies happens just at the end of the page.
> >
> > if (!$errortext and $Anmelden) {
> > if (!empty($Permanent)) {
> > $expires = time()+ 365 * 86400; // 365 days
> > setcookie ("l.Lastname", $_SESSION['l_Lastname'], $expires);
> > setcookie (" l.Firstname", $_SESSION['l_Firstname'], $expires);
> > setcookie ("l.Email1", $_SESSION['l_Email1'], $expires);
> > setcookie ("l.Email2", $_SESSION['l_Email2'], $expires);
> > }
> > echo "<script type=\"text/javascript\">
> > parent.location.replace('$index_php";
> > </script>";
> > exit;
> > }
> >
> > O. Wyss
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
M. Sokolewicz wrote:
On a sidenote, 99% of the world never calls ob_flush (or any such
function) since PHP flushes the buffer automatically at the end of its
execution.
I'll keep the ob_end_flush just for showing what's going on, but thanks
for the hint.
The reason why setting cookies for you doesn't work is because of the
way a HTTP response is structured. It consists of 2 parts: header and
body separated by 2 new lines (\n\n). It is _required_ that _all_
headers come _before_ the body. Cookies are actually headers (a
set-cookie: [...] header) aswell as any headers set via php's header()
function. Any output made by the script (be it a single whitespace, a
bunch of text, etc.) will automatically flush the headers, followed by
the separator (\n\n) followed by the specified output. After that has
been sent, everything outputted will be dumped into the body of the
response (simply because you can't "go back" to the headers which were
already sent earlier), so you can't set cookies (which are headers
themselves).
Thanks, now it's understandable.
So, why does output buffering help here? Simply put, instead of dumping
headers and any other output directly to the client, PHP buffers it all
into memory. As such, since it hasn't been sent yet, PHP can still
alter/add headers even though it also has body-output. Once it receives
the command, PHP will send all headers, the separator and the output to
the client. This is done when PHP encounters an ob_flush or ob_end_flush
call, _and_ when the script has finished execution automatically.
The documentation seems pretty clear to me, however, if you feel it
should be clarified better, feel free to send a patch to the
[EMAIL PROTECTED] list.
- Tul
O. Wyss
--- End Message ---
--- Begin Message ---
M. Sokolewicz wrote:
emits). Now, I'm not going to go into how redirecting that way won't
work (or at least shouldn't), but a hint would be to do it properly
using header('Location: [...]') instead.
I'm aware that using Javascript within a PHP code block doesn't seems
logical yet I haven't known header ('Location...). In my case I could
easilly do without redirection but just exit and fall back on the
calling page. Yet I want to remove the login page from the browser
history. Does the header function have the same effect?
O. Wyss
--- End Message ---
--- Begin Message ---
Hi,
Sorry for late response.
The main idea is in sending text messages using email, SMS, our messaging
service. Also you can hold some web notes there.
I agree it is not good for now.
This is just start of this project.
I am trying to do one step to WEB2 world.
You can look http://www.netvibes.com , http://www.pageflakes.com/
I mean DHTML, PHP, AJAX can do fantastic things
If you have better idea tell me please
Thank you Dan very much
Best, Gevorg
-----Original Message-----
From: Dan [mailto:[EMAIL PROTECTED]
Sent: Saturday, August 18, 2007 4:05 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Re: www.soongy.com
What is this supposed to be exactly? I gather from looking at it quickly
that uses can signup, then send messages to other signed up users right?
So it's like email, but you can only send messages to other people that
signup, and login through that specific webpage. Forgive me but I don't see
the appeal, what is this for?
- Dan
""Gevorg Harutyunyan"" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello,
>
>
>
> I am Gevorg.
>
> I just wanted to introduce you my new PHP based work here www.soongy.com
> <http://www.soongy.com/> .
>
> It is working on PHP and MySQL and here is used DHTML, AJAX.
>
>
>
> Thank you very much.
>
>
>
> Waiting for your response
>
>
>
> Regards,
>
> Gevorg
>
>
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---