Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #14480 > unrolled thread

Pulling ad-hoc data from a database into a PHP web page

Started by"James Harris" <james.harris.1@gmail.com>
First post2014-11-06 00:23 +0000
Last post2014-11-10 21:27 +0000
Articles 20 on this page of 34 — 9 participants

Back to article view | Back to comp.lang.php


Contents

  Pulling ad-hoc data from a database into a PHP web page "James Harris" <james.harris.1@gmail.com> - 2014-11-06 00:23 +0000
    Re: Pulling ad-hoc data from a database into a PHP web page Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-06 04:54 +0100
      Re: Pulling ad-hoc data from a database into a PHP web page Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-06 09:19 -0500
        Re: Pulling ad-hoc data from a database into a PHP web page "James Harris" <james.harris.1@gmail.com> - 2014-11-06 15:39 +0000
          Re: Pulling ad-hoc data from a database into a PHP web page Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-06 11:32 -0500
            Re: Pulling ad-hoc data from a database into a PHP web page "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2014-11-26 10:26 +0100
              Re: Pulling ad-hoc data from a database into a PHP web page Tim Streater <timstreater@greenbee.net> - 2014-11-26 09:38 +0000
                Re: Pulling ad-hoc data from a database into a PHP web page "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2014-11-26 11:56 +0100
              Re: Pulling ad-hoc data from a database into a PHP web page Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-26 07:51 -0500
                Re: Pulling ad-hoc data from a database into a PHP web page "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2014-11-26 14:24 +0100
                  Re: Pulling ad-hoc data from a database into a PHP web page Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-26 08:36 -0500
                    Re: Pulling ad-hoc data from a database into a PHP web page Matthew Carter <m@ahungry.com> - 2014-11-26 10:21 -0500
                      Re: Pulling ad-hoc data from a database into a PHP web page "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2014-11-26 20:57 +0100
                      Re: Pulling ad-hoc data from a database into a PHP web page Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-26 16:21 -0500
          Re: Pulling ad-hoc data from a database into a PHP web page "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-06 18:27 +0100
      Re: Pulling ad-hoc data from a database into a PHP web page "James Harris" <james.harris.1@gmail.com> - 2014-11-06 15:58 +0000
        Re: Pulling ad-hoc data from a database into a PHP web page Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-06 21:34 +0100
    Re: Pulling ad-hoc data from a database into a PHP web page Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-05 23:00 -0500
      Re: Pulling ad-hoc data from a database into a PHP web page "James Harris" <james.harris.1@gmail.com> - 2014-11-06 15:29 +0000
        Re: Pulling ad-hoc data from a database into a PHP web page Matthew Carter <m@ahungry.com> - 2014-11-06 10:44 -0500
          Re: Pulling ad-hoc data from a database into a PHP web page "James Harris" <james.harris.1@gmail.com> - 2014-11-06 16:15 +0000
            Re: Pulling ad-hoc data from a database into a PHP web page Matthew Carter <m@ahungry.com> - 2014-11-06 11:25 -0500
              Re: Pulling ad-hoc data from a database into a PHP web page Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-06 12:42 -0500
              Re: Pulling ad-hoc data from a database into a PHP web page Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-08 13:50 +0100
                Re: Pulling ad-hoc data from a database into a PHP web page Matthew Carter <m@ahungry.com> - 2014-11-08 21:19 -0500
                  Re: Pulling ad-hoc data from a database into a PHP web page Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-08 22:08 -0500
                  Re: Pulling ad-hoc data from a database into a PHP web page Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-09 08:09 +0100
            Re: Pulling ad-hoc data from a database into a PHP web page "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-06 18:24 +0100
              Re: Pulling ad-hoc data from a database into a PHP web page Matthew Carter <m@ahungry.com> - 2014-11-06 12:37 -0500
              Re: Pulling ad-hoc data from a database into a PHP web page "James Harris" <james.harris.1@gmail.com> - 2014-11-06 17:51 +0000
                Re: Pulling ad-hoc data from a database into a PHP web page "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-06 20:56 +0100
        Re: Pulling ad-hoc data from a database into a PHP web page Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-06 12:40 -0500
        Re: Pulling ad-hoc data from a database into a PHP web page richard <noreply@example.com> - 2014-11-10 11:17 -0500
          Re: Pulling ad-hoc data from a database into a PHP web page Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-10 21:27 +0000

Page 1 of 2  [1] 2  Next page →


#14480 — Pulling ad-hoc data from a database into a PHP web page

From"James Harris" <james.harris.1@gmail.com>
Date2014-11-06 00:23 +0000
SubjectPulling ad-hoc data from a database into a PHP web page
Message-ID<m3ef2b$u9h$1@dont-email.me>
I am looking for a good way to pull ad-hoc info from a database into a web 
page. By "good" I mean a way that is efficient for the server and convenient 
for the person writing the web page. Some of the ad-hoc info will be 
scalars. Some will be lists and, possibly, some will be tabular. Is there 
already a standard way to do things like this?

It's been a whiile since I used PHP but from a quick look it seems it may be 
best to define a number of functions to retrieve and echo data. A call to 
the scalar function would be something like

  scalar_get("key")

where the key uniquely identifies a cell in a table. The subroutine would 
just echo the result into the output html that gets sent to the web browser. 
Is that reasonable and is there a way to make the subroutine efficient given 
that there may be many scalar_get() calls in the body of the page?

James

[toc] | [next] | [standalone]


#14486

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-11-06 04:54 +0100
Message-ID<9211084.ztrPHf13qF@PointedEars.de>
In reply to#14480
James Harris wrote:

> I am looking for a good way to pull ad-hoc info from a database into a
> web page. By "good" I mean a way that is efficient for the server and
> convenient for the person writing the web page.

You can't have your cake and eat it.

> Some of the ad-hoc info will be scalars. Some will be lists and, possibly,
> some will be tabular.

With regard to data, a list is a table with one column.

> Is there already a standard way to do things like this?

Yes.

> It's been a whiile since I used PHP but from a quick look it seems it may
> be best to define a number of functions to retrieve and echo data.

Three at most.

> A call to the scalar function would be something like
> 
>   scalar_get("key")
> 
> where the key uniquely identifies a cell in a table.

You mean a _column_.  A common ontology for databases is that a database 
consists of tables, a table consists of rows and columns, each row and 
column consists of fields; the fields of each column that belong to the same 
row constitute a record, and several records constitute a data set.

