[PHP] Re: echo?
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'].') '; > else > echo ' '; > } > 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 f-ginerjm (M) g-smith8 That is, all but the first result has x in front of it. These are HTML entities that display as characters and it so happens that f is 'j' and g is 'g'. Strictly, these entities should be terminated with a semi-colon (i.e. f and g), 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 "\n"; } HTH, -- Geoff Lane Cornwall, UK ge...@gjctech.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: echo?
23 mar 2011 kl. 02.42 skrev Jim Giner: > 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'].') '; >else >echo ' '; >} > > > 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. > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > Why not try some basic debugging strategies and see what you get? Try: for ($i=0; $i<$rows; $i++) { var_dump($i); $j = $i+1; $row = mysql_fetch_array($qrslt); echo $j.'-'.$row['userid']; var_dump($j); if ($row['user_priv']<> "") echo ' ('.$row['user_priv'].') '; else echo ' '; } The output you've posted, that's rendered output, right? What's the raw output? By the way, the code snippet you gave us is not complete. Is there anything else? As Dan noticed earlier, judging from that code snippet only, there must be something else funky going on. /frank -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: echo?
Hi after of the for, u can use it shoulds back the class of variable, by example "its is string" "its is int" etc for ($i=0;$i<$rows;$i++) echo $i.' '.$row['itemname']; echo gettype($i); Can be that you must define before the class of this variable, because, the system is thinking this is a string class data or hexa etc. grettings and sorry for my written english ;) -- Ricardo ___ IT Architect website: http://www.pulsarinara.com
Re: [PHP] Re: echo?
On 23 March 2011 07:46, Geoff Lane 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'].') '; >> else >> echo ' '; >> } > > >> 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 f-ginerjm (M) g-smith8 > > That is, all but the first result has x in front of it. These are > HTML entities that display as characters and it so happens that f > is 'j' and g is 'g'. Strictly, these entities should be terminated > with a semi-colon (i.e. f and g), 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 "\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
Re: [PHP] Re: echo?
I am outputting to a on an html page. A doesn't work, nor does \n, hence the . Of course, if I don't need the & then I've just saved two keystrokes. :) Also - I do believe I tried ($i+1) and that didn't work either. "Paul M Foster" wrote in message news:20110323034621.go1...@quillandmouse.com... > On Tue, Mar 22, 2011 at 10:50:54PM -0400, Jim Giner wrote: > >> Yes - it is J and I. I tried using $i+1 in the echo originally but it >> wouldn't run. That's why I created $j. > > Yes, the substitution creates a syntax error unless surrounded by > parentheses or the like. > >> And just what is wrong with the old cr/lf sequence? How would you have >> done >> it? > > You're using HTML-encoded entities for 0x0d and 0x0a. You can simply > use 0x0d and 0x0a instead. If you're running this in a web context, you > should use "" instead of CRLF. At the command line, I'm not > familiar with running PHP on Windows. In *nix environments, it's enough > to use "\n", just as they do in C. It might even work in Windows; I > don't know. If not, you should be able to use "\r\n". You can also try > the constant PHP_EOL, which is supposed to handle newlines in a > cross-platform way. > > Paul > > -- > Paul M. Foster > http://noferblatz.com > http://quillandmouse.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: echo?
By george - I think you've solved it! As for my coding choice - that's the beauty of programming - everybody has a way of solving a problem/creating a solution. Unless you are concerned with performance(which in this particular case is not a concern), there is no 'wrong way'. "Geoff Lane" wrote in message news:1278073104.20110323074...@gjctech.co.uk... > 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'].') '; >> else >> echo ' '; >> } > > >> 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 f-ginerjm (M) g-smith8 > > That is, all but the first result has x in front of it. These are > HTML entities that display as characters and it so happens that f > is 'j' and g is 'g'. Strictly, these entities should be terminated > with a semi-colon (i.e. f and g), 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 "\n"; > } > > HTH, > > -- > Geoff Lane > Cornwall, UK > ge...@gjctech.co.uk > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: echo?
On Wed, 2011-03-23 at 08:28 -0400, Jim Giner wrote: > I am outputting to a on an html page. A doesn't work, nor > does \n, hence the . Of course, if I don't need the & then I've > just saved two keystrokes. :) Also - I do believe I tried ($i+1) and that > didn't work either. > > "Paul M Foster" wrote in message > news:20110323034621.go1...@quillandmouse.com... > > On Tue, Mar 22, 2011 at 10:50:54PM -0400, Jim Giner wrote: > > > >> Yes - it is J and I. I tried using $i+1 in the echo originally but it > >> wouldn't run. That's why I created $j. > > > > Yes, the substitution creates a syntax error unless surrounded by > > parentheses or the like. > > > >> And just what is wrong with the old cr/lf sequence? How would you have > >> done > >> it? > > > > You're using HTML-encoded entities for 0x0d and 0x0a. You can simply > > use 0x0d and 0x0a instead. If you're running this in a web context, you > > should use "" instead of CRLF. At the command line, I'm not > > familiar with running PHP on Windows. In *nix environments, it's enough > > to use "\n", just as they do in C. It might even work in Windows; I > > don't know. If not, you should be able to use "\r\n". You can also try > > the constant PHP_EOL, which is supposed to handle newlines in a > > cross-platform way. > > > > Paul > > > > -- > > Paul M. Foster > > http://noferblatz.com > > http://quillandmouse.com > > > Jim with the \n, it does work in a textarea. you must put the \n inside the "", so: $q = 'select * from director_records '; $qrslt = mysql_query($q); $rows = mysql_num_rows($qrslt); for ($i = 0; $i < $rows; $i++) { $row = mysql_fetch_array($qrslt); echo ($i + 1) .'-'. $row['userid']; if ($row['user_priv'] != "") echo ' ('. $row['user_priv'] .')'; echo "\n"; } give that a try -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: echo?
not the concern in this posting "Richard Quadling" wrote in message news:aanlktindqu7bzeamtcwh6y9f3m9yjxqpt-ime9ysh...@mail.gmail.com... On 23 March 2011 07:46, Geoff Lane 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'].') '; >> else >> echo ' '; >> } > > >> 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 f-ginerjm (M) g-smith8 > > That is, all but the first result has x in front of it. These are > HTML entities that display as characters and it so happens that f > is 'j' and g is 'g'. Strictly, these entities should be terminated > with a semi-colon (i.e. f and g), 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 "\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
Re: [PHP] Re: echo?
it was as complete as need be to demonstrate my dilemma, as Richard has discovered above "Frank Arensmeier" wrote in message news:7cfb015a-c530-4712-9ebc-fbdf5b0ed...@gmail.com... 23 mar 2011 kl. 02.42 skrev Jim Giner: > 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'].') '; >else >echo ' '; >} > > > 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. > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > Why not try some basic debugging strategies and see what you get? Try: for ($i=0; $i<$rows; $i++) { var_dump($i); $j = $i+1; $row = mysql_fetch_array($qrslt); echo $j.'-'.$row['userid']; var_dump($j); if ($row['user_priv']<> "") echo ' ('.$row['user_priv'].') '; else echo ' '; } The output you've posted, that's rendered output, right? What's the raw output? By the way, the code snippet you gave us is not complete. Is there anything else? As Dan noticed earlier, judging from that code snippet only, there must be something else funky going on. /frank -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: echo?
Very Interesting - '\n' doesn't work, but "\n" does work. "Steve Staples" wrote in message news:1300883645.5100.973.camel@webdev01... > On Wed, 2011-03-23 at 08:28 -0400, Jim Giner wrote: >> I am outputting to a on an html page. A doesn't work, >> nor >> does \n, hence the . Of course, if I don't need the & then I've >> just saved two keystrokes. :) Also - I do believe I tried ($i+1) and >> that >> didn't work either. >> >> "Paul M Foster" wrote in message >> news:20110323034621.go1...@quillandmouse.com... >> > On Tue, Mar 22, 2011 at 10:50:54PM -0400, Jim Giner wrote: >> > >> >> Yes - it is J and I. I tried using $i+1 in the echo originally but it >> >> wouldn't run. That's why I created $j. >> > >> > Yes, the substitution creates a syntax error unless surrounded by >> > parentheses or the like. >> > >> >> And just what is wrong with the old cr/lf sequence? How would you >> >> have >> >> done >> >> it? >> > >> > You're using HTML-encoded entities for 0x0d and 0x0a. You can simply >> > use 0x0d and 0x0a instead. If you're running this in a web context, you >> > should use "" instead of CRLF. At the command line, I'm not >> > familiar with running PHP on Windows. In *nix environments, it's enough >> > to use "\n", just as they do in C. It might even work in Windows; I >> > don't know. If not, you should be able to use "\r\n". You can also try >> > the constant PHP_EOL, which is supposed to handle newlines in a >> > cross-platform way. >> > >> > Paul >> > >> > -- >> > Paul M. Foster >> > http://noferblatz.com >> > http://quillandmouse.com >> >> >> > > Jim > > with the \n, it does work in a textarea. you must put the \n inside > the "", so: > > $q = 'select * from director_records '; > $qrslt = mysql_query($q); > $rows = mysql_num_rows($qrslt); > for ($i = 0; $i < $rows; $i++) > { >$row = mysql_fetch_array($qrslt); >echo ($i + 1) .'-'. $row['userid']; >if ($row['user_priv'] != "") >echo ' ('. $row['user_priv'] .')'; >echo "\n"; > } > > > give that a try > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: echo?
http://php.net/manual/en/language.types.string.php -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ On Wednesday, 23 March 2011 at 12:39, Jim Giner wrote: > Very Interesting - '\n' doesn't work, but "\n" does work. > "Steve Staples" wrote in message > news:1300883645.5100.973.camel@webdev01... > > On Wed, 2011-03-23 at 08:28 -0400, Jim Giner wrote: > > > I am outputting to a on an html page. A doesn't work, > > > nor > > > does \n, hence the . Of course, if I don't need the & then I've > > > just saved two keystrokes. :) Also - I do believe I tried ($i+1) and > > > that > > > didn't work either. > > > > > > "Paul M Foster" wrote in message > > > news:20110323034621.go1...@quillandmouse.com... > > > > On Tue, Mar 22, 2011 at 10:50:54PM -0400, Jim Giner wrote: > > > > > > > > > Yes - it is J and I. I tried using $i+1 in the echo originally but it > > > > > wouldn't run. That's why I created $j. > > > > > > > > Yes, the substitution creates a syntax error unless surrounded by > > > > parentheses or the like. > > > > > > > > > And just what is wrong with the old cr/lf sequence? How would you > > > > > have > > > > > done > > > > > it? > > > > > > > > You're using HTML-encoded entities for 0x0d and 0x0a. You can simply > > > > use 0x0d and 0x0a instead. If you're running this in a web context, you > > > > should use "" instead of CRLF. At the command line, I'm not > > > > familiar with running PHP on Windows. In *nix environments, it's enough > > > > to use "\n", just as they do in C. It might even work in Windows; I > > > > don't know. If not, you should be able to use "\r\n". You can also try > > > > the constant PHP_EOL, which is supposed to handle newlines in a > > > > cross-platform way. > > > > > > > > Paul > > > > > > > > -- > > > > Paul M. Foster > > > > http://noferblatz.com > > > > http://quillandmouse.com > > > > Jim > > > > with the \n, it does work in a textarea. you must put the \n inside > > the "", so: > > > > $q = 'select * from director_records '; > > $qrslt = mysql_query($q); > > $rows = mysql_num_rows($qrslt); > > for ($i = 0; $i < $rows; $i++) > > { > > $row = mysql_fetch_array($qrslt); > > echo ($i + 1) .'-'. $row['userid']; > > if ($row['user_priv'] != "") > > echo ' ('. $row['user_priv'] .')'; > > echo "\n"; > > } > > > > > > give that a try > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: echo?
As Richard proved my problem was caused by my use of the archaic cr/lf character pair. Once I found the correct syntax for using \n my output of the loop counter worked. thanks for all the suggestions. My first experience on a PHP newsgroup and it was a postiive one. I've spent the last 12+ years using newsgroups for Paradox development and this group is *just* as supportive and knowledgeable. (no jokes about using paradox for so long. If your users can manage on a desktop solution, pdox can't be beaten for what it could/can do.) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: echo?
Thanks for the pointer. Had not run across that tidbit before. "Stuart Dallas" wrote in message news:b43dfd4fa2ac4489aaf538d1bf7a8...@3ft9.com... > http://php.net/manual/en/language.types.string.php > > -Stuart > > -- > Stuart Dallas > 3ft9 Ltd > http://3ft9.com/ > > On Wednesday, 23 March 2011 at 12:39, Jim Giner wrote: >> Very Interesting - '\n' doesn't work, but "\n" does work. >> "Steve Staples" wrote in message >> news:1300883645.5100.973.camel@webdev01... >> > On Wed, 2011-03-23 at 08:28 -0400, Jim Giner wrote: >> > > I am outputting to a on an html page. A doesn't work, >> > > nor >> > > does \n, hence the . Of course, if I don't need the & then >> > > I've >> > > just saved two keystrokes. :) Also - I do believe I tried ($i+1) and >> > > that >> > > didn't work either. >> > > >> > > "Paul M Foster" wrote in message >> > > news:20110323034621.go1...@quillandmouse.com... >> > > > On Tue, Mar 22, 2011 at 10:50:54PM -0400, Jim Giner wrote: >> > > > >> > > > > Yes - it is J and I. I tried using $i+1 in the echo originally >> > > > > but it >> > > > > wouldn't run. That's why I created $j. >> > > > >> > > > Yes, the substitution creates a syntax error unless surrounded by >> > > > parentheses or the like. >> > > > >> > > > > And just what is wrong with the old cr/lf sequence? How would you >> > > > > have >> > > > > done >> > > > > it? >> > > > >> > > > You're using HTML-encoded entities for 0x0d and 0x0a. You can >> > > > simply >> > > > use 0x0d and 0x0a instead. If you're running this in a web context, >> > > > you >> > > > should use "" instead of CRLF. At the command line, I'm not >> > > > familiar with running PHP on Windows. In *nix environments, it's >> > > > enough >> > > > to use "\n", just as they do in C. It might even work in Windows; I >> > > > don't know. If not, you should be able to use "\r\n". You can also >> > > > try >> > > > the constant PHP_EOL, which is supposed to handle newlines in a >> > > > cross-platform way. >> > > > >> > > > Paul >> > > > >> > > > -- >> > > > Paul M. Foster >> > > > http://noferblatz.com >> > > > http://quillandmouse.com >> > >> > Jim >> > >> > with the \n, it does work in a textarea. you must put the \n inside >> > the "", so: >> > >> > $q = 'select * from director_records '; >> > $qrslt = mysql_query($q); >> > $rows = mysql_num_rows($qrslt); >> > for ($i = 0; $i < $rows; $i++) >> > { >> > $row = mysql_fetch_array($qrslt); >> > echo ($i + 1) .'-'. $row['userid']; >> > if ($row['user_priv'] != "") >> > echo ' ('. $row['user_priv'] .')'; >> > echo "\n"; >> > } >> > >> > >> > give that a try >> >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: echo?
On Wed, Mar 23, 2011 at 07:46:03AM +, Geoff Lane 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'].') '; > > else > > echo ' '; > > } > > > > 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 f-ginerjm (M) g-smith8 > > That is, all but the first result has x in front of it. These are > HTML entities that display as characters and it so happens that f > is 'j' and g is 'g'. Strictly, these entities should be terminated > with a semi-colon (i.e. f and g), 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 "\n"; > } > > HTH, *Brilliant* catch. Well done. Paul -- Paul M. Foster http://noferblatz.com http://quillandmouse.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Protecting against session hijacking.
I am not sure I am doing this right, I have login.php which does: $ua = $_SERVER['HTTP_USER_AGENT']; $ua .= rand(0,4200); $ua = md5($ua); and upon successful auth, I push them to the main program: header ("Location: squert.php?id=$ua"); at the beginning of squert.php I have: if(!isset($_SESSION['sUser'])) { sKill(); } else { $sUser = $_SESSION['sUser'];} if(!isset($_SESSION['sEmail'])) { sKill(); } else { $sEmail = $_SESSION['sEmail'];} if(!isset($_SESSION['sType'])) { sKill(); } else { $sType = $_SESSION['sType'];} if(!isset($_SESSION['sTime'])) { sKill(); } else { $sTime = $_SESSION['sTime'];} if(!isset($_REQUEST['id'])) { sKill(); } else { $id = $_REQUEST['id'];} sKill just does session unset|destroy and redirects to login.php. Is this right? I am not sure that the id part is. Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Upload Progress Meter
I am in need of an upload progress meter. I've seen plenty of tutorials = on-line requiring installing modules, hooks, patches, etc. However, my = Wordpress install accomplished this without me having to make any = modifications to my PHP install. So, how is it done? Thanks! Floyd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Upload Progress Meter
On Wed, 2011-03-23 at 09:59 -0400, Floyd Resler wrote: > I am in need of an upload progress meter. I've seen plenty of tutorials = > on-line requiring installing modules, hooks, patches, etc. However, my = > Wordpress install accomplished this without me having to make any = > modifications to my PHP install. So, how is it done? > > Thanks! > Floyd > you can google this... "jquery upload progress meter" or: http://www.nixboxdesigns.com/demos/jquery-uploadprogress.php http://www.bitrepository.com/uploading-files-with-progress-bar.html Steve -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Upload Progress Meter
On Mar 23, 2011, at 10:10 AM, Steve Staples wrote: > On Wed, 2011-03-23 at 09:59 -0400, Floyd Resler wrote: >> I am in need of an upload progress meter. I've seen plenty of tutorials = >> on-line requiring installing modules, hooks, patches, etc. However, my = >> Wordpress install accomplished this without me having to make any = >> modifications to my PHP install. So, how is it done? >> >> Thanks! >> Floyd >> > > you can google this... > > "jquery upload progress meter" > > or: > http://www.nixboxdesigns.com/demos/jquery-uploadprogress.php > > http://www.bitrepository.com/uploading-files-with-progress-bar.html > > > > Steve > I'll check it out! Thanks! Floyd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] adding objects to $SESSION with serialize()
Hi, I'm developing a web application using moodle, and I'm trying to create a PHP object tree to be used in $SESSION. Objects are defined as class foo { private $module_name; private $sub_modules = array(); } I have a main module (object) and I use the following function to add serialized sub modules to such object: public function add_sub_module(&$mod) { $name = $mod->get_mod_name(); $this->sub_modules[$name] = serialize(&$mod); } where the get_mod_name() function simply returns the $module_name private field. After adding a sub module to the main module, I always update the main module in $SESSION using serialize($main_module). Once returned to the page, i restore the main module with unserialize($SESSION->$main_module_name), and then I call the following function to retrieve a sub module: public function &search_sub_module($name='') {; foreach($this->sub_modules as $mod_name => $mod) { if ($name == $mod_name) { return unserialize($mod); } $obj_mod_file = $mod_name.".php"; require_once($obj_mod_file); $obj_mod = unserialize($mod); $modr =& $obj_mod->search_sub_module($name); if ($modr != NULL) { return $modr; } } return NULL; } I found that sub_modules added to the main_module->sub_modules list are correctly retrieved, but if I add a sub module to a main_module's sub module, it cannot be get after the main module has been serialized. What do I mistake? Please help. Thanks Daniele
[PHP] help with _get error
Hello All, I'm having a problem with this line of code which worked fine for years: $l_url2 = ".".$_GET[SERVER_NAME]; Here is the error: [Wed Mar 23 13:33:49 2011] [error] [client 16.139.201.61] PHP Notice: Use of undefined constant SERVER_NAME - assumed 'SERVER_NAME' in /home//modules/jack.php on line 322 Thanks! J
Re: [PHP] help with _get error
On Wed, Mar 23, 2011 at 10:46 AM, Jack wrote: > I'm having a problem with this line of code which worked fine for years: > > $l_url2 = ".".$_GET[SERVER_NAME]; > Place quotes around the key. $l_url2 = ".".$_GET['SERVER_NAME']; Normally PHP treats SERVER_NAME as the name of a constant. There's a setting that allows PHP to treat it as a string if there is no constant with that name, but using that feature has drawbacks and is not good practice. It's possible that your PHP was upgraded or the setting was disabled. Either way, there is no downside to using quotes short of two keystrokes (one if you use a good editor), and you should get used to quoting your strings. Peace, David
[PHP] Re: help with _get error
On 23/03/2011 17:46, Jack wrote: Hello All, I'm having a problem with this line of code which worked fine for years: $l_url2 = ".".$_GET[SERVER_NAME]; Here is the error: [Wed Mar 23 13:33:49 2011] [error] [client 16.139.201.61] PHP Notice: Use of undefined constant SERVER_NAME - assumed 'SERVER_NAME' in /home//modules/jack.php on line 322 Thanks! J You need to put the name of the GET data you want to read in brackets. Like so. $_GET['SERVER_NAME']; or $l_url2 = ".".$_GET['SERVER_NAME']; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP hangs with empty result set
I've been having a problem when querying a database with php and the mysql library the offending code follows. If the result is an empty set, PHP hangs. I've had to add code to the script to set up a max execution time to kill the script after 30 seconds if it doesn't complete. This is happening on a very busy site and in the past, it has brought the server to its knees. The code that follows is actual code copied and pasted from the script. I've trie wrapping an "if ($result_2) {...}: and "if (mysql_num_rows($result_2) > 0) { ..}" around the while loop and it's made no difference. thanks in advance, Curtis $dbhandle2 = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); //echo "Connected to MySQL"; //select a database to work with $selected = mysql_select_db("database",$dbhandle2) or die("Could not select examples"); while ($_parent !="0") { $result_2 = mysql_query("SELECT catagory_parent FROM t_catagories where catagory_ID=" .$_parent); $num_rows_2 = mysql_num_rows($result_2); if($num_rows_2 > "0") { while ($row = mysql_fetch_array($result_2)) { $_parent= $row{'catagory_parent'}; $_parents[$counter] = $row{'catagory_parent'}; $counter++; } } } mysql_close($dbhandle2);
Re: [PHP] PHP hangs with empty result set
On Wed, 2011-03-23 at 15:34 -0400, Curtis Maurand wrote: > > I've been having a problem when querying a database with php and the mysql > library the offending code follows. If the result is an empty > set, PHP hangs. I've had to add code to the script to set up a max > execution time to kill the script after 30 seconds if it doesn't > complete. This is happening on a very busy site and in the past, it > has brought the server to its knees. The code that follows is actual > code copied and pasted from the script. I've trie wrapping an > "if ($result_2) {...}: and "if (mysql_num_rows($result_2) > > 0) { ..}" around the while loop and it's made no difference. > > thanks in advance, > Curtis > > > $dbhandle2 = mysql_connect($hostname, $username, $password) > or > die("Unable to connect to MySQL"); > //echo "Connected > to MySQL"; > > //select a database to work with > $selected = mysql_select_db("database",$dbhandle2) > or > die("Could not select examples"); > > while > ($_parent !="0") { > $result_2 = > mysql_query("SELECT catagory_parent FROM t_catagories where > catagory_ID=" .$_parent); > $num_rows_2 = > mysql_num_rows($result_2); > if($num_rows_2 > > "0") > { > while > ($row = mysql_fetch_array($result_2)) { > > $_parent= $row{'catagory_parent'}; > > $_parents[$counter] = $row{'catagory_parent'}; > > $counter++; > } > > } > } > mysql_close($dbhandle2); > The only obvious thing that I can see is that you're checking if the number of results is greater than a string, not a number. I believe PHP automagically converts it into an integer for the comparison, but try changing it to an actual integer and seeing if that resolves it. There is one other time you use a zero in quotes like that, but without seeing the rest of the code it's impossible to tell whether this would be causing an issue. Check to see if you really do want to compare the string value. Again, this should be automatically converted by PHP, but there are cases where the conversion isn't what you might expect. Lastly, I noticed you're using curly braces instead of square brackets to reference the $row array values. Was this just a typo or your actual code? Array elements really should be referenced by square brackets. -- Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP hangs with empty result set
> The only obvious thing that I can see is that you're checking if the > number of results is greater than a string, not a number. I believe PHP > automagically converts it into an integer for the comparison, but try > changing it to an actual integer and seeing if that resolves it. > > There is one other time you use a zero in quotes like that, but without > seeing the rest of the code it's impossible to tell whether this would > be causing an issue. Check to see if you really do want to compare the > string value. Again, this should be automatically converted by PHP, but > there are cases where the conversion isn't what you might expect. > the dropped quote was a typo. I'm good at that. > Lastly, I noticed you're using curly braces instead of square brackets > to reference the $row array values. Was this just a typo or your actual > code? Array elements really should be referenced by square brackets. > I made the change from the curly braces. I didn't actually write the code. I'm thinking of re-writing this code using the PEAR MDB2 libraries and mysqli. Would that help? --Curtis
[PHP] looking for a newsgroup for JS
Anyone know of a working Javascript newsgroup? I googled and tried adding several to my OE newsgroups but couldn't find the servers. comp.lang.javascript pl.lang. mozilla.. All of these (can't remember their names now) came up with the same error message. As part of learning php, I suddenly have a need to learn some js as well. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] looking for a newsgroup for JS
[snip] Anyone know of a working Javascript newsgroup? I googled and tried adding several to my OE newsgroups but couldn't find the servers. [/snip] He jQuery forum also answers JavaScript questions; forum.jquery.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] adding objects to $SESSION with serialize()
Daniele Capuano wrote: Hi, I'm developing a web application using moodle, and I'm trying to create a PHP object tree to be used in $SESSION. Objects are defined as class foo { private $module_name; private $sub_modules = array(); } I have a main module (object) and I use the following function to add serialized sub modules to such object: public function add_sub_module(&$mod) { $name = $mod->get_mod_name(); $this->sub_modules[$name] = serialize(&$mod); } where the get_mod_name() function simply returns the $module_name private field. After adding a sub module to the main module, I always update the main module in $SESSION using serialize($main_module). Once returned to the page, i restore the main module with unserialize($SESSION->$main_module_name), and then I call the following function to retrieve a sub module: public function&search_sub_module($name='') {; foreach($this->sub_modules as $mod_name => $mod) { if ($name == $mod_name) { return unserialize($mod); } $obj_mod_file = $mod_name.".php"; require_once($obj_mod_file); $obj_mod = unserialize($mod); $modr =& $obj_mod->search_sub_module($name); if ($modr != NULL) { return $modr; } } return NULL; } I found that sub_modules added to the main_module->sub_modules list are correctly retrieved, but if I add a sub module to a main_module's sub module, it cannot be get after the main module has been serialized. What do I mistake? Please help. Thanks Daniele Is '$SESSION' just a typo?.. s/b '$_SESSION'. Donovan -- D Brooke -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] looking for a newsgroup for JS
At 04:20 PM 3/23/2011, Jim Giner wrote: Anyone know of a working Javascript newsgroup? I googled and tried adding several to my OE newsgroups but couldn't find the servers. I frequent an on-line PHP forum at phpfreaks.com. There is a Javascript section there that seems to be quite active: http://www.phpfreaks.com/forums/index.php?board=6.0 Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] help with _get error
Jack wrote: Hello All, I'm having a problem with this line of code which worked fine for years: $l_url2 = ".".$_GET[SERVER_NAME]; Here is the error: [Wed Mar 23 13:33:49 2011] [error] [client 16.139.201.61] PHP Notice: Use of undefined constant SERVER_NAME - assumed 'SERVER_NAME' in /home//modules/jack.php on line 322 Thanks! J You need to learn the differences in error reporting levels. My guess is you changed hosts recently. ;-) Donovan -- D Brooke -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Can I modify a MySQL object?
Let's say I do a query: $result = mysql_query("select * from tablename"); Is there some way I can manually update the contents of certain columns/records in $result? I don't want to actually update MySQL, just the results that I'm holding in memory for this script. Can I do it without converting it to a regular array? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Can I modify a MySQL object?
I should have said "modify the contents of a MySQL resource". On Mar 23, 2011, at 5:06 PM, Brian Dunning wrote: > Let's say I do a query: > > $result = mysql_query("select * from tablename"); > > Is there some way I can manually update the contents of certain > columns/records in $result? I don't want to actually update MySQL, just the > results that I'm holding in memory for this script. Can I do it without > converting it to a regular array? > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: echo?
Jim Giner wrote: > I am outputting to a on an html page. A doesn't work, nor > does \n, hence the . Of course, if I don't need the & then I've > just saved two keystrokes. :) Also - I do believe I tried ($i+1) and > that didn't work either. > > "Paul M Foster" wrote in message > news:20110323034621.go1...@quillandmouse.com... >> On Tue, Mar 22, 2011 at 10:50:54PM -0400, Jim Giner wrote: >> >>> Yes - it is J and I. I tried using $i+1 in the echo originally but it >>> wouldn't run. That's why I created $j. >> >> Yes, the substitution creates a syntax error unless surrounded by >> parentheses or the like. >> >>> And just what is wrong with the old cr/lf sequence? How would you have >>> done >>> it? >> >> You're using HTML-encoded entities for 0x0d and 0x0a. You can simply >> use 0x0d and 0x0a instead. If you're running this in a web context, you >> should use "" instead of CRLF. At the command line, I'm not >> familiar with running PHP on Windows. In *nix environments, it's enough >> to use "\n", just as they do in C. It might even work in Windows; I >> don't know. If not, you should be able to use "\r\n". You can also try >> the constant PHP_EOL, which is supposed to handle newlines in a >> cross-platform way. >> >> Paul >> >> -- >> Paul M. Foster >> http://noferblatz.com >> http://quillandmouse.com It's possibly worth reinforcing at this stage of the game that and are incorrectly formed strings to represent CR and LF, in that they should have a closing semicolon to delimit the end of the entity. I think this was pointed out elsewhere but I believe it deserves repeating. Cheers -- David Robley Sumo Wrestling: survival of the fattest. Today is Pungenday, the 10th day of Discord in the YOLD 3177. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Can I modify a MySQL object?
On Wed, Mar 23, 2011 at 05:12:00PM -0700, Brian Dunning wrote: > I should have said "modify the contents of a MySQL resource". > > On Mar 23, 2011, at 5:06 PM, Brian Dunning wrote: > > > Let's say I do a query: > > > > $result = mysql_query("select * from tablename"); > > > > Is there some way I can manually update the contents of certain > > columns/records in $result? I don't want to actually update MySQL, just the > > results that I'm holding in memory for this script. Can I do it without > > converting it to a regular array? Resources are, I believe, opaque, thus not directly modifiable (safely). Paul -- Paul M. Foster http://noferblatz.com http://quillandmouse.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Can I modify a MySQL object?
Depends on where you want to manipulate. In mysql you can $query = 'select first_name as FNAME from tablename'; In this result you changed the column name from first_name to FNAME for the result only. In this example we can change the data returned in a particular field by using an if statement. $query = 'select IF(first_name='John','Big Bad John',first_name) FROM tablename; If the first_name field contains john we convert the name else just return the name in the row. Is that what you wanted? Richard L. Buskirk Senior Software Engineer/Systems Administrator You can't grow your business with systems that are on life support... -Original Message- From: Brian Dunning [mailto:br...@briandunning.com] Sent: Wednesday, March 23, 2011 8:07 PM To: PHP-General List Subject: [PHP] Can I modify a MySQL object? Let's say I do a query: $result = mysql_query("select * from tablename"); Is there some way I can manually update the contents of certain columns/records in $result? I don't want to actually update MySQL, just the results that I'm holding in memory for this script. Can I do it without converting it to a regular array? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php