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


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

fetching all items at once - how do you code to display them?

Started byrichard <noreply@example.com>
First post2015-04-03 21:54 -0400
Last post2015-04-06 02:05 +0000
Articles 20 on this page of 25 — 7 participants

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


Contents

  fetching all items at once - how do you code to display them? richard <noreply@example.com> - 2015-04-03 21:54 -0400
    Re: fetching all items at once - how do you code to display them? Jerry Stuckle <jstucklex@attglobal.net> - 2015-04-03 22:14 -0400
    Re: fetching all items at once - how do you code to display them? Denis McMahon <denismfmcmahon@gmail.com> - 2015-04-04 23:28 +0000
      Re: fetching all items at once - how do you code to display them? richard <noreply@example.com> - 2015-04-04 19:32 -0400
        Re: fetching all items at once - how do you code to display them? Doug Miller <doug_at_milmac_dot_com@example.com> - 2015-04-05 01:15 +0000
          Re: fetching all items at once - how do you code to display them? richard <noreply@example.com> - 2015-04-05 10:56 -0400
            Re: fetching all items at once - how do you code to display them? Richard Yates <richard@yatesguitar.com> - 2015-04-05 08:14 -0700
              Re: fetching all items at once - how do you code to display them? richard <noreply@example.com> - 2015-04-05 11:24 -0400
            Re: fetching all items at once - how do you code to display them? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-04-05 11:18 -0400
              Re: fetching all items at once - how do you code to display them? richard <noreply@example.com> - 2015-04-05 11:28 -0400
                Re: fetching all items at once - how do you code to display them? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-04-05 11:52 -0400
                  Re: fetching all items at once - how do you code to display them? Doug Miller <doug_at_milmac_dot_com@example.com> - 2015-04-06 02:01 +0000
                    Re: fetching all items at once - how do you code to display them? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-04-08 20:16 -0400
                      Re: fetching all items at once - how do you code to display them? richard <noreply@example.com> - 2015-04-09 22:32 -0400
                        Re: fetching all items at once - how do you code to display them? Richard Heathfield <rjh@cpax.org.uk> - 2015-04-10 07:48 +0100
                        Re: fetching all items at once - how do you code to display them? Doug Miller <doug_at_milmac_dot_com@example.com> - 2015-04-11 03:11 +0000
              Re: fetching all items at once - how do you code to display them? Denis McMahon <denismfmcmahon@gmail.com> - 2015-04-06 07:58 +0000
            Re: fetching all items at once - how do you code to display them? Denis McMahon <denismfmcmahon@gmail.com> - 2015-04-06 07:48 +0000
        Re: fetching all items at once - how do you code to display them? Denis McMahon <denismfmcmahon@gmail.com> - 2015-04-05 04:47 +0000
          Re: fetching all items at once - how do you code to display them? richard <noreply@example.com> - 2015-04-05 10:58 -0400
            Re: fetching all items at once - how do you code to display them? Jerry Stuckle <jstucklex@attglobal.net> - 2015-04-05 11:21 -0400
              Re: fetching all items at once - how do you code to display them? richard <noreply@example.com> - 2015-04-05 11:40 -0400
                Re: fetching all items at once - how do you code to display them? Jerry Stuckle <jstucklex@attglobal.net> - 2015-04-05 14:55 -0400
                Re: fetching all items at once - how do you code to display them? Doug Miller <doug_at_milmac_dot_com@example.com> - 2015-04-06 02:07 +0000
            Re: fetching all items at once - how do you code to display them? Doug Miller <doug_at_milmac_dot_com@example.com> - 2015-04-06 02:05 +0000

Page 1 of 2  [1] 2  Next page →


#15200 — fetching all items at once - how do you code to display them?

Fromrichard <noreply@example.com>
Date2015-04-03 21:54 -0400
Subjectfetching all items at once - how do you code to display them?
Message-ID<46bui2hdar3f$.1qryyy3zcx5um.dlg@40tude.net>
"SELECT * from sixty where (
  (peak='1')
  AND  (year>1959)
  AND  (year<1970)
) ORDER BY year, sid "

Considering this code provided by Erwin Moller, how does one now display
the information?

The standard method of using $row=$result() winds up with only the first
item ending up in a displayed table while the other items are just bunched
up together one after the other.

