Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 17th, 2005, 06:42 AM
Slant
Guest
 
Posts: n/a
Default Better MySQL/PHP query formatting (simple question)

I have been using MySQL in conjunction with PHP for many years now...
I have been using the exact same method for not only connecting to a
database and performing the queries but also displaying the results.

I've been told numerous times that my methods are out-dated. I'm more
than willing to cede to this possibility but I need help getting out
of the rut!!! Can anyone help me?

Here are some examples:

<head>
....
<?php include "../../../_private/mysql.inc"; ?>
<?php $db = mysql_connect("$server","$user","$pass"); ?>
....
</head>

<body>
....
<?php
mysql_select_db("database_name",$db);
$result = mysql_query("SELECT * FROM temple_items",$db);
while ($myrow = mysql_fetch_array($result)) {
$id = $myrow["ID"];
$name = $myrow["Name"];
$amount = $myrow["Amount"];
$date = $myrow["Date"];

echo "<div>" . $name . ": " . $amount . " (" . $date . ")</div><br
/>";
}
?>
....
</body>

It's crap, I know... I've been told that there are more efficient ways
of doing nearly all of this. Can someone instruct me in the ways of
better database queries? I'm hopeless until I have this knowledge. ;)

Thanks beyond words in advance.
  #2  
Old July 17th, 2005, 06:42 AM
Tony Marston
Guest
 
Posts: n/a
Default Re: Better MySQL/PHP query formatting (simple question)

Take a look at http://www.tonymarston.net/php-mysql...plication.html
which describes a sample application I have built using techniques I have
described elsewhere on my website. You can run it online and also download
all the source code.

I must warn you that it is pretty advanced stuff - it is based on the 3 Tier
architecture and the Model-View-Controller design pattern; it uses XSL
transformations for all HTML output, and a series of OO classes for talking
to database entities. There is a high degree of reusable code, therefore it
really is a Rapid Application Development (RAD) environment.

Hope this helps.

--
Tony (a legend in his own lunchtime) Marston

http://www.tonymarston.net



"Slant" <slant@cylence.org> wrote in message
news:7c70bda5.0406081515.2e494246@posting.google.c om...[color=blue]
> I have been using MySQL in conjunction with PHP for many years now...
> I have been using the exact same method for not only connecting to a
> database and performing the queries but also displaying the results.
>
> I've been told numerous times that my methods are out-dated. I'm more
> than willing to cede to this possibility but I need help getting out
> of the rut!!! Can anyone help me?
>
> Here are some examples:
>
> <head>
> ...
> <?php include "../../../_private/mysql.inc"; ?>
> <?php $db = mysql_connect("$server","$user","$pass"); ?>
> ...
> </head>
>
> <body>
> ...
> <?php
> mysql_select_db("database_name",$db);
> $result = mysql_query("SELECT * FROM temple_items",$db);
> while ($myrow = mysql_fetch_array($result)) {
> $id = $myrow["ID"];
> $name = $myrow["Name"];
> $amount = $myrow["Amount"];
> $date = $myrow["Date"];
>
> echo "<div>" . $name . ": " . $amount . " (" . $date . ")</div><br
> />";
> }
> ?>
> ...
> </body>
>
> It's crap, I know... I've been told that there are more efficient ways
> of doing nearly all of this. Can someone instruct me in the ways of
> better database queries? I'm hopeless until I have this knowledge. ;)
>
> Thanks beyond words in advance.[/color]


  #3  
Old July 17th, 2005, 06:42 AM
Benny Hill
Guest
 
Posts: n/a
Default Re: Better MySQL/PHP query formatting (simple question)

On Wed, 09 Jun 2004 00:45:01 +0100, Tony Marston wrote:

* snip Tony's reply *

Hi Tony,

I just wanted to mention that I think your site is very well written.
Your code samples are well structured and consistent and I think anyone
who would like to be a better PHP programmer would do well to check out
your site.