> The subroutine would just echo the result into the output html that gets
> sent to the web browser

As a rule of thumb, you want to escape all output.  You may even have to 
recode it for proper display.

> Is that reasonable

No.

> and is there a way to make the subroutine efficient given that there may
> be many scalar_get() calls in the body of the page?

Mu. [1]

Next time, ask questions the smart way:
<http://www.catb.org/~esr/faqs/smart-questions.html>
















[1] You can cache query results so that you do not have to issue a new query 
    when you need data from the same data set.  But the notion of “ad-hoc
    data” contradicts with that approach; “ad-hoc data” changes.

-- 
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#14492

FromJerry Stuckle <jstucklex@attglobal.net>
Date2014-11-06 09:19 -0500
Message-ID<m3g01n$eu7$1@dont-email.me>
In reply to#14486
On 11/5/2014 10:54 PM, the pedantic troll Thomas 'Pointed Head' Lahn wrote:
> James Harris wrote:
> 
>> I am looking for a good way to pull ad-hoc info from a database into a
>> web page. By "good" I mean a way that is efficient for the server and
>> convenient for the person writing the web page.
> 
> You can't have your cake and eat it.
> 
>> Some of the ad-hoc info will be scalars. Some will be lists and, possibly,
>> some will be tabular.
> 
> With regard to data, a list is a table with one column.
> 
>> Is there already a standard way to do things like this?
> 
> Yes.
> 
>> It's been a whiile since I used PHP but from a quick look it seems it may
>> be best to define a number of functions to retrieve and echo data.
> 
> Three at most.
> 
>> A call to the scalar function would be something like
>>
>>   scalar_get("key")
>>
>> where the key uniquely identifies a cell in a table.
> 
> You mean a _column_.  A common ontology for databases is that a database 
> consists of tables, a table consists of rows and columns, each row and 
> column consists of fields; the fields of each column that belong to the same 
> row constitute a record, and several records constitute a data set.
> 
>> The subroutine would just echo the result into the output html that gets
>> sent to the web browser
> 
> As a rule of thumb, you want to escape all output.  You may even have to 
> recode it for proper display.
> 
>> Is that reasonable
> 
> No.
> 
>> and is there a way to make the subroutine efficient given that there may
>> be many scalar_get() calls in the body of the page?
> 
> Mu. [1]
> 
> Next time, ask questions the smart way:
> <http://www.catb.org/~esr/faqs/smart-questions.html>
> 

Smart questions.  Dumb answers - but typical of Pointed Head.
Completely useless.

James, I suggest you just ignore the troll.  Your life will be much better.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#14494

From"James Harris" <james.harris.1@gmail.com>
Date2014-11-06 15:39 +0000
Message-ID<m3g4nk$275$1@dont-email.me>
In reply to#14492
"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message 
news:m3g01n$eu7$1@dont-email.me...
> On 11/5/2014 10:54 PM, the pedantic troll Thomas 'Pointed Head' Lahn 
> wrote:

...

>> Next time, ask questions the smart way:
>> <http://www.catb.org/~esr/faqs/smart-questions.html>
>>
>
> Smart questions.  Dumb answers - but typical of Pointed Head.
> Completely useless.
>
> James, I suggest you just ignore the troll.  Your life will be much 
> better.

LOL. Since he referred me to a guide on asking questions I was going to 
return the favour and refer him to a guide to providing answers.

That said, I can see that his effort to help was genuine ... I think.

James

[toc] | [prev] | [next] | [standalone]


#14499

FromJerry Stuckle <jstucklex@attglobal.net>
Date2014-11-06 11:32 -0500
Message-ID<m3g7q8$fl7$1@dont-email.me>
In reply to#14494
On 11/6/2014 10:39 AM, James Harris wrote:
> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message 
> news:m3g01n$eu7$1@dont-email.me...
>> On 11/5/2014 10:54 PM, the pedantic troll Thomas 'Pointed Head' Lahn 
>> wrote:
> 
> ...
> 
>>> Next time, ask questions the smart way:
>>> <http://www.catb.org/~esr/faqs/smart-questions.html>
>>>
>>
>> Smart questions.  Dumb answers - but typical of Pointed Head.
>> Completely useless.
>>
>> James, I suggest you just ignore the troll.  Your life will be much 
>> better.
> 
> LOL. Since he referred me to a guide on asking questions I was going to 
> return the favour and refer him to a guide to providing answers.
> 
> That said, I can see that his effort to help was genuine ... I think.
> 
> James
> 
> 

James, "Pointed Head" is a troll, well-known in several newsgroups.
This (lack of) answer is typical of most of his posts.  The only time he
gets something even halfway right is when someone else has answered the
question first, often times with code.  Then two days or so later,
Pointed Head will copy that post and claim it as his answer.

I suggest you just ignore his crap.  The only reason I responded was for
the benefit of you and other readers - showing him for what he is, to
the uninformed.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#14636

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2014-11-26 10:26 +0100
Message-ID<cdlkmqFolp5U1@mid.uni-berlin.de>
In reply to#14499
On 06.11.2014 17:32, Jerry Stuckle wrote:
> On 11/6/2014 10:39 AM, James Harris wrote:
>> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
>> news:m3g01n$eu7$1@dont-email.me...
>>> On 11/5/2014 10:54 PM, the pedantic troll Thomas 'Pointed Head' Lahn
>>> wrote:
>>
>> ...
>>
>>>> Next time, ask questions the smart way:
>>>> <http://www.catb.org/~esr/faqs/smart-questions.html>
>>>>
>>>
>>> Smart questions.  Dumb answers - but typical of Pointed Head.
>>> Completely useless.
>>>
>>> James, I suggest you just ignore the troll.  Your life will be much
>>> better.
>>
>> LOL. Since he referred me to a guide on asking questions I was going to
>> return the favour and refer him to a guide to providing answers.
>>
>> That said, I can see that his effort to help was genuine ... I think.
>>
>> James
>>
>>
>
> James, "Pointed Head" is a troll, well-known in several newsgroups.
> This (lack of) answer is typical of most of his posts.  The only time he
> gets something even halfway right is when someone else has answered the
> question first, often times with code.  Then two days or so later,
> Pointed Head will copy that post and claim it as his answer.
>
> I suggest you just ignore his crap.  The only reason I responded was for
> the benefit of you and other readers - showing him for what he is, to
> the uninformed.
>