If I simply fetch one item at a time, the table is displayed as wanted.

By this usage of the word "table" I am not speaking of the database table
stored on the server. But the html displayed table on the page.

[toc] | [next] | [standalone]


#15201

FromJerry Stuckle <jstucklex@attglobal.net>
Date2015-04-03 22:14 -0400
Message-ID<mfnhcv$n3k$1@dont-email.me>
In reply to#15200
On 4/3/2015 9:54 PM, richard wrote:
> "SELECT * from sixty where (
>   (peak='1')
>   AND  (year>1959)
>   AND  (year<1970)
> ) ORDER BY year, sid "
> 
> Considering this code provided by Erwin Moller, how does one now display
> the information?
> 
> The standard method of using $row=$result() winds up with only the first
> item ending up in a displayed table while the other items are just bunched
> up together one after the other.
> 
> If I simply fetch one item at a time, the table is displayed as wanted.
> 
> By this usage of the word "table" I am not speaking of the database table
> stored on the server. But the html displayed table on the page.
> 

Like you do any other time your search returns multiple results.  You
fetch a row and display it.  Repeat as necessary.

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

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


#15202

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2015-04-04 23:28 +0000
Message-ID<mfps3p$j9e$1@dont-email.me>
In reply to#15200
On Fri, 03 Apr 2015 21:54:12 -0400, richard wrote:

> "SELECT * from sixty where (
>   (peak='1')
>   AND  (year>1959)
>   AND  (year<1970)
> ) ORDER BY year, sid "
> 
> Considering this code provided by Erwin Moller, how does one now display
> the information?
> 
> The standard method of using $row=$result() winds up with only the first
> item ending up in a displayed table while the other items are just
> bunched up together one after the other.
> 
> If I simply fetch one item at a time, the table is displayed as wanted.
> 
> By this usage of the word "table" I am not speaking of the database
> table stored on the server. But the html displayed table on the page.

Note that the following is an example that assumes the reader has some 
competencies and understanding of php, and the use of the ellipsis

<?php

// Start the table:

echo "<table>\n";

// print the table header row

echo "<tr> <th>header</th>... </tr>\n";

// use a loop that fetches every row from the mysqli result
// this example assumes the mysqli result is in $result
// $data is a local variable in the loop

while ($data = mysqli_fetch_assoc($result)) {

// in here you write out a single table row for each set of
// $data from the query result

echo "<tr> <td>{$data['fieldname']}</td>... </tr>\n";

}

// close the table

echo "</table>";

?>

-- 
Denis McMahon, denismfmcmahon@gmail.com

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


#15203

Fromrichard <noreply@example.com>
Date2015-04-04 19:32 -0400
Message-ID<1lpvv6118algy.1pzxv594x426f$.dlg@40tude.net>
In reply to#15202
On Sat, 4 Apr 2015 23:28:57 +0000 (UTC), Denis McMahon wrote:

> On Fri, 03 Apr 2015 21:54:12 -0400, richard wrote:
> 
>> "SELECT * from sixty where (
>>   (peak='1')
>>   AND  (year>1959)
>>   AND  (year<1970)
>> ) ORDER BY year, sid "
>> 
>> Considering this code provided by Erwin Moller, how does one now display
>> the information?
>> 
>> The standard method of using $row=$result() winds up with only the first
>> item ending up in a displayed table while the other items are just
>> bunched up together one after the other.
>> 
>> If I simply fetch one item at a time, the table is displayed as wanted.
>> 
>> By this usage of the word "table" I am not speaking of the database
>> table stored on the server. But the html displayed table on the page.
> 
> Note that the following is an example that assumes the reader has some 
> competencies and understanding of php, and the use of the ellipsis
> 
> <?php
> 
> // Start the table:
> 
> echo "<table>\n";
> 
> // print the table header row
> 
> echo "<tr> <th>header</th>... </tr>\n";
> 
> // use a loop that fetches every row from the mysqli result
> // this example assumes the mysqli result is in $result
> // $data is a local variable in the loop
> 
> while ($data = mysqli_fetch_assoc($result)) {
> 
> // in here you write out a single table row for each set of
> // $data from the query result
> 
> echo "<tr> <td>{$data['fieldname']}</td>... </tr>\n";
> 
> }
> 
> // close the table
> 
> echo "</table>";
> 
> ?>

