473,322 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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.
Jul 17 '05 #1
4 1951
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" <sl***@cylence.org> wrote in message
news:7c**************************@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.

Jul 17 '05 #2
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
Jul 17 '05 #3

"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

Jul 17 '05 #4
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" <to**@NOSPAM.demon.co.uk> wrote in message news:<ca*******************@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.

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Bruce A. Julseth | last post by:
Newbie Question: Is there a way to import MS Access into MySQL? Maybe create a CSV or something. If so, what would be the SQL to do this? Thanks... Bruce
2
by: Robert | last post by:
I need some help with formatting some text received from a database query. I am only selecting a single row per query so the formatting will only be performed on a single row. The rows I need to...
0
by: Ed Smith | last post by:
I have two questions about REFERENCES: 1. It appears that mySQL treats REFERENCES associated with an attribute differently than FOREIGN KEY (<blah>) REFERENCES... Specifically, the first form...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
3
by: Juan Antonio Villa | last post by:
Hello, I'm having a problem replicating a simple database using the binary log replication, here is the problem: When the master sends an update to the slave, an example update reads as follows:...
16
by: laverdir | last post by:
<? $query = "SELECT " . $this->tabela3 . ".id, " . $this->tabela3 . ".naziv, " . $this->tabela3 . ".spisatelj, " . $this->tabela3 . ".najava, " . " DATE_FORMAT(" . $this->tabela3 ....
30
by: Einstein30000 | last post by:
Hi, in one of my php-scripts is the following query (with an already open db-connection): $q = "INSERT INTO main (name, img, descr, from, size, format, cat, host, link, date) VALUES ('$name',...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.