I am so utterly fed up with this troll shit. If you feel compelled to comment every 
posting of Mr. Spock with "ignore the troll" I should write a bot to answer your 
postings the same way.

/Str.

[toc] | [prev] | [next] | [standalone]


#14638

FromTim Streater <timstreater@greenbee.net>
Date2014-11-26 09:38 +0000
Message-ID<261120140938476435%timstreater@greenbee.net>
In reply to#14636
In article <cdlkmqFolp5U1@mid.uni-berlin.de>, M. Strobel
<sorry_no_mail_here@nowhere.dee> wrote:

> On 06.11.2014 17:32, Jerry Stuckle wrote:

> > I suggest you just ignore his crap.  The only reason I responded was for
> > the benefit of you and other readers - showing him for what he is, to
> > the uninformed.

> I am so utterly fed up with this troll shit. If you feel compelled to comment
> every posting of Mr. Spock with "ignore the troll" I should write a bot to
> answer your postings the same way.

If PointyHead were to:

1) Go away and learn some manners
2) Keep his pedantic overbearing supercilious attitude to himself
3) Understand that this is not a classroom and he is not the teacher
standing there teaching us
4) Understand that he does not own this javascript newsgroup

in short were he to *grow* *up* and *lighten* *up* he might be better
appreciated here. But I'm not holding my breath.

-- 
"Please stop telling us what you feel. Please stop telling us what your 
intuition is. Your intuitive feelings are of no interest whatsoever, 
and nor are mine. I don't give a bugger what you feel, or what I feel. 
I want to know what the evidence shows."             -- Richard Dawkins

[toc] | [prev] | [next] | [standalone]


#14640

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2014-11-26 11:56 +0100
Message-ID<cdlpvoFq5nlU1@mid.uni-berlin.de>
In reply to#14638
On 26.11.2014 10:38, Tim Streater wrote:
> In article <cdlkmqFolp5U1@mid.uni-berlin.de>, M. Strobel
> <sorry_no_mail_here@nowhere.dee> wrote:
>
>> On 06.11.2014 17:32, Jerry Stuckle wrote:
>
>> > I suggest you just ignore his crap.  The only reason I responded was for
>> > the benefit of you and other readers - showing him for what he is, to
>> > the uninformed.
>
>> I am so utterly fed up with this troll shit. If you feel compelled to comment
>> every posting of Mr. Spock with "ignore the troll" I should write a bot to
>> answer your postings the same way.
>
> If PointyHead were to:
>
> 1) Go away and learn some manners
> 2) Keep his pedantic overbearing supercilious attitude to himself
> 3) Understand that this is not a classroom and he is not the teacher
> standing there teaching us
> 4) Understand that he does not own this javascript newsgroup
>
> in short were he to *grow* *up* and *lighten* *up* he might be better
> appreciated here. But I'm not holding my breath.
>

I am not praising the contributions of Spock, points 2 and 3 describe him well.

But I find 2 and 3 much easier to ignore than someone trying continuously to run down 
others, with this disgusting attitude "stick with me and the others are trolls".

/Str.




[toc] | [prev] | [next] | [standalone]


#14641

FromJerry Stuckle <jstucklex@attglobal.net>
Date2014-11-26 07:51 -0500
Message-ID<m54ibd$10d$1@dont-email.me>
In reply to#14636
On 11/26/2014 4:26 AM, M. Strobel wrote:
> On 06.11.2014 17:32, Jerry Stuckle wrote:
>> On 11/6/2014 10:39 AM, James Harris wrote:
>>> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
>>> news:m3g01n$eu7$1@dont-email.me...
>>>> On 11/5/2014 10:54 PM, the pedantic troll Thomas 'Pointed Head' Lahn
>>>> wrote:
>>>
>>> ...
>>>
>>>>> Next time, ask questions the smart way:
>>>>> <http://www.catb.org/~esr/faqs/smart-questions.html>
>>>>>
>>>>
>>>> Smart questions.  Dumb answers - but typical of Pointed Head.
>>>> Completely useless.
>>>>
>>>> James, I suggest you just ignore the troll.  Your life will be much
>>>> better.
>>>
>>> LOL. Since he referred me to a guide on asking questions I was going to
>>> return the favour and refer him to a guide to providing answers.
>>>
>>> That said, I can see that his effort to help was genuine ... I think.
>>>
>>> James
>>>
>>>
>>
>> James, "Pointed Head" is a troll, well-known in several newsgroups.
>> This (lack of) answer is typical of most of his posts.  The only time he
>> gets something even halfway right is when someone else has answered the
>> question first, often times with code.  Then two days or so later,
>> Pointed Head will copy that post and claim it as his answer.
>>
>> I suggest you just ignore his crap.  The only reason I responded was for
>> the benefit of you and other readers - showing him for what he is, to
>> the uninformed.
>>
> 
> I am so utterly fed up with this troll shit. If you feel compelled to
> comment every posting of Mr. Spock with "ignore the troll" I should
> write a bot to answer your postings the same way.
> 
> /Str.

Frankly, I don't give a damn.

I think it's important for people new to the group to know what Pointed
Head is - and that he is no way represents the rest of the people in the
group.

If you don't like it, don't read it.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#14642

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2014-11-26 14:24 +0100
Message-ID<cdm2kaFsd3gU1@mid.uni-berlin.de>
In reply to#14641
On 26.11.2014 13:51, Jerry Stuckle wrote:
> On 11/26/2014 4:26 AM, M. Strobel wrote:
>> On 06.11.2014 17:32, Jerry Stuckle wrote:
>>> On 11/6/2014 10:39 AM, James Harris wrote:
>>>> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
>>>> news:m3g01n$eu7$1@dont-email.me...
>>>>> On 11/5/2014 10:54 PM, the pedantic troll Thomas 'Pointed Head' Lahn
>>>>> wrote:
>>>>
>>>> ...
>>>>
>>>>>> Next time, ask questions the smart way:
>>>>>> <http://www.catb.org/~esr/faqs/smart-questions.html>
>>>>>>
>>>>>
>>>>> Smart questions.  Dumb answers - but typical of Pointed Head.
>>>>> Completely useless.
>>>>>
>>>>> James, I suggest you just ignore the troll.  Your life will be much
>>>>> better.
>>>>
>>>> LOL. Since he referred me to a guide on asking questions I was going to
>>>> return the favour and refer him to a guide to providing answers.
>>>>
>>>> That said, I can see that his effort to help was genuine ... I think.
>>>>
>>>> James
>>>>
>>>>
>>>
>>> James, "Pointed Head" is a troll, well-known in several newsgroups.
>>> This (lack of) answer is typical of most of his posts.  The only time he
>>> gets something even halfway right is when someone else has answered the
>>> question first, often times with code.  Then two days or so later,
>>> Pointed Head will copy that post and claim it as his answer.
>>>
>>> I suggest you just ignore his crap.  The only reason I responded was for
>>> the benefit of you and other readers - showing him for what he is, to
>>> the uninformed.
>>>
>>
>> I am so utterly fed up with this troll shit. If you feel compelled to
>> comment every posting of Mr. Spock with "ignore the troll" I should
>> write a bot to answer your postings the same way.
>>
>> /Str.
>
> Frankly, I don't give a damn.
>
> I think it's important for people new to the group to know what Pointed
> Head is - and that he is no way represents the rest of the people in the
> group.
>
> If you don't like it, don't read it.
>
If you don't like it, don't read it. Same to you.

