This is a discussion on "seeking more efficient code" within the PHP Forum section. This forum, and the thread "seeking more efficient code are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
seeking more efficient code
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
seeking more efficient code
please take a look at this script. i was having problems getting my <select><option> html form to work properly until i, against my better judgement, added the two additional mysql_fetch_array functions for "artist_id2" and "artist_id3" (support one, and support two).
do you have a suggestion for a more efficient way to write this code? i have a snapshot of my table here. i hope you can understand in the midst of this mess what i'm trying to do... thanks!!
|
|
|
|
|||
|
I can see a couple of things that may help as starters...
Firstly, I see a lot of code that's been cut and pasted a number of times and the altered a bit. If you find your self cutting and pasting code to write a script - there's probably an easier way ... and you're making yourself a maintenance nightmare if you insist on duplicating code Don't copy and paste - write a function. If you have to change bits of the code when you copy and paste, THAT is the clue as to what should be passed into the function as parameters Second - Don't write long, multiline quotes strings with backslashed quotes within. There are several alternatives, including a here document.
|
|
|||
|
grahame,
first off, THANK you very much for the tip on functions() i've been studying PHP for a little while, but only started keeping a log of notes to myself, and that little bit is going in there! now, for the other part-- your recommendation about the long parts of multiple strings... i don't understand what you're telling me, but i'd like to learn. thanks so much!! Quote:
|
|
|||
|
In a quoted string as shown in your original sample code, you had spent a great deal of time adding \ characters in front of any \ you really wanted within the string. Not only had you taken (I'm sure) quite a while to get those all correct, but it also made reading the script much harder.
By using a "here document" - perhaps that would be better if it was called a multicharacter delimiter - you can make the code look much easier. The delimiter can be more or less anything - I chose the word DONE but you'll often find people using something more descriptive like HEADER or even EOT (for end of text). Example showing (almost) the same text both ways:
|
|
|||
|
oh! i see-- so, that's just done like this where ever i want echo (or print), or put it in a variable:
thanks!! |
![]() |
| Tags |
| seeking, efficient, code |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Seeking P/T Creative Graphic Web Designer (no code) | ep2002 | Job Opportunities | 0 | Mar 21st, 2008 10:28 |
| [SOLVED] Can this be made more efficient | AdRock | Databases | 0 | Nov 19th, 2007 23:05 |
| live search code and styleswitcher code | hebel | JavaScript Forum | 0 | May 12th, 2007 06:16 |
| efficient code | Maverick25r | PHP Forum | 1 | Sep 6th, 2006 01:20 |
| Can somebody give me the code to hide the source code? | renren | JavaScript Forum | 7 | Mar 7th, 2006 12:27 |