Done that.
What I get is 11 duplicates of the first item.
So why does it stop at 11 when I have 200 records?

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


#15204

FromDoug Miller <doug_at_milmac_dot_com@example.com>
Date2015-04-05 01:15 +0000
Message-ID<XnsA472D868748A8dougmilmaccom@213.239.209.88>
In reply to#15203
richard <noreply@example.com> wrote in news:1lpvv6118algy.1pzxv594x426f$.dlg@
40tude.net:

[...]
> 
> Done that.
> What I get is 11 duplicates of the first item.
> So why does it stop at 11 when I have 200 records?
> 
Kind of hard to answer that question when we can't see your code....

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


#15206

Fromrichard <noreply@example.com>
Date2015-04-05 10:56 -0400
Message-ID<1at1d2mgi02g2$.1ptb1cxropkt8$.dlg@40tude.net>
In reply to#15204
On Sun, 5 Apr 2015 01:15:55 +0000 (UTC), Doug Miller wrote:

> richard <noreply@example.com> wrote in news:1lpvv6118algy.1pzxv594x426f$.dlg@
> 40tude.net:
> 
> [...]
>> 
>> Done that.
>> What I get is 11 duplicates of the first item.
>> So why does it stop at 11 when I have 200 records?
>> 
> Kind of hard to answer that question when we can't see your code....

$result = mysqli_query($link,"SELECT * from sixty where (
  (peak='1')
	and (year>1959)
	and (year<1970)
  ) ORDER BY year, sid ");
$rows = mysqli_fetch_assoc($result);

$total=count($rows);
echo $total;  // displays "11"
echo "<br>";
echo $rows['title'];  //displays nothing.

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


#15208

FromRichard Yates <richard@yatesguitar.com>
Date2015-04-05 08:14 -0700
Message-ID<0uj2ia1vvmacc9odqutqjes42b8kj3spjd@4ax.com>
In reply to#15206
On Sun, 5 Apr 2015 10:56:15 -0400, richard <noreply@example.com>
wrote:

>On Sun, 5 Apr 2015 01:15:55 +0000 (UTC), Doug Miller wrote:
>
>> richard <noreply@example.com> wrote in news:1lpvv6118algy.1pzxv594x426f$.dlg@
>> 40tude.net:
>> 
>> [...]
>>> 
>>> Done that.
>>> What I get is 11 duplicates of the first item.
>>> So why does it stop at 11 when I have 200 records?
>>> 
>> Kind of hard to answer that question when we can't see your code....
>
>$result = mysqli_query($link,"SELECT * from sixty where (
>  (peak='1')
>	and (year>1959)
>	and (year<1970)
>  ) ORDER BY year, sid ");
>$rows = mysqli_fetch_assoc($result);
>
>$total=count($rows);
>echo $total;  // displays "11"
>echo "<br>";
>echo $rows['title'];  //displays nothing.

In your code, $total does not give you the number of rows, it gives
you the size of the $row array (which is the number of columns in each
record).

You get the number of rows with $total=mysqli_num_rows($result);

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


#15211

Fromrichard <noreply@example.com>
Date2015-04-05 11:24 -0400
Message-ID<1a8b7v7x5juhk.tcqgzxjhwfgo$.dlg@40tude.net>
In reply to#15208
On Sun, 05 Apr 2015 08:14:54 -0700, Richard Yates wrote:

> $total=mysqli_num_rows($result);

thanks.
that now shows the correct total of records.

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


#15209

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2015-04-05 11:18 -0400
Message-ID<XmcUw.164808$Dd3.150064@fx19.iad>
In reply to#15206
On Sunday April 5 2015 10:56, in comp.lang.php, "richard"
<noreply@example.com> wrote:

> On Sun, 5 Apr 2015 01:15:55 +0000 (UTC), Doug Miller wrote:
> 
>> richard <noreply@example.com> wrote in
>> news:1lpvv6118algy.1pzxv594x426f$.dlg@ 40tude.net:
>> 
>> [...]
>>> 
>>> Done that.
>>> What I get is 11 duplicates of the first item.
>>> So why does it stop at 11 when I have 200 records?

Because you are doing it wrong. See the comments below.


>> Kind of hard to answer that question when we can't see your code....
> 
> $result = mysqli_query($link,"SELECT * from sixty where (
>   (peak='1')
> and (year>1959)
> and (year<1970)
>   ) ORDER BY year, sid ");
> $rows = mysqli_fetch_assoc($result);

mysqli_fetch_assoc() populates an associative array with  *a SINGLE row* of
the resultset.

> $total=count($rows);
> echo $total;  // displays "11"

You have eleven columns in the fetched row.

> echo "<br>";
> echo $rows['title'];  //displays nothing.

Do you have a table column named 'title'?


To get the entire table, you have to do something like

 $result = mysqli_query($link,"SELECT * FROM sixty 
   WHERE ((peak='1') AND (year>1959) AND (year<1970))
   ORDER BY year, sid ");

 $total = mysqli_num_rows($result);
 echo $total;

 while ($rows = mysqli_fetch_assoc($result))
 {
   echo "<br/>"
   echo $rows['title'];
 }


-- 
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request

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


#15212

Fromrichard <noreply@example.com>
Date2015-04-05 11:28 -0400
Message-ID<d6kkyq3t756u.cae98b7s6kcm$.dlg@40tude.net>
In reply to#15209
On Sun, 05 Apr 2015 11:18:14 -0400, Lew Pitcher wrote:

> On Sunday April 5 2015 10:56, in comp.lang.php, "richard"
> <noreply@example.com> wrote:
> 
>> On Sun, 5 Apr 2015 01:15:55 +0000 (UTC), Doug Miller wrote:
>> 
>>> richard <noreply@example.com> wrote in
>>> news:1lpvv6118algy.1pzxv594x426f$.dlg@ 40tude.net:
>>> 
>>> [...]
>>>> 
>>>> Done that.
>>>> What I get is 11 duplicates of the first item.
>>>> So why does it stop at 11 when I have 200 records?
> 
> Because you are doing it wrong. See the comments below.
> 
> 
>>> Kind of hard to answer that question when we can't see your code....
>> 
>> $result = mysqli_query($link,"SELECT * from sixty where (
>>   (peak='1')
>> and (year>1959)
>> and (year<1970)
>>   ) ORDER BY year, sid ");
>> $rows = mysqli_fetch_assoc($result);
> 
> mysqli_fetch_assoc() populates an associative array with  *a SINGLE row* of
> the resultset.
> 
>> $total=count($rows);
>> echo $total;  // displays "11"
> 
> You have eleven columns in the fetched row.
> 
>> echo "<br>";
>> echo $rows['title'];  //displays nothing.
> 
> Do you have a table column named 'title'?
> 
> 
> To get the entire table, you have to do something like
> 
>  $result = mysqli_query($link,"SELECT * FROM sixty 
>    WHERE ((peak='1') AND (year>1959) AND (year<1970))
>    ORDER BY year, sid ");
> 
>  $total = mysqli_num_rows($result);
>  echo $total;
> 
>  while ($rows = mysqli_fetch_assoc($result))
>  {
>    echo "<br/>"
>    echo $rows['title'];
>  }

Thank you sir. That worked like a charm.
<snicker> you forgot the ; after the br tag.

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


#15214

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2015-04-05 11:52 -0400
Message-ID<vTcUw.153157$Ek3.39252@fx13.iad>
In reply to#15212
On Sunday April 5 2015 11:28, in comp.lang.php, "richard"
<noreply@example.com> wrote:

[snip]

> Thank you sir. That worked like a charm.

You are welcome.

> <snicker> you forgot the ; after the br tag.

Can you say "bite the hand that feeds you"?
Apparently, you aren't all that gracious when someone helps you.


-- 
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request

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


#15216

FromDoug Miller <doug_at_milmac_dot_com@example.com>
Date2015-04-06 02:01 +0000
Message-ID<XnsA473E028B6572dougmilmaccom@213.239.209.88>
In reply to#15214
Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote in news:vTcUw.153157$Ek3.39252
@fx13.iad:

> On Sunday April 5 2015 11:28, in comp.lang.php, "richard"
> <noreply@example.com> wrote:
> 
> [snip]
> 
>> Thank you sir. That worked like a charm.
> 
> You are welcome.
> 
>> <snicker> you forgot the ; after the br tag.
> 
> Can you say "bite the hand that feeds you"?
> Apparently, you aren't all that gracious when someone helps you.

You're *just now* noticing that, Lew? 

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


#15221

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2015-04-08 20:16 -0400
Message-ID<sxjVw.223005$pp5.78645@fx29.iad>
In reply to#15216
On Sunday April 5 2015 22:01, in comp.lang.php, "Doug Miller"
<doug_at_milmac_dot_com@example.com> wrote:

> Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote in
> news:vTcUw.153157$Ek3.39252 @fx13.iad:
> 
>> On Sunday April 5 2015 11:28, in comp.lang.php, "richard"
>> <noreply@example.com> wrote:
>> 
>> [snip]
>> 
>>> Thank you sir. That worked like a charm.
>> 
>> You are welcome.
>> 
>>> <snicker> you forgot the ; after the br tag.
>> 
>> Can you say "bite the hand that feeds you"?
>> Apparently, you aren't all that gracious when someone helps you.
> 
> You're *just now* noticing that, Lew?

I know that "richard" is a d*ck.
I just didn't know how big a d*ck he was.

-- 
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request

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


#15225

Fromrichard <noreply@example.com>
Date2015-04-09 22:32 -0400
Message-ID<1qry4qqazpwa4$.1r42kff51v2cc.dlg@40tude.net>
In reply to#15221
On Wed, 08 Apr 2015 20:16:23 -0400, Lew Pitcher wrote:

> On Sunday April 5 2015 22:01, in comp.lang.php, "Doug Miller"
> <doug_at_milmac_dot_com@example.com> wrote:
> 
>> Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote in
>> news:vTcUw.153157$Ek3.39252 @fx13.iad:
>> 
>>> On Sunday April 5 2015 11:28, in comp.lang.php, "richard"
>>> <noreply@example.com> wrote:
>>> 
>>> [snip]
>>> 
>>>> Thank you sir. That worked like a charm.
>>> 
>>> You are welcome.
>>> 
>>>> <snicker> you forgot the ; after the br tag.
>>> 
>>> Can you say "bite the hand that feeds you"?
>>> Apparently, you aren't all that gracious when someone helps you.
>> 
>> You're *just now* noticing that, Lew?
> 
> I know that "richard" is a d*ck.
> I just didn't know how big a d*ck he was.

And you apparently have no sense of humer.
When I post code, somebody always jumps on my case for making a minor typo.
When I find they made a mistake, I get bashed for pointing it out.
Look up the definition of the word snicker.

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


#15226

FromRichard Heathfield <rjh@cpax.org.uk>
Date2015-04-10 07:48 +0100
Message-ID<mg7rlm$qv1$1@dont-email.me>
In reply to#15225
On 10/04/15 03:32, richard wrote:

<snip>

> Look up the definition of the word snicker.

Doesn't it mean Marathon? At least, for those of us old enough to 
remember shillings and ounces and the like.

-- 
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

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


#15228

FromDoug Miller <doug_at_milmac_dot_com@example.com>
Date2015-04-11 03:11 +0000
Message-ID<XnsA478EBF539AAFdougmilmaccom@213.239.209.88>
In reply to#15225
richard <noreply@example.com> wrote in news:1qry4qqazpwa4$.1r42kff51v2cc.dlg@
40tude.net:

> On Wed, 08 Apr 2015 20:16:23 -0400, Lew Pitcher wrote:
> 
>> On Sunday April 5 2015 22:01, in comp.lang.php, "Doug Miller"
>> <doug_at_milmac_dot_com@example.com> wrote:
>> 
>>> Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote in
>>> news:vTcUw.153157$Ek3.39252 @fx13.iad:
>>> 
>>>> On Sunday April 5 2015 11:28, in comp.lang.php, "richard"
>>>> <noreply@example.com> wrote:
>>>> 
>>>> [snip]
>>>> 
>>>>> Thank you sir. That worked like a charm.
>>>> 
>>>> You are welcome.
>>>> 
>>>>> <snicker> you forgot the ; after the br tag.
>>>> 
>>>> Can you say "bite the hand that feeds you"?
>>>> Apparently, you aren't all that gracious when someone helps you.
>>> 
>>> You're *just now* noticing that, Lew?
>> 
>> I know that "richard" is a d*ck.
>> I just didn't know how big a d*ck he was.
> 
> And you apparently have no sense of humer.
> When I post code, somebody always jumps on my case for making a minor typo.

No, Richard The Stupid, when you post code somebody always jumps on your case for 
your longstanding, persistent inability to learn the difference between = and ==. That's *not* 
a typo, that's just Stupid.

> When I find they made a mistake, I get bashed for pointing it out.
> Look up the definition of the word snicker.
> 

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


#15220

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2015-04-06 07:58 +0000
Message-ID<mfteb9$t03$4@dont-email.me>
In reply to#15209
On Sun, 05 Apr 2015 11:18:14 -0400, Lew Pitcher wrote:

>  while ($rows = mysqli_fetch_assoc($result))
>  {
>    echo "<br/>"
>    echo $rows['title'];
>  }

See my post of 12:28 AM, I thought I'd given richard a nicely explained 
example of using this loop to generate an HTML table from the results of 
the database query, but he obviously didn't read it.

-- 
Denis McMahon, denismfmcmahon@gmail.com

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


#15219

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2015-04-06 07:48 +0000
Message-ID<mftdpa$t03$3@dont-email.me>
In reply to#15206
On Sun, 05 Apr 2015 10:56:15 -0400, richard wrote:

> On Sun, 5 Apr 2015 01:15:55 +0000 (UTC), Doug Miller wrote:
> 
>> richard <noreply@example.com> wrote in
>> news:1lpvv6118algy.1pzxv594x426f$.dlg@
>> 40tude.net:
>> 
>> [...]
>>> 
>>> Done that.
>>> What I get is 11 duplicates of the first item.
>>> So why does it stop at 11 when I have 200 records?
>>> 
>> Kind of hard to answer that question when we can't see your code....
> 
> $result = mysqli_query($link,"SELECT * from sixty where (
>   (peak='1')
> 	and (year>1959)
> 	and (year<1970)
>   ) ORDER BY year, sid ");

> $rows = mysqli_fetch_assoc($result);

This thing that you're calling $rows is only getting a single record from 
$result.
 
> $total=count($rows);
> echo $total;  // displays "11"

That's the number of fields in the record you just pulled out of $result, 
not the number of records retrieved.

All the other records are still in $result. This is why you loop through 
$result as I posted earlier.

> echo "<br>";
> echo $rows['title'];  //displays nothing.

That means you don't have a field called 'title' in your record.

try replacing:

> $total=count($rows);
> echo $total;  // displays "11"
> echo "<br>";
> echo $rows['title'];  //displays nothing.

with:

echo '<pre>\n';
echo print_r($rows, true);
echo '</pre>\n';

This will print out the array that corresponds to the record you got from 
$result.

p.s. we're still waiting to hear what the data type of the years field is.

-- 
Denis McMahon, denismfmcmahon@gmail.com

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


#15205

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2015-04-05 04:47 +0000
Message-ID<mfqeo9$va3$1@dont-email.me>
In reply to#15203
On Sat, 04 Apr 2015 19:32:29 -0400, richard wrote:

> On Sat, 4 Apr 2015 23:28:57 +0000 (UTC), Denis McMahon wrote:
> 
>> On Fri, 03 Apr 2015 21:54:12 -0400, richard wrote:
>> 
>>> "SELECT * from sixty where (
>>>   (peak='1')
>>>   AND  (year>1959)
>>>   AND  (year<1970)
>>> ) ORDER BY year, sid "
>>> 
>>> Considering this code provided by Erwin Moller, how does one now
>>> display the information?
>>> 
>>> The standard method of using $row=$result() winds up with only the
>>> first item ending up in a displayed table while the other items are
>>> just bunched up together one after the other.
>>> 
>>> If I simply fetch one item at a time, the table is displayed as
>>> wanted.
>>> 
>>> By this usage of the word "table" I am not speaking of the database
>>> table stored on the server. But the html displayed table on the page.
>> 
>> Note that the following is an example that assumes the reader has some
>> competencies and understanding of php, and the use of the ellipsis
>> 
>> <?php
>> 
>> // Start the table:
>> 
>> echo "<table>\n";
>> 
>> // print the table header row
>> 
>> echo "<tr> <th>header</th>... </tr>\n";
>> 
>> // use a loop that fetches every row from the mysqli result // this
>> example assumes the mysqli result is in $result // $data is a local
>> variable in the loop
>> 
>> while ($data = mysqli_fetch_assoc($result)) {
>> 
>> // in here you write out a single table row for each set of // $data
>> from the query result
>> 
>> echo "<tr> <td>{$data['fieldname']}</td>... </tr>\n";
>> 
>> }
>> 
>> // close the table
>> 
>> echo "</table>";
>> 
>> ?>
> 
> Done that.
> What I get is 11 duplicates of the first item.
> So why does it stop at 11 when I have 200 records?

Perhaps your query is not fetching the data you think it is. Without 
running your query against your datatable at the mysql command line, it's 
hard to tell.

I suspect but I can't be sure that the reason you're getting 11 values 
might be linked to the "(year>1959) AND (year<1970)" part of the query.

There might be an issue if you have stored years as strings and are now 
trying to compare those strings with a numeric value. I'm not sure, 
because I don't usually try to compare strings with numbers in mysql.

-- 
Denis McMahon, denismfmcmahon@gmail.com

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


#15207

Fromrichard <noreply@example.com>
Date2015-04-05 10:58 -0400
Message-ID<1xbslhz79f19i.1tpyrouzu9o3f$.dlg@40tude.net>
In reply to#15205
On Sun, 5 Apr 2015 04:47:05 +0000 (UTC), Denis McMahon wrote:

> On Sat, 04 Apr 2015 19:32:29 -0400, richard wrote:
> 
>> On Sat, 4 Apr 2015 23:28:57 +0000 (UTC), Denis McMahon wrote:
>> 
>>> On Fri, 03 Apr 2015 21:54:12 -0400, richard wrote:
>>> 
>>>> "SELECT * from sixty where (
>>>>   (peak='1')
>>>>   AND  (year>1959)
>>>>   AND  (year<1970)
>>>> ) ORDER BY year, sid "
>>>> 
>>>> Considering this code provided by Erwin Moller, how does one now
>>>> display the information?
>>>> 
>>>> The standard method of using $row=$result() winds up with only the
>>>> first item ending up in a displayed table while the other items are
>>>> just bunched up together one after the other.
>>>> 
>>>> If I simply fetch one item at a time, the table is displayed as
>>>> wanted.
>>>> 
>>>> By this usage of the word "table" I am not speaking of the database
>>>> table stored on the server. But the html displayed table on the page.
>>> 
>>> Note that the following is an example that assumes the reader has some
>>> competencies and understanding of php, and the use of the ellipsis
>>> 
>>> <?php
>>> 
>>> // Start the table:
>>> 
>>> echo "<table>\n";
>>> 
>>> // print the table header row
>>> 
>>> echo "<tr> <th>header</th>... </tr>\n";
>>> 
>>> // use a loop that fetches every row from the mysqli result // this
>>> example assumes the mysqli result is in $result // $data is a local
>>> variable in the loop
>>> 
>>> while ($data = mysqli_fetch_assoc($result)) {
>>> 
>>> // in here you write out a single table row for each set of // $data
>>> from the query result
>>> 
>>> echo "<tr> <td>{$data['fieldname']}</td>... </tr>\n";
>>> 
>>> }
>>> 
>>> // close the table
>>> 
>>> echo "</table>";
>>> 
>>> ?>
>> 
>> Done that.
>> What I get is 11 duplicates of the first item.
>> So why does it stop at 11 when I have 200 records?
> 
> Perhaps your query is not fetching the data you think it is. Without 
> running your query against your datatable at the mysql command line, it's 
> hard to tell.
> 
> I suspect but I can't be sure that the reason you're getting 11 values 
> might be linked to the "(year>1959) AND (year<1970)" part of the query.
> 
> There might be an issue if you have stored years as strings and are now 
> trying to compare those strings with a numeric value. I'm not sure, 
> because I don't usually try to compare strings with numbers in mysql.

I tried using the "between" part and that resulted in displaying "0".

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


Page 1 of 2  [1] 2  Next page →

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


csiph-web