/Str.

[toc] | [prev] | [next] | [standalone]


#14643

FromJerry Stuckle <jstucklex@attglobal.net>
Date2014-11-26 08:36 -0500
Message-ID<m54l09$b88$1@dont-email.me>
In reply to#14642
On 11/26/2014 8:24 AM, M. Strobel wrote:
> On 26.11.2014 13:51, Jerry Stuckle wrote:
>> On 11/26/2014 4:26 AM, M. Strobel wrote:
>>> On 06.11.2014 17:32, Jerry Stuckle wrote:
>>>> On 11/6/2014 10:39 AM, James Harris wrote:
>>>>> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
>>>>> news:m3g01n$eu7$1@dont-email.me...
>>>>>> On 11/5/2014 10:54 PM, the pedantic troll Thomas 'Pointed Head' Lahn
>>>>>> wrote:
>>>>>
>>>>> ...
>>>>>
>>>>>>> Next time, ask questions the smart way:
>>>>>>> <http://www.catb.org/~esr/faqs/smart-questions.html>
>>>>>>>
>>>>>>
>>>>>> Smart questions.  Dumb answers - but typical of Pointed Head.
>>>>>> Completely useless.
>>>>>>
>>>>>> James, I suggest you just ignore the troll.  Your life will be much
>>>>>> better.
>>>>>
>>>>> LOL. Since he referred me to a guide on asking questions I was
>>>>> going to
>>>>> return the favour and refer him to a guide to providing answers.
>>>>>
>>>>> That said, I can see that his effort to help was genuine ... I think.
>>>>>
>>>>> James
>>>>>
>>>>>
>>>>
>>>> James, "Pointed Head" is a troll, well-known in several newsgroups.
>>>> This (lack of) answer is typical of most of his posts.  The only
>>>> time he
>>>> gets something even halfway right is when someone else has answered the
>>>> question first, often times with code.  Then two days or so later,
>>>> Pointed Head will copy that post and claim it as his answer.
>>>>
>>>> I suggest you just ignore his crap.  The only reason I responded was
>>>> for
>>>> the benefit of you and other readers - showing him for what he is, to
>>>> the uninformed.
>>>>
>>>
>>> I am so utterly fed up with this troll shit. If you feel compelled to
>>> comment every posting of Mr. Spock with "ignore the troll" I should
>>> write a bot to answer your postings the same way.
>>>
>>> /Str.
>>
>> Frankly, I don't give a damn.
>>
>> I think it's important for people new to the group to know what Pointed
>> Head is - and that he is no way represents the rest of the people in the
>> group.
>>
>> If you don't like it, don't read it.
>>
> If you don't like it, don't read it. Same to you.
> 
> /Str.

Unlike you, I'm not posting for MY benefit.  I'm posting for the benefit
of new readers.  I'd hate for them to think everyone was like Pointed
Head or you.  Many of us are quite helpful.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#14644

FromMatthew Carter <m@ahungry.com>
Date2014-11-26 10:21 -0500
Message-ID<87zjbej8cs.fsf@ahungry.com>
In reply to#14643
Jerry Stuckle <jstucklex@attglobal.net> writes:

> On 11/26/2014 8:24 AM, M. Strobel wrote:
>> On 26.11.2014 13:51, Jerry Stuckle wrote:
>>> On 11/26/2014 4:26 AM, M. Strobel wrote:
>>>> On 06.11.2014 17:32, Jerry Stuckle wrote:
>>>>> On 11/6/2014 10:39 AM, James Harris wrote:
>>>>>> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
>>>>>> news:m3g01n$eu7$1@dont-email.me...
>>>>>>> On 11/5/2014 10:54 PM, the pedantic troll Thomas 'Pointed Head' Lahn
>>>>>>> wrote:
>>>>>>
>>>>>> ...
>>>>>>
>>>>>>>> Next time, ask questions the smart way:
>>>>>>>> <http://www.catb.org/~esr/faqs/smart-questions.html>
>>>>>>>>
>>>>>>>
>>>>>>> Smart questions.  Dumb answers - but typical of Pointed Head.
>>>>>>> Completely useless.
>>>>>>>
>>>>>>> James, I suggest you just ignore the troll.  Your life will be much
>>>>>>> better.
>>>>>>
>>>>>> LOL. Since he referred me to a guide on asking questions I was
>>>>>> going to
>>>>>> return the favour and refer him to a guide to providing answers.
>>>>>>
>>>>>> That said, I can see that his effort to help was genuine ... I think.
>>>>>>
>>>>>> James
>>>>>>
>>>>>>
>>>>>
>>>>> James, "Pointed Head" is a troll, well-known in several newsgroups.
>>>>> This (lack of) answer is typical of most of his posts.  The only
>>>>> time he
>>>>> gets something even halfway right is when someone else has answered the
>>>>> question first, often times with code.  Then two days or so later,
>>>>> Pointed Head will copy that post and claim it as his answer.
>>>>>
>>>>> I suggest you just ignore his crap.  The only reason I responded was
>>>>> for
>>>>> the benefit of you and other readers - showing him for what he is, to
>>>>> the uninformed.
>>>>>
>>>>
>>>> I am so utterly fed up with this troll shit. If you feel compelled to
>>>> comment every posting of Mr. Spock with "ignore the troll" I should
>>>> write a bot to answer your postings the same way.
>>>>
>>>> /Str.
>>>
>>> Frankly, I don't give a damn.
>>>
>>> I think it's important for people new to the group to know what Pointed
>>> Head is - and that he is no way represents the rest of the people in the
>>> group.
>>>
>>> If you don't like it, don't read it.
>>>
>> If you don't like it, don't read it. Same to you.
>> 
>> /Str.
>
> Unlike you, I'm not posting for MY benefit.  I'm posting for the benefit
> of new readers.  I'd hate for them to think everyone was like Pointed
> Head or you.  Many of us are quite helpful.

