Re: There's got to be a better way



On 25 Mar, 21:37, Mary Pegg <inva...@xxxxxxxxxxx> wrote:
shimmyshack wrote:
if (isset($c['s']['a5'])) echo htmlentities($c['s']['a1'])."<br>";
.
.
.
if (isset($c['s']['a5'])) echo htmlentities($c['s']['a5'])."<br>";
that's alot of work for sake of sticking with what _you_ find more
readable

So what you're really arguing in favour of is wrapping it up in a
function, which is what I've done. But the question is whether it's
worth creating a for loop to run through a1 to a5 rather than simply
calling each by name.

all the chages above and more are so simple with Rani's method. If you

No, they're simple if it's wrapped up in a function. Whether or not
a1 to a5 get generated by a for loop I've still got b, c, d, e, f (etc)
to deal with. NB I'm using these as symbols - in reality they are the
field names from a database, so no getting smart and suggesting that I
can generate b to f automagically. OTOH I could stick the field names
in an array and step through the array. This might be worth doing.

can't take good advice don't ask for it.

I know this is Usenet but you don't *have* to be rude and abrasive.

--
"Checking identity papers is a complete waste of time. If anyone can
be counted on to have valid papers, it will be the terrorists".

it's not rude or abrasive, to notice you don't take advice and say so,
perhaps a little bruusque though, and I apologise if I made you cross.
FYI, I work with annoyingly complex database tables whose structure
changes as my client changes their requirements, to stop this kind of
hard coded approach which started to cost me too much time, I use
DESCRIBE `tablename`, and SHOW FULL COLUMNS FROM `tablename` which can
then be used to get the comments, fieldnames etc... then using a reg
exp on bool enum varchar() int() and so on to get metadata about the
table which is then pumped into the application.
In this way you can use general methods to print and parse data
without ever having to hard code the fieldnames, you can use it to
dynamically generate forms etc...
Instead of repeatedly writing code to format output from the DB, you
just need a vlid link, and some form of instructions what your db
connection is to "get" and "output" and finally the output format -
preventing too much or too little from being drawn from the DB. You
only have to code this once, and after than it can be used everywhere
you need output. It might seem a little extreme to folks, I don't
know, but I find this approach saves time. The class which serves html
markup can end up being very complex but you can control things with a
couple of calls and an array.

.



Relevant Pages

  • Re: Theres got to be a better way
    ... in an array and step through the array. ... I work with annoyingly complex database tables whose structure ... DESCRIBE `tablename`, and SHOW FULL COLUMNS FROM `tablename` which can ... then be used to get the comments, fieldnames etc... ...
    (comp.lang.php)
  • Re: Theres got to be a better way
    ... in an array and step through the array. ... I work with annoyingly complex database tables whose structure ... then be used to get the comments, fieldnames etc... ... Instead of repeatedly writing code to format output from the DB, ...
    (comp.lang.php)
  • Re: Cannot locate dynamically declared array
    ... >> I thought the eval will actually declare @USER array. ... > foreach my $fieldname (@fieldnames) ...
    (comp.lang.perl.misc)
  • Re: Importing data from Access to Excel, but I need to vary the table from Access
    ... .CommandText = Array(_ ... .FieldNames = True ... .PreserveFormatting = True ... .RefreshStyle = xlInsertDeleteCells ...
    (microsoft.public.excel.programming)
  • Re: Foxpro questions
    ... Go the other direction with CREATE TABLE tablename FROM ARRAY ... myarray. ... Cass Lewart wrote: ...
    (microsoft.public.fox.programmer.exchange)