[PHP-DB] Re: OT - [PHP-DB] Advice to PHP beginners

2002-03-27 Thread -BD-


did the tabs get stripped in your mail, or is there a reason the code
couldn't be written like the following?
i'm curious, since this is the way i do 90% of my code - makes it easy to
see what's going on... but i dunno about performance or parsing impact
(never gave it much thought until now)...?

newbily yours...




- Original Message -
From: "Adam Royle" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, March 27, 2002 4:44 PM
Subject: [PHP-DB] Advice to PHP beginners


> Just some advice... You should use a consistent programming style,
> especially with PHP. You can read some guys advice here.
> http://www.phpbuilder.com/columns/tim20010101.php3?page=1
>
> Some of the advantages of having a consistent style, is when you are
> looking for bugs. If you look over your code and see something unusual,
> then you can target that area to see if it is the culprit. If you don't
> have a consistent style, then sometimes that can cause serious
> heartache, as everything will look unusual.
>
> A few issues that trip up most people when beginning to use PHP, is the
> syntax errors. Usually these arise from quote issues, to semi-colon and
> brace issues. A lot of this trouble can be avoided (or easily debugged)
> by simply using tabs to your advantage. Consider the following:
>
>  echo 'what';
> if (!$condition2){
> include 'thing.php';
> while (!$dead)
> { if ($jam!= $yes){ $dead = true;
> } else{
> for ($i=0;$i<100;$i++)
> { $thing = processSomething('something', "something2");
> $string = 'something'.$here."too";
> }
> ?>
>
> Technically I *think* this would be syntactically correct, but if I was
> looking for a bug, I would be shot in the foot. A better way to write
> this would be the following:
>
> 
> if ($condition){
> echo "correct";
> } else {
> echo "what";
> if (!$condition2){
> include ('thing.php');
> while (!$dead){
> if ($jam != $yes){
> $dead = true;
> } else {
> for ($i=0;$i<100;$i++){
> $thing = processSomething("something", "something2");
> $string = "something $here too";
> }
> }
> }
> }
> }
>
> ?>
>
> So its a couple more lines, but if I came back to that script a month or
> two months later trying to fix something, or add a new feature, it would
> be easy. Couple that style with comments and you're on fire!!!
>
> Hope this helps for someone out there...
>
> Adam
>
>



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




Re: [PHP-DB] Help with update...

2001-08-18 Thread BD

it's amazing.. I've been banging my head for over an hour on this, then as
soon as I send for help, I see the obvious - first of all, my error checking
was done *before* the query executed... then, to make it even more of an
effort in mindlessness, the table name capitalization was throwing it all
off!!

Sorry for the waste of good bandwidth...

~BD~



http://www.bustdustr.net
http://www.rfbdproductions.com
Home Of Radio Free BD
For The Difference.


- Original Message -----
From: BD <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, August 18, 2001 12:21 PM
Subject: [PHP-DB] Help with update...


> I'm working under the gun here, so please excuse me if this turns out to
be
> something really simple, but it's got me stumped... I'm trying to update
the
> "cover" field in a table by using the album_id field in the table and
adding
> a ".jpg" extention to it...
> For example:
> "Update albums set cover = "1.jpg" where album_id = 1"
>
> For some reason, however, the update isn't working when executed... here
are
> the results I get:
>
> album_id: 1 - cover: 1.jpg
> UPDATE ALBUMS SET COVER = "1.jpg" WHERE ALBUM_ID = 1
> mysql_errno: 0:   mysql_error:
> Update Failed!
>
> As you can see, there's no error code generated, and the update statement
> works great from the command line...
>
> here's the relevant code (i'm connecting to the database as root, so i
don't
> think it's a permissions thing...):
> $query = "SELECT * FROM albums ORDER BY album_id";
>
> $stuff = mysql_query($query) or die("Select Failed!");
>
> while ($results = mysql_fetch_array($stuff)) {
>
>   $cover = $results['album_id'].".jpg";
>   $album_id = $results['album_id'];
>   echo $album_id." - ".$cover."";
>   $update = "UPDATE ALBUMS SET COVER = \"$cover\" WHERE ALBUM_ID =
> $album_id";
>   echo $update."";
>   echo mysql_errno().": ".mysql_error()."";
>   mysql_query($update) or die("Update Failed!");
>  }
>
>
> Simple... right? But it's beating me up this morning.. I would greatly
> appreciate it if anyone could show me the error of my ways...
>
> ~BD~
>
> http://www.bustdustr.net
> http://www.rfbdproductions.com
> Home Of Radio Free BD
> For The Difference.
>
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] Help with update...

2001-08-18 Thread BD

I'm working under the gun here, so please excuse me if this turns out to be
something really simple, but it's got me stumped... I'm trying to update the
"cover" field in a table by using the album_id field in the table and adding
a ".jpg" extention to it...
For example:
"Update albums set cover = "1.jpg" where album_id = 1"

For some reason, however, the update isn't working when executed... here are
the results I get:

album_id: 1 - cover: 1.jpg
UPDATE ALBUMS SET COVER = "1.jpg" WHERE ALBUM_ID = 1
mysql_errno: 0:   mysql_error:
Update Failed!

As you can see, there's no error code generated, and the update statement
works great from the command line...

here's the relevant code (i'm connecting to the database as root, so i don't
think it's a permissions thing...):
$query = "SELECT * FROM albums ORDER BY album_id";

$stuff = mysql_query($query) or die("Select Failed!");

while ($results = mysql_fetch_array($stuff)) {

  $cover = $results['album_id'].".jpg";
  $album_id = $results['album_id'];
  echo $album_id." - ".$cover."";
  $update = "UPDATE ALBUMS SET COVER = \"$cover\" WHERE ALBUM_ID =
$album_id";
  echo $update."";
  echo mysql_errno().": ".mysql_error()."";
  mysql_query($update) or die("Update Failed!");
 }


Simple... right? But it's beating me up this morning.. I would greatly
appreciate it if anyone could show me the error of my ways...

~BD~

http://www.bustdustr.net
http://www.rfbdproductions.com
Home Of Radio Free BD
For The Difference.




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] How to drop a table when user leaves prematurely?

2001-07-16 Thread -BD-

Thanks, Christopher...

I feel better now knowing  that I wasn't just missing something really
obvious.. on the other hand, I should have thought of the "stateless" aspect
myself

I'll take the timestamp approach, and see what I can come up with...

BD

http://www.bustdustr.net
http://www.rfbdproductions.com
The Entertainment Center
Home Of Radio Free BD
For A Difference.


- Original Message -
From: Christopher Ostmo <[EMAIL PROTECTED]>
To: BD <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Monday, July 16, 2001 1:42 PM
Subject: Re: [PHP-DB] How to drop a table when user leaves prematurely?


> BD pressed the little lettered thingies in this order...
>
> > Ugh!
> >
> > I'm sure this is fairly simple, but I have yet to come up with a way to
do
> > it...
> >
> > In a nutshell, our application creates, uses and drops a table while the
> > user is working on the site. Unfortunately, because of "other
> > considerations", we can't use a defined temp table - it has to be
created
> > as a regular table. We have a routine in the app that will drop the
table
> > once the user is done with their work, but if they leave for some reason
> > before they're done, the table is left hanging out there. This wasn't a
> > problem at first, but we're building up quite a collection of useless
> > tables right now.
> >
> > Is there any way to drop the table automagically when the user leaves
> > prematurely, either by closing their browser or jumping to another site?
I
> > tried using register_shutdown_function(), but it didn't seem to have any
> > effect...
> >
> > I think, and I know I may be way off base, is that there are a lot of
pages
> > involved in this application, and I'm not sure how to tell the app that
the
> > user is just going from one page to the next or is actually going
> > bye-bye...
> >
>
> HTTP is stateless (there is no persistent connection between the server
> and browser), so there is no way for you to tell the difference on the
> server side whether the user has gone to get coffee, has closed his or
> her browser or has been abducted by aliens.  You can do two things
> that are rather unreliable:
> 1) Have a "Log Out" button.  This is unreliable because many (most?)
> people will simply not use it.
> 2) Use a javascript to detect when the user has gone away. This is
> unreliable because many people disable javascript or use non-compliant
> browsers.
>
> The only sure way to keep your temp tables at a minimum is to store a
> creation date or datetime field in the temp table and destroy the table
> when it has reached a reasonable age.  I prefer to run perl scripts from
> cron to do this and typically choose 48 hours as the time at which I feel
> that it is safe to assume that the user has abandoned his or her data.
>
> Good luck...
>
> Christopher Ostmo
> a.k.a. [EMAIL PROTECTED]
> AppIdeas.com
> Innovative Application Ideas
> Meeting cutting edge dynamic
> web site needs since the
> dawn of Internet time (1995)
>
> Business Applications:
> http://www.AppIdeas.com/
>
> Open Source Applications:
> http://open.AppIdeas.com/


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] How to drop a table when user leaves prematurely?

2001-07-15 Thread BD

Ugh!

I'm sure this is fairly simple, but I have yet to come up with a way to do it...

In a nutshell, our application creates, uses and drops a table while the user is 
working on the site. Unfortunately, because of "other considerations", we can't use a 
defined temp table - it has to be created as a regular table. We have a routine in the 
app that will drop the table once the user is done with their work, but if they leave 
for some reason before they're done, the table is left hanging out there. This wasn't 
a problem at first, but we're building up quite a collection of useless tables right 
now.

Is there any way to drop the table automagically when the user leaves prematurely, 
either by closing their browser or jumping to another site? I tried using 
register_shutdown_function(), but it didn't seem to have any effect...

I think, and I know I may be way off base, is that there are a lot of pages involved 
in this application, and I'm not sure how to tell the app that the user is just going 
from one page to the next or is actually going bye-bye...

-BD-


http://www.bustdustr.net
http://www.rfbdproductions.com
The Entertainment Center
Home Of Radio Free BD
For A Difference.





[PHP-DB] Pages not displaying?

2001-05-23 Thread BD

Have what I think is kind of a weird situation going on...

I have a survey that's dynamically built from a mysql database. The basic
logic of the program is to create a table based on user name, then read 10
questions from the "master" table, and insert them into the user table once
the user completes a page. The next page repeats the process, with the
additional step of checking the user table after each master table read to
make sure there are no duplicate questions being processed. Once all the
questions are read and the user completes the test, the user table is then
dropped and life goes on... (Note: I know there is probably a MUCH better
way to do this, but I was in a rush and this was my first attemp at
PHP...I'm definitely open for suggestions...)

The problem some of my users are running into is that occasionally wierd
things begin to occur, such as *some* of the questions not displaying
(there's no pattern that I've found  to which ones don't display when this
occurs, and they're all pulled from the database) while the response radio
buttons for the missing questions will display just fine... or the page
won't show up at all...  or, one page will show up, the next one won't, and
then the next one will...I've not been able to duplicate any of these at all
myself. They're platform independent - I know of a case where it occured on
a Win2000 machine and a Mac G3...

Now for the newbie questions:
Is there significant resource usage on the client side when dealing with
php/mysql?  I wouldn't think there should be any, but...

I'm not passing a lot of variables through the form, but does doing this eat
significant resources on the client side? Or, would it be better to pass all
the "used" question thru the form instead of creating and using the user
table?

And finally - does anyone have any idea where I should start looking?
There's nothing in any error logs that indicate any problems...

-BD-



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] Looking for a script

2001-05-19 Thread BD

Can someone point me towards a down & dirty (and, of course, free)
classified ads script? doesn't have to be fancy, but I have to get it in
this weekend...

TIA

-BD-

http://www.bustdustr.net
Home of Radio Free Bd



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Newbie question

2001-05-03 Thread ~BD~

EXACTLY what I was looking for...
Thanks!

http://www.bustdustr.net
Home of Radio Free Bd


- Original Message -
From: CC Zona <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, May 03, 2001 1:42 PM
Subject: Re: [PHP-DB] Newbie question


> In article <034101c0d3f3$0dd747e0$41041dd8@winbox>,
>  [EMAIL PROTECTED] ("~BD~") wrote:
>
> > at the end of my script, I run a set of closing and clean-up
procedures..
> > what I would like to be able to do is that when a user bails out of the
> > script by closing the browser or leaving the site/page, detect that
they've
> > gone, and then go ahead and run my closing procedures.. is this
possible?
>
> http://php.net/manual/en/features.connection-handling.php
> http://php.net/register-shutdown-function
>
> --
> CC
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] Newbie question

2001-05-03 Thread ~BD~

I've gone thru everything I can find, and I'm sure I'm just missing it (it's
happened before), but...

at the end of my script, I run a set of closing and clean-up procedures..
what I would like to be able to do is that when a user bails out of the
script by closing the browser or leaving the site/page, detect that they've
gone, and then go ahead and run my closing procedures.. is this possible?

I'd appreciate a point in the right direction, with or without an RTFM ...
:)

TIA
~BD~

http://www.bustdustr.net
Home of Radio Free Bd



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Really embarassing newbie question...

2001-04-26 Thread ~BD~

Doh!
Sorry about that - yes, it's MySQL. And I complete blew by
mysql_list_tables - I mis-read what I thought it did, then didn't look at it
any further...

I told you it was embarrasing...
Thanks!

http://www.bustdustr.net
Home of Radio Free Bd



> You didn't mention what DBMS you are running... Assuming it is MySQL,
check
> page 686 in the PHP Manual, you're looking for mysql_list_tables()
>
> Enjoy...
>
> -Original Message-
> From: ~BD~ [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, April 26, 2001 9:33 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP-DB] Really embarassing newbie question...
>
>
> Sorry to do this to ya...
> I"ve been involved with PHP for a total of two days now, and I'm kinda
> stumped. I've been looking in docs for about 4 hours now for this, and I'm
> sure I'm slipping right by the obvious answer somewhere, but
>
> What's the best (recommended) way to determine if a table exists in a
> database? Is it to try a query on it, and check the returned error? that's
> the way I'm set up now, but I can't help but think there's got to be a
> better way...
>
> TIA,
> ~BD~
>
>
>
> http://www.bustdustr.net
> Home of Radio Free Bd



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] Really embarassing newbie question...

2001-04-26 Thread ~BD~

Sorry to do this to ya...
I"ve been involved with PHP for a total of two days now, and I'm kinda
stumped. I've been looking in docs for about 4 hours now for this, and I'm
sure I'm slipping right by the obvious answer somewhere, but

What's the best (recommended) way to determine if a table exists in a
database? Is it to try a query on it, and check the returned error? that's
the way I'm set up now, but I can't help but think there's got to be a
better way...

TIA,
~BD~



http://www.bustdustr.net
Home of Radio Free Bd



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]