I'm new to the group (~a month) and PointedEars never really came off too abrasive
to me - I guess it depends on each person's sensitivity to pedantry, and
I find it relatively easy to glance past any into the meatier parts of
the posts. 

-- 
Matthew Carter (m@ahungry.com)
http://ahungry.com

[toc] | [prev] | [next] | [standalone]


#14646

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2014-11-26 20:57 +0100
Message-ID<cdmpkqF4433U1@mid.uni-berlin.de>
In reply to#14644
On 26.11.2014 16:21, Matthew Carter wrote:
> Jerry Stuckle <jstucklex@attglobal.net> writes:
>
>> On 11/26/2014 8:24 AM, M. Strobel wrote:
>>> On 26.11.2014 13:51, Jerry Stuckle wrote:
>>>> On 11/26/2014 4:26 AM, M. Strobel wrote:
>>>>> On 06.11.2014 17:32, Jerry Stuckle wrote:
>>>>>> On 11/6/2014 10:39 AM, James Harris wrote:
>>>>>>> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
>>>>>>> news:m3g01n$eu7$1@dont-email.me...
>>>>>>>> On 11/5/2014 10:54 PM, the pedantic troll Thomas 'Pointed Head' Lahn
>>>>>>>> wrote:
>>>>>>>
>>>>>>> ...
>>>>>>>
>>>>>>>>> Next time, ask questions the smart way:
>>>>>>>>> <http://www.catb.org/~esr/faqs/smart-questions.html>
>>>>>>>>>
>>>>>>>>
>>>>>>>> Smart questions.  Dumb answers - but typical of Pointed Head.
>>>>>>>> Completely useless.
>>>>>>>>
>>>>>>>> James, I suggest you just ignore the troll.  Your life will be much
>>>>>>>> better.
>>>>>>>
>>>>>>> LOL. Since he referred me to a guide on asking questions I was
>>>>>>> going to
>>>>>>> return the favour and refer him to a guide to providing answers.
>>>>>>>
>>>>>>> That said, I can see that his effort to help was genuine ... I think.
>>>>>>>
>>>>>>> James
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> James, "Pointed Head" is a troll, well-known in several newsgroups.
>>>>>> This (lack of) answer is typical of most of his posts.  The only
>>>>>> time he
>>>>>> gets something even halfway right is when someone else has answered the
>>>>>> question first, often times with code.  Then two days or so later,
>>>>>> Pointed Head will copy that post and claim it as his answer.
>>>>>>
>>>>>> I suggest you just ignore his crap.  The only reason I responded was
>>>>>> for
>>>>>> the benefit of you and other readers - showing him for what he is, to
>>>>>> the uninformed.
>>>>>>
>>>>>
>>>>> I am so utterly fed up with this troll shit. If you feel compelled to
>>>>> comment every posting of Mr. Spock with "ignore the troll" I should
>>>>> write a bot to answer your postings the same way.
>>>>>
>>>>> /Str.
>>>>
>>>> Frankly, I don't give a damn.
>>>>
>>>> I think it's important for people new to the group to know what Pointed
>>>> Head is - and that he is no way represents the rest of the people in the
>>>> group.
>>>>
>>>> If you don't like it, don't read it.
>>>>
>>> If you don't like it, don't read it. Same to you.
>>>
>>> /Str.
>>
>> Unlike you, I'm not posting for MY benefit.  I'm posting for the benefit
>> of new readers.  I'd hate for them to think everyone was like Pointed
>> Head or you.  Many of us are quite helpful.
>
> I'm new to the group (~a month) and PointedEars never really came off too abrasive
> to me - I guess it depends on each person's sensitivity to pedantry, and
> I find it relatively easy to glance past any into the meatier parts of
> the posts.
>
Of course you pick the cherries, and try to ignore the (growing) gargabe. And have 
your own opinion.

"Abrasive" is a good word for it. These people need some contradiction, from time to 
time.


/Str.

[toc] | [prev] | [next] | [standalone]


#14647

FromJerry Stuckle <jstucklex@attglobal.net>
Date2014-11-26 16:21 -0500
Message-ID<m55g7o$tiv$1@dont-email.me>
In reply to#14644
On 11/26/2014 10:21 AM, Matthew Carter wrote:
> Jerry Stuckle <jstucklex@attglobal.net> writes:
> 
>> On 11/26/2014 8:24 AM, M. Strobel wrote:
>>> On 26.11.2014 13:51, Jerry Stuckle wrote:
>>>> On 11/26/2014 4:26 AM, M. Strobel wrote:
>>>>> On 06.11.2014 17:32, Jerry Stuckle wrote:
>>>>>> On 11/6/2014 10:39 AM, James Harris wrote:
>>>>>>> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
>>>>>>> news:m3g01n$eu7$1@dont-email.me...
>>>>>>>> On 11/5/2014 10:54 PM, the pedantic troll Thomas 'Pointed Head' Lahn
>>>>>>>> wrote:
>>>>>>>
>>>>>>> ...
>>>>>>>
>>>>>>>>> Next time, ask questions the smart way:
>>>>>>>>> <http://www.catb.org/~esr/faqs/smart-questions.html>
>>>>>>>>>
>>>>>>>>
>>>>>>>> Smart questions.  Dumb answers - but typical of Pointed Head.
>>>>>>>> Completely useless.
>>>>>>>>
>>>>>>>> James, I suggest you just ignore the troll.  Your life will be much
>>>>>>>> better.
>>>>>>>
>>>>>>> LOL. Since he referred me to a guide on asking questions I was
>>>>>>> going to
>>>>>>> return the favour and refer him to a guide to providing answers.
>>>>>>>
>>>>>>> That said, I can see that his effort to help was genuine ... I think.
>>>>>>>
>>>>>>> James
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> James, "Pointed Head" is a troll, well-known in several newsgroups.
>>>>>> This (lack of) answer is typical of most of his posts.  The only
>>>>>> time he
>>>>>> gets something even halfway right is when someone else has answered the
>>>>>> question first, often times with code.  Then two days or so later,
>>>>>> Pointed Head will copy that post and claim it as his answer.
>>>>>>
>>>>>> I suggest you just ignore his crap.  The only reason I responded was
>>>>>> for
>>>>>> the benefit of you and other readers - showing him for what he is, to
>>>>>> the uninformed.
>>>>>>
>>>>>
>>>>> I am so utterly fed up with this troll shit. If you feel compelled to
>>>>> comment every posting of Mr. Spock with "ignore the troll" I should
>>>>> write a bot to answer your postings the same way.
>>>>>
>>>>> /Str.
>>>>
>>>> Frankly, I don't give a damn.
>>>>
>>>> I think it's important for people new to the group to know what Pointed
>>>> Head is - and that he is no way represents the rest of the people in the
>>>> group.
>>>>
>>>> If you don't like it, don't read it.
>>>>
>>> If you don't like it, don't read it. Same to you.
>>>
>>> /Str.
>>
>> Unlike you, I'm not posting for MY benefit.  I'm posting for the benefit
>> of new readers.  I'd hate for them to think everyone was like Pointed
>> Head or you.  Many of us are quite helpful.
> 
> I'm new to the group (~a month) and PointedEars never really came off too abrasive
> to me - I guess it depends on each person's sensitivity to pedantry, and
> I find it relatively easy to glance past any into the meatier parts of
> the posts. 
> 

