This is a discussion on Better MySQL/PHP query formatting (simple question) within the PHP Language forums, part of the PHP Programming Forums category; I have been using MySQL in conjunction with PHP for many years now... I have been using the exact same ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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. |
|
|||
|
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... > 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. |
|
|||
|
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 |
|
|||
|
"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... > 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 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 |
|
|||
|
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>... > "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... > > 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 > > 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. |