Better MySQL/PHP query formatting (simple question)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Slant

    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("SE LECT * FROM temple_items",$ db);
    while ($myrow = mysql_fetch_arr ay($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.
  • Tony Marston

    #2
    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

    This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL




    "Slant" <slant@cylence. org> wrote in message
    news:7c70bda5.0 406081515.2e494 246@posting.goo gle.com...[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("SE LECT * FROM temple_items",$ db);
    > while ($myrow = mysql_fetch_arr ay($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]


    Comment

    • Benny Hill

      #3
      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

      Comment

      • Tony Marston

        #4
        Re: Better MySQL/PHP query formatting (simple question)


        "Benny Hill" <benny_hill3@yo ur_rose_colored _glassesyahoo.c om> wrote in
        message
        news:pan.2004.0 6.09.03.39.57.2 27678@your_rose _colored_glasse syahoo.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

        This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL




        Comment

        • Slant

          #5
          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.de mon.co.uk> wrote in message news:<ca6nl9$nk a$1$8300dec7@ne ws.demon.co.uk> ...[color=blue]
          > "Benny Hill" <benny_hill3@yo ur_rose_colored _glassesyahoo.c om> wrote in
          > message
          > news:pan.2004.0 6.09.03.39.57.2 27678@your_rose _colored_glasse syahoo.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]

          Comment

          Working...