Stick around long enough and you'll see what I mean about "Pointed
head".  He's well-known as a troll in several newsgroups - not just here.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#14501

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2014-11-06 18:27 +0100
Message-ID<m3gb2i$ise$1@solani.org>
In reply to#14494
Am 06.11.2014 um 16:39 schrieb James Harris:

> That said, I can see that his effort to help was genuine ... I think.

Most certainly.  And his signature in
<news:9211084.ztrPHf13qF@PointedEars.de> is genuine, too.

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#14496

From"James Harris" <james.harris.1@gmail.com>
Date2014-11-06 15:58 +0000
Message-ID<m3g5qi$6td$1@dont-email.me>
In reply to#14486
"Thomas 'PointedEars' Lahn" <PointedEars@web.de> wrote in message 
news:9211084.ztrPHf13qF@PointedEars.de...
> James Harris wrote:
>
>> I am looking for a good way to pull ad-hoc info from a database into a
>> web page. By "good" I mean a way that is efficient for the server and
>> convenient for the person writing the web page.
>
> You can't have your cake and eat it.

That's too vague to reply to. Maybe I want icing and a cherry on it too....

>> Some of the ad-hoc info will be scalars. Some will be lists and, 
>> possibly,
>> some will be tabular.
>
> With regard to data, a list is a table with one column.

With regard to data, yes.

>> Is there already a standard way to do things like this?
>
> Yes.

Which is...?

>> It's been a whiile since I used PHP but from a quick look it seems it may
>> be best to define a number of functions to retrieve and echo data.
>
> Three at most.

I probably agree that three would be a good target but that will depend on 
how I retrieve the data. I would like to be able to pull back a whole table 
(or a subset of rows thereof) from the database and include it in the web 
page with a single call so as to keep the page source simple and easy for 
people to use. If I do that then the function which pulls the data has to 
know how to format it - and formats may vary. There may be something I can 
do with templates and default parameters to simplify this.

As a good compromise there may be a way to specify the layout of a table as 
three functions: header, each row, and footer. Again, am not sure yet.

>> A call to the scalar function would be something like
>>
>>   scalar_get("key")
>>
>> where the key uniquely identifies a cell in a table.
>
> You mean a _column_.

No, I mean a cell (or a field of a record, if you prefer). The key would be 
a unique identifier for the scalar that I want to embed in the page, not a 
key in a database sense.

...

>> The subroutine would just echo the result into the output html that gets
>> sent to the web browser
>
> As a rule of thumb, you want to escape all output.  You may even have to
> recode it for proper display.

Good point.

>> Is that reasonable
>
> No.

IYO.

>> and is there a way to make the subroutine efficient given that there may
>> be many scalar_get() calls in the body of the page?
>
> Mu. [1]

...

> [1] You can cache query results so that you do not have to issue a new 
> query
>    when you need data from the same data set.  But the notion of "ad-hoc
>    data" contradicts with that approach; "ad-hoc data" changes.

I was more concerned with reusing the connection to the database. If you 
could take a look at the reply I made to Jerry Stuckle I included in it a 
working function that illustrates the problem. In terms of scalars - which 
the posted code illustrates - I guess I would want to connect to the 
database and prepare any queries once and then use the queries an arbitrary 
number of times in the page.

James

[toc] | [prev] | [next] | [standalone]


#14508

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-11-06 21:34 +0100
Message-ID<4030537.OAdHOdONia@PointedEars.de>
In reply to#14496
James Harris wrote:

> "Thomas 'PointedEars' Lahn" […] wrote:
>> James Harris wrote:
>>> I am looking for a good way to pull ad-hoc info from a database into a
>>> web page. By "good" I mean a way that is efficient for the server and
>>> convenient for the person writing the web page.
>> You can't have your cake and eat it.
> 
> That's too vague to reply to. Maybe I want icing and a cherry on it
> too....

(You still could not do it.  Once eaten it would be gone.)

OK, in non-idiomatic English: The goals you have set are mutually exclusive.  
The most efficient way for the server is if you issue a pure database query.  
The most convenient for the person writing the “web page” (there is no such 
thing) is if you do not do that, because you would have to hide from them 
the complexity that you have to implement elsewhere so that it looks simple 
*to them*.
 
>>> Some of the ad-hoc info will be scalars. Some will be lists and,
>>> possibly, some will be tabular.
>> With regard to data, a list is a table with one column.
> 
> With regard to data, yes.

So as this is about “pulling *data*” (from a relational database), the 
distinction you have made is purely artificial.  Data and presentation of 
data (which raises questions like “Do I use an HTML ‘ul’ element or a 
‘table‘ element?”) are separate things.
 
>>> Is there already a standard way to do things like this?
>> Yes.
> 
> Which is...?

There *are* “standard” ways to make database queries.  You are not currently 
employing any.  As a training course about how to properly write a database-
aware application in PHP is far beyond the scope of this newsgroup, I 
suggest you RTFM and STFW first, and come back with more specific questions 
later.  (And double-check against that all replies you receive in the 
meantime.)

But it turns out that “things like this” is too vague to reply to in the 
first place.  And too contradicting.
 
>>> It's been a whiile since I used PHP but from a quick look it seems it
>>> may be best to define a number of functions to retrieve and echo data.
>>
>> Three at most.
> 
> I probably agree that three would be a good target but that will depend on
> how I retrieve the data.

Yes, I was talking only about the entry points, given your very short 
specifications.  The other "functions" called by those methods would 
actually be methods, because of OOP – if you used any non-methods in the 
first place.

> I would like to be able to pull back a whole table (or a subset of rows
> thereof) from the database

There is a corresponding function and method with mysqli, and a 
corresponding method with PDO.  You will find it easily in the PHP manual if 
you replace “pull back” with the more appropriate term “fetch”.  And keep in 
mind that you can filter arrays.

> and include it in the web page with a single call so as to keep the page
> source simple and easy for people to use. If I do that then the function
> which pulls the data has to know how to format it

No, it does not.  Not separating data and presentation of data is your third 
mistake.

> - and formats may vary.

So do not do that.  Either include the formatting in the template or have 
*another* function/method called in the template that uses the retrieved 
data and does the formatting for you/the template author.  Preferably by 
include, unless the data to format is atomic.

> There may be something I can do with templates and default parameters to
> simplify this.

There is (there are many, actually).  Why do you not do *some* research and 
*try* *before* you ask?
 
> As a good compromise there may be a way to specify the layout of a table
> as three functions: header, each row, and footer. Again, am not sure yet.

You are right not to be sure; this is not a sound (or efficient) approach.  
Read on includes instead (that is not a new thing at all; one must wonder at 
this point if you have done *any* PHP development before).
 
>>> A call to the scalar function would be something like
>>>
>>>   scalar_get("key")
>>>
>>> where the key uniquely identifies a cell in a table.
>> You mean a _column_.
> 
> No, I mean a cell (or a field of a record, if you prefer).

I do.  A database table is _not_ like a spreadsheet.

> The key would-be a unique identifier for the scalar that I want to embed 
> in the page, not a key in a database sense.

That *is* the definition of a database table key.  You should also 
(re-)learn basic database theory first.
 
>>> Is that reasonable
>> No.
> 
> IYO.

What else could it be?
 
>>> and is there a way to make the subroutine efficient given that there may
>>> be many scalar_get() calls in the body of the page?
>>
>> Mu. [1]
> 
> ...
> 
>> [1] You can cache query results so that you do not have to issue a new
>> query
>>    when you need data from the same data set.  But the notion of "ad-hoc
>>    data" contradicts with that approach; "ad-hoc data" changes.
> 
> I was more concerned with reusing the connection to the database.

The proper way, the “standard way” if you will, is to use a class whose 
instance encapsulates all database-relevant data, including the connection 
resource, and actions.

> If you could take a look at the reply I made to Jerry Stuckle

In the first reply you made to Jerry Stuckle you demonstrated behavior 
indicating that it is not worthwhile investing (my) free time into your 
problems as you only laughed at the good advice that I gave you.  I do not 
see that this has changed much.  Neither do my replies to you.

However, from your other reply ISTM you are unaware of class-based object-
oriented programming in PHP or in general, which is basic knowledge by now.  
So if you want a robust solution, you should learn that first (after which 
you will discover that this wheel has already been invented by Zend, the PHP 
company).  After that, you want to look into PDO and Prepared Statement to 
avoid the SQL injection that your code currently is susceptible to.

> I included in it a working function that illustrates the problem. In terms
> of scalars - which the posted code illustrates - I guess I would want to
> connect to the database and prepare any queries once and then use the
> queries an arbitrary number of times in the page.

Reasonable.  See the paragraph above for that.

-- 
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#14489

FromJerry Stuckle <jstucklex@attglobal.net>
Date2014-11-05 23:00 -0500
Message-ID<m3erom$ri2$1@dont-email.me>
In reply to#14480
On 11/5/2014 7:23 PM, James Harris wrote:
> I am looking for a good way to pull ad-hoc info from a database into a web 
> page. By "good" I mean a way that is efficient for the server and convenient 
> for the person writing the web page. Some of the ad-hoc info will be 
> scalars. Some will be lists and, possibly, some will be tabular. Is there 
> already a standard way to do things like this?
> 
> It's been a whiile since I used PHP but from a quick look it seems it may be 
> best to define a number of functions to retrieve and echo data. A call to 
> the scalar function would be something like
> 
>   scalar_get("key")
> 
> where the key uniquely identifies a cell in a table. The subroutine would 
> just echo the result into the output html that gets sent to the web browser. 
> Is that reasonable and is there a way to make the subroutine efficient given 
> that there may be many scalar_get() calls in the body of the page?
> 
> James
> 
> 

First of all, there is not "cell" in a SQL database table.  You get one
or more rows, and can select columns from that row.  If you have a
primary key, you will get a single row back by selecting on that key.

As for getting multiple rows - I normally select all rows of interest,
and display them in a loop.  That is much more efficient than retrieving
multiple rows based on the selection criteria used to retrieve the
primary keys.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#14493

From"James Harris" <james.harris.1@gmail.com>
Date2014-11-06 15:29 +0000
Message-ID<m3g44n$ve0$1@dont-email.me>
In reply to#14489
"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message 
news:m3erom$ri2$1@dont-email.me...
> On 11/5/2014 7:23 PM, James Harris wrote:
>> I am looking for a good way to pull ad-hoc info from a database into a 
>> web
>> page. By "good" I mean a way that is efficient for the server and 
>> convenient
>> for the person writing the web page. Some of the ad-hoc info will be
>> scalars. Some will be lists and, possibly, some will be tabular. Is there
>> already a standard way to do things like this?
>>
>> It's been a whiile since I used PHP but from a quick look it seems it may 
>> be
>> best to define a number of functions to retrieve and echo data. A call to
>> the scalar function would be something like
>>
>>   scalar_get("key")
>>
>> where the key uniquely identifies a cell in a table. The subroutine would
>> just echo the result into the output html that gets sent to the web 
>> browser.
>> Is that reasonable and is there a way to make the subroutine efficient 
>> given
>> that there may be many scalar_get() calls in the body of the page?
>>
>> James
>>
>>
>
> First of all, there is not "cell" in a SQL database table.  You get one
> or more rows, and can select columns from that row.  If you have a
> primary key, you will get a single row back by selecting on that key.

Would "field" be better? Whatever the case I mean the intersection of a row 
and a column of a table, i.e. a specific field in a specific record where 
the record is idenfitied by a unique key.

To illustrate what I was asking in my original post I have come up with a 
function to retrieve scalars. It works but I am concerned that it may be 
inefficient due to reissuing the database-connect call each time. Is there a 
better way to write this so that the connection is opened once and just 
reused as many times as the function is called? Would making the connection 
a gobal be the way to do it?

function scalar_get($key) {
  global $sv, $db, $un, $pw;
  echo "In function scalar_get($key)<br/>";
  echo "Make db connection to $db<br/>";

  $conn = mysqli_connect($sv, $un, $pw);
  if (!$conn) {
    die("Database connection failed: " . mysqli_connect_error());
  }
  echo "Database connected successfully<br/>";

  $sql = "select value from $db.scalars where id = \"$key\";";
  $result = mysqli_query($conn, $sql);
  if ($result === FALSE) {
    echo "Query ($sql) failed: " . mysqli_error($conn) . "<br/>";
  } elseif (mysqli_num_rows($result) !== 1) {
    echo "Expected one row, got " . mysqli_num_rows($result) . "<br/>";
  } else {
    echo "Got one row<br/>";
    $row = mysqli_fetch_row($result);
    echo "Result is ($row[0])<br/>";
  }
}

The idea is that a function like the above (but less verbose!) would be 
called an arbitrary number of times in the main body of a page by means of 
calls such as the following. At least for scalars I may get it to return the 
string instead of printing it.

  scalar_get("forename");
  echo "<br/>";
  scalar_get("surname");
  echo "<br/>";

> As for getting multiple rows - I normally select all rows of interest,
> and display them in a loop.  That is much more efficient than retrieving
> multiple rows based on the selection criteria used to retrieve the
> primary keys.

Understood.

James

[toc] | [prev] | [next] | [standalone]


#14495

FromMatthew Carter <m@ahungry.com>
Date2014-11-06 10:44 -0500
Message-ID<87oaskxriy.fsf@ahungry.com>
In reply to#14493
"James Harris" <james.harris.1@gmail.com> writes:

> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message 
> news:m3erom$ri2$1@dont-email.me...
>> On 11/5/2014 7:23 PM, James Harris wrote:
>>> I am looking for a good way to pull ad-hoc info from a database into a 
>>> web
>>> page. By "good" I mean a way that is efficient for the server and 
>>> convenient
>>> for the person writing the web page. Some of the ad-hoc info will be
>>> scalars. Some will be lists and, possibly, some will be tabular. Is there
>>> already a standard way to do things like this?
>>>
>>> It's been a whiile since I used PHP but from a quick look it seems it may 
>>> be
>>> best to define a number of functions to retrieve and echo data. A call to
>>> the scalar function would be something like
>>>
>>>   scalar_get("key")
>>>
>>> where the key uniquely identifies a cell in a table. The subroutine would
>>> just echo the result into the output html that gets sent to the web 
>>> browser.
>>> Is that reasonable and is there a way to make the subroutine efficient 
>>> given
>>> that there may be many scalar_get() calls in the body of the page?
>>>
>>> James
>>>
>>>
>>
>> First of all, there is not "cell" in a SQL database table.  You get one
>> or more rows, and can select columns from that row.  If you have a
>> primary key, you will get a single row back by selecting on that key.
>
> Would "field" be better? Whatever the case I mean the intersection of a row 
> and a column of a table, i.e. a specific field in a specific record where 
> the record is idenfitied by a unique key.
>
> To illustrate what I was asking in my original post I have come up with a 
> function to retrieve scalars. It works but I am concerned that it may be 
> inefficient due to reissuing the database-connect call each time. Is there a 
> better way to write this so that the connection is opened once and just 
> reused as many times as the function is called? Would making the connection 
> a gobal be the way to do it?
>
> function scalar_get($key) {
>   global $sv, $db, $un, $pw;
>   echo "In function scalar_get($key)<br/>";
>   echo "Make db connection to $db<br/>";
>
>   $conn = mysqli_connect($sv, $un, $pw);
>   if (!$conn) {
>     die("Database connection failed: " . mysqli_connect_error());
>   }
>   echo "Database connected successfully<br/>";
>
>   $sql = "select value from $db.scalars where id = \"$key\";";
>   $result = mysqli_query($conn, $sql);
>   if ($result === FALSE) {
>     echo "Query ($sql) failed: " . mysqli_error($conn) . "<br/>";
>   } elseif (mysqli_num_rows($result) !== 1) {
>     echo "Expected one row, got " . mysqli_num_rows($result) . "<br/>";
>   } else {
>     echo "Got one row<br/>";
>     $row = mysqli_fetch_row($result);
>     echo "Result is ($row[0])<br/>";
>   }
> }
>
> The idea is that a function like the above (but less verbose!) would be 
> called an arbitrary number of times in the main body of a page by means of 
> calls such as the following. At least for scalars I may get it to return the 
> string instead of printing it.
>
>   scalar_get("forename");
>   echo "<br/>";
>   scalar_get("surname");
>   echo "<br/>";
>
>> As for getting multiple rows - I normally select all rows of interest,
>> and display them in a loop.  That is much more efficient than retrieving
>> multiple rows based on the selection criteria used to retrieve the
>> primary keys.
>
> Understood.
>
> James
>
>

I would either:
  - Wrap the function in a class and store the DB connection as a class
  variable
  - Pass the connection as an additional parameter to the function
  - If you insist on including a 'global' line in there, use the
  connection as the global (instead of the name/pass etc.)

Opening a database each time you want to do a single query is more
inefficient than opening and keeping open.

Is your database going to be two column like this?

    --------------
    | id | value |
    --------------

If so, you could probably make 'id' your unique key and omit your elseif
clause in the row checking snippet (it seems like having duplicate ids
would break the manner in which you want to query this information).

-- 
Matthew Carter (m@ahungry.com)
http://ahungry.com

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.php


csiph-web