I also have to tip my hat to you since you have obviously spent some
time writing COBOL code (I'm an RPG guy myself). COBOL is the only
language I have encountered (so far) that I just can't like.

Keep up the good work.

--
Benny
  #4  
Old July 17th, 2005, 06:43 AM
Tony Marston
Guest
 
Posts: n/a
Default Re: Better MySQL/PHP query formatting (simple question)


"Benny Hill" <benny_hill3@your_rose_colored_glassesyahoo.com> wrote in
message
news:pan.2004.06.09.03.39.57.227678@your_rose_colo red_glassesyahoo.com...[color=blue]
> On Wed, 09 Jun 2004 00:45:01 +0100, Tony Marston wrote:
>
> * snip Tony's reply *
>
> Hi Tony,
>
> I just wanted to mention that I think your site is very well written.
> Your code samples are well structured and consistent and I think anyone
> who would like to be a better PHP programmer would do well to check out
> your site.
>
> I also have to tip my hat to you since you have obviously spent some
> time writing COBOL code (I'm an RPG guy myself). COBOL is the only
> language I have encountered (so far) that I just can't like.
>
> Keep up the good work.
>
> --
> Benny[/color]

Thanks for those kind words.

As for your comments about COBOL all I can say is that in its day it was
pretty damn good (it was, after all, one of the first 3rd generation
languages ever), but has been overtaken by newer languages which work
totally differently. The main complaint against COBOL is that it is very
verbose and takes a long time to write a program from scratch. But a
programmer only ever writes ONE program from scratch (his first) and
thereafter all others are copies which are modified to taste.

With COBOL I learned how to design and implement reusable components in
order to reduce development times, and I have used the same skill in all
other languages I have used since, including PHP.

It is interesting to see that COBOL still appears high up in the Programming
Community Index at http://www.tiobe.com/tpci.htm, but I don't think I would
ever go back to it.

--
Tony Marston

http://www.tonymarston.net



  #5  
Old July 17th, 2005, 06:43 AM
Slant
Guest
 
Posts: n/a
Default Re: Better MySQL/PHP query formatting (simple question)

Woohoo!! That's right... Cobol still on the list, right next to, um,
Fortran.. ;)

Tony, thanks immensely for the awesome examples!! I have not even had
a chance to touch it yet. lol. I will hopefully get to tonight though.

Thanks again, and keep up such awesome work. :)

Slant


"Tony Marston" <tony@NOSPAM.demon.co.uk> wrote in message news:<ca6nl9$nka$1$8300dec7@news.demon.co.uk>...[color=blue]
> "Benny Hill" <benny_hill3@your_rose_colored_glassesyahoo.com> wrote in
> message
> news:pan.2004.06.09.03.39.57.227678@your_rose_colo red_glassesyahoo.com...[color=green]
> > On Wed, 09 Jun 2004 00:45:01 +0100, Tony Marston wrote:
> >
> > * snip Tony's reply *
> >
> > Hi Tony,
> >
> > I just wanted to mention that I think your site is very well written.
> > Your code samples are well structured and consistent and I think anyone
> > who would like to be a better PHP programmer would do well to check out
> > your site.
> >
> > I also have to tip my hat to you since you have obviously spent some
> > time writing COBOL code (I'm an RPG guy myself). COBOL is the only
> > language I have encountered (so far) that I just can't like.
> >
> > Keep up the good work.
> >
> > --
> > Benny[/color]
>
> Thanks for those kind words.
>
> As for your comments about COBOL all I can say is that in its day it was
> pretty damn good (it was, after all, one of the first 3rd generation
> languages ever), but has been overtaken by newer languages which work
> totally differently. The main complaint against COBOL is that it is very
> verbose and takes a long time to write a program from scratch. But a
> programmer only ever writes ONE program from scratch (his first) and
> thereafter all others are copies which are modified to taste.
>
> With COBOL I learned how to design and implement reusable components in
> order to reduce development times, and I have used the same skill in all
> other languages I have used since, including PHP.
>
> It is interesting to see that COBOL still appears high up in the Programming
> Community Index at http://www.tiobe.com/tpci.htm, but I don't think I would
> ever go back to it.[/color]
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles