Re: Re: echo?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



not the concern in this posting
"Richard Quadling" <rquadling@xxxxxxxxx> wrote in message 
news:AANLkTindQu7BZeaMtcwh6y9f3M9yjXqPt-ime9YshUgk@xxxxxxxxxxxxxxxxx
On 23 March 2011 07:46, Geoff Lane <geoff@xxxxxxxxxxxxx> wrote:
> Hi Jim,
>
> On Wednesday, March 23, 2011, 1:42:18 AM, you wrote:
>
>> ok - here's the code in question.
>> $q = 'select * from director_records ';
>> $qrslt = mysql_query($q);
>> $rows = mysql_num_rows($qrslt);
>> for ($i=0; $i<$rows; $i++)
>> {
>> $j = $i+1;
>> $row = mysql_fetch_array($qrslt);
>> echo $j.'-'.$row['userid'];
>> if ($row['user_priv']<> "")
>> echo ' ('.$row['user_priv'].')&#13&#10';
>> else
>> echo '&#13&#10';
>> }
>
>
>> The output I get is:
>
>
>> 1-smith5
>> f-ginerjm (M)
>> g-smith8
>
>> While the alpha parts are valid, the index is only correct for the first 
>> one
>> (0) obviously.
>
>
> I couldn't understand why you're getting characters, so I thought I'd
> have a go myself. First, some DDL and DML to recreate your data:
>
> create table director_records (userid char(16), user_priv char(8));
> insert into director_records (userid, user_priv) values ('smith5', 
> ''),('ginerjm','M'),('smith8','');
>
> Now when I ran your code I got:
>
> 1-smith5&#13&#102-ginerjm (M)&#13&#103-smith8&#13&#10
>
> That is, all but the first result has &#10x in front of it. These are
> HTML entities that display as characters and it so happens that &#102
> is 'j' and &#103 is 'g'. Strictly, these entities should be terminated
> with a semi-colon (i.e. &#102; and &#103;), but your browser is
> 'obligingly' making sense of the 'bad formatting' and this is why
> you're getting characters.
>
> BTW, an alternative to your for construct would be to use a while loop
> to iterate through a data table. e.g. in your case, I'd have used:
>
> $q = 'select * from director_records ';
> $qrslt = mysql_query($q);
> $i = 1;
> while ($row = mysql_fetch_array($qrslt)){
> echo $i++ . '-' . $row['userid'];
> if ($row['user_priv']<>""){
> echo " (" . $row['user_priv'] . ")";
> }
> echo "<br>\n";
> }
>
> HTH,

I use ...

while(False !== ($row = mysql_fetch_array($qrslt)){
}

just so that if I have a query with 1 cell which is 0, or '', I don't
abort the loop.


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux