473,323 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Truly bizzare 'echo' problem

This was origianlly one line and was acting strange so I divided it
into three lines and it still acts the same strange way:

Code, cut and pasted from script:

....
$rec_count=$_GET['rc'];
$start=$_GET['sp'];
echo 'Records ' . $start+1;
echo ' through ' . $start+$per_page;
echo ' of ' . $rec_count . '<p>';
....

emitted HTML cut and pasted from the browser:

135 of 49<p>

$start is 0, $per_page is 35 and $rec_count is 49.

This is at the outermost leve, not inside any conditionals, and in
desparation I even stripped out nearby comments. What am I missing
here? the word 'of' gets echoes fine but the other words don't get
echoed at all. I'm really stumped.

Finally, I cut and pasted those three lines along with setting the
variables into an completely empty file that looks like this:

<html>
<head>
<title>temp</title>
</head>
<body>
<?
$start=0;
$per_page=35;
$rec_count=49;
echo 'Records ' . $start+1;
echo ' through ' . $start+$per_page;
echo ' of ' . $rec_count . '<p>';
?>
</body>
</html>

and the emitted HTML is still: 135 of 49<p>

instead of: Record 1 through 35 of 40<p>

FWIW: I'm doing this on a Yahoo/Geocities whosted web site.

--gary

Mar 16 '06 #1
3 1249
Never mind. I figured it out. A php newbie brain fart. s/b echo
'Records' . ($start+1); with parens.

--gary

Mar 16 '06 #2
"fiziwig" <fi*****@yahoo.com> wrote:
Never mind. I figured it out. A php newbie brain fart. s/b echo
'Records' . ($start+1); with parens.


That's correct, but do you understand why? The "." and "+" operators have
equal precedence, so the expression gets evaluated left-to-right.

echo 'Records ' . $start+1;

It computes "'Records ' . $start", which it does by converting $start to a
string, producing "Records 0". It then tries to add 1 to it, which it does
by converting the string to an integer. The string becomes 0, so the
result is 1, and that's what gets echoed.

One of the hazards of working with a loosely-typed language.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Mar 17 '06 #3
Thanks for that explanation. It makes perfect sense now, where before
it was just a strange and inexplicable quirk of the language.

--gary

Mar 17 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: lawrence | last post by:
I wanted to test xml_parse_into_struct() so I took the example off of www.php.net and put this code up on a site: <?php $simple = <<<END <item>
1
by: nick | last post by:
In the web site http://greywolfdesign.com , there is a pop-up menu (when mouse over 'Portfolio' menu item), it always works well when using IE (6). However, when using Mozilla 1.6, the popup...
18
by: Richard Gutery | last post by:
I have an ASP page that I need to have a Message Box on. When I try to run the page, I get the following message : Exception Not Handled. Permission Denied. To trouble shoot, I gave everyone...
8
by: BCC | last post by:
I am getting a non-reproduceable release mode only error, that is proving to be really a pain. I can in some cases narrow it down by try/catch blocks but even that behavior is totally f*ed up. ...
1
by: Zri Man | last post by:
I have come across a bizzare behaviour with DB2/UDB 8.2 on SuSE Linux 2.41 When I have a MQT Refresh going on (complete refresh) it appears to lock the underlying base tables used to build the...
7
by: Martin Pritchard | last post by:
Hi, Sorry for my ignorance, but I'm a bit new to C++. I've been handed over a C++ app written in VS2002 which I have to convert to VS2005. Apparently it's been written in a C style, but cannot...
2
by: the.duckman | last post by:
G'Day, I have a simple peice of code behaving in a rather eratic manner. outputStreams = new MemoryStream(); //.... some code to add values to the stream ... bool ready = false; //.... some...
114
by: Andy | last post by:
Dear Python dev community, I'm CTO at a small software company that makes music visualization software (you can check us out at www.soundspectrum.com). About two years ago we went with decision...
32
by: Request-1 | last post by:
hi folks, html coder here, new and terrified * of php!! aaaaaa! i'm trying to bury a JS script to rotate a photo, in a page i converted from html to php. the conversion went well, it was to...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.