Wrox Programmer Forums
|
BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5
This is the forum to discuss the Wrox book Beginning PHP4 by Wankyu Choi, Allan Kent, Chris Lea, Ganesh Prasad, Chris Ullman; ISBN: 9780764543647
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 3rd, 2003, 03:21 PM
Authorized User
 
Join Date: Jul 2003
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Nik. That line 247 problem is the original problem that's already been addressed in this thread. No biggie there.

I was wondering about having the url defined after the Javascript 'window.open' was launched, and having the delay fix that, so I just plugged the url into where it would normally go and deleted the *NEW_WIN.location.href = url;* line (with the added delay) and it's working now. I guess I'm just trying to understand the book examples. I'm too new to the stuff still.

Quote:
quote:Finally, there's something else you mentioned that seems strange -- having a function defined within a function. What's that all about?
I was seeing this:
function html_header() {
   global $new_win_width, $new_win_height;
   ?>
   <HTML>
   <HEAD>
   <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
   <!--
   function open_window(url) {
      var NEW_WIN = null;
      NEW_WIN = window.open ("", "RecordViewer",
                             "toolbar=no,width="+
                             <?php echo $new_win_width ?>+
                             ",height="+<?php echo $new_win_height?>+
                             ",directories=no,status=no,
                             scrollbars=yes,resize=no,menubar=no");
      NEW_WIN.location.href = url;
   }
    //-->
   </SCRIPT>
   <TITLE>User Record Viewer</TITLE>
   </HEAD>
   <BODY>
   <?php
}

as a function defined within a function, but you've explained that. I guess Javascript needs it's functions defined somewhere as well (if it's not a library function), and I *guess* you can put the function definitions anywhere as long as they're inside the <SCRIPT></SCRIPT> tags.

I can post the generated code if you like. I ran the wrox scripts, and they bombed on me too. During a workaround, I did find a database error, but after correcting that, I went back and the script still failed. It's got something to do with the system delay. I found the hint at this location:

http://tech.irt.org/articles/js128/index.htm#4

Anyway, I'm a little surprised that no one else has had this particular problem (or haven't discussed it here).

http://web.wrox.com/0764543644/3730-code-win.zip
has all of the (corrected) book examples for beginning PHP4.
 
Old November 3rd, 2003, 07:45 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Oregon
I was seeing this:
function html_header() {
global $new_win_width, $new_win_height;
?>
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
        snip snip snip
</HEAD>
<BODY>
<?php
}

as a function defined within a function, but you've explained that. I guess Javascript needs it's functions defined somewhere as well (if it's not a library function), and I *guess* you can put the function definitions anywhere as long as they're inside the <SCRIPT></SCRIPT> tags.
Right. Keep in mind that HTML and JavaScript are languages in their own right. PHP is a language that facilitates the process of accepting user input via HTTP connections, accessing databases, and generating output. PHP doesn't care what that output is -- it can be text or binary data. Most of the time, you're generating HTML. Some of the time, you're generating JavaScript. You can use PHP to generate other text formats, such as comma- or tab-separated value files, XML files, configuration files, email texts, PDF files, etc. You can generate binary data such as JPG or PNG images, or shockwave flash animations.


Quote:
quote:Originally posted by Oregon
It's got something to do with the system delay. I found the hint at this location:

http://tech.irt.org/articles/js128/index.htm#4

Anyway, I'm a little surprised that no one else has had this particular problem (or haven't discussed it here).
Yeah, that is interesting. I wasn't aware of that problem. I think it's because I've never used window.open() to open a window without telling it what url to render in that window.

Check the difference:

NewWindow = window.open(url, window_title, properties);

     vs.

NewWindow = window.open('', window_title, properties);
NewWindow.location.href = url;


I wonder if the top way would work better for you... I am out of practice with JavaScript and unfortunately don't have the time right now to write a little test page.


Take care,

Nik
http://www.bigaction.org/
 
Old November 4th, 2003, 01:27 PM
Authorized User
 
Join Date: Jul 2003
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Nik. That's what I'd done to fix it. I guess it's one of those reasons that some people see bugs and some don't. It could just be machine dependent (hardware/software configuration)?

So, to continue the flaming folder discussion, the book example:

    <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
   <!--
   function open_window(url) {
      var NEW_WIN = null;
      NEW_WIN = window.open ("", "RecordViewer",
                             "toolbar=no,width="+
                             <?php echo $new_win_width ?>+
                             ",height="+<?php echo $new_win_height?>+
                             ",directories=no,status=no,
                             scrollbars=yes,resize=no,menubar=no");
      NEW_WIN.location.href = url;
   } //-->
   </SCRIPT>

was changed to:

   <script language="JavaScript" type="text/javascript">
   <!--
   function open_window(url) {
      NEW_WIN = window.open (url, "RecordViewer","toolbar=no,width="+<?php echo $new_win_width ?>+",height="+<?php echo $new_win_height?>+",directories=no,status=no,scrol lbars=yes,resize=no,menubar=no");
   }
   // -->
   </script>

Note that the var NEW_WIN = null; was removed, and the url is not in quotes. I guess once you cross over into Javascript land, the rules change? For instance, quotes around $new_win_width or $new_win_height (after the php echo) make no difference, although I'm sure there is a standard to follow to keep from looking too sloppy. Anyway...
 
Old November 4th, 2003, 02:06 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, keep in mind that url is a string variable in Javascript. It's nothing to PHP, since you're not within <?php ?> script delimiters. If you surrounded url in quotes, you'd make it the string "url", not the variable url. In PHP, variables are prefixed with $, so they're easier to spot, and PHP handles variable substitution within double-quoted strings. Not so in JavaScript -- you have to break out of your strings and use concatenation (using the + sign, whereas PHP uses a period).

The quotes around the PHP echo are, again, nothing to PHP, since they're outside of the script delimiters (<?php and ?>). What you're doing is generating javascript code to break out of a string and concatenate a numeric value.

Your generated code looks like this:

    "toolbar=no,width="+
    600+
    ",height="+800+
    ",directories=no,status=no,
    scrollbars=yes,resize=no,menubar=no"


Those plusses are concatenation operators. Since you're not concatenating the values of JavaScript variables, you can omit them entirely:

NEW_WIN = window.open ("", "RecordViewer",
                           "toolbar=no,width=<?php echo $new_win_width ?>,height=<?php echo $new_win_height?>,directories=no,status=no,scrollb ars=yes,resize=no,menubar=no");

The concatenation is merely in place to make both your PHP and generated-JavaScript more readable.


Take care,

Nik
http://www.bigaction.org/
 
Old November 4th, 2003, 02:45 PM
Authorized User
 
Join Date: Jul 2003
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Whew! Thanks again. I was wondering about that. You are a wealth of information (a veritable cornucopia)! More of the real world vs. 'the book' discussion. So far, I've only bought the two PHP4 books (beginning and professional) and HTML 4.01 Programmer's reference from WROX. It looks like I'm going to get a whole lot more real world information online.

P.S., that's a killer resume.
 
Old November 4th, 2003, 05:03 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, that's how it should be, I guess... You don't start learning how to design a house by starting with a book and finishing with a well-thought-out architectural design. It takes years of formal training and practice.

The analogy often breaks because no one is willing to hire an architect who's fairly new and without a formal education in the subject, but a LOT of people are willing to shell out a few hundred bucks to a "programmer" who's only experience in web application design and development is completing the example problems in the Intro to PHP book and throwing up a personal website.

I'm increasingly frustrated with the marketing concept behind learning ANY language FAST FAST FAST, be it Italian, Spanish, C++, PHP, etc... It's just not done.

Still, though, flipping through some decent books and reading online tutorials is a great place to start. If you stick with it, you can learn the fundamentals of the language and, with guidance and support from a community such as this, eventually get to the point where the toy scripts in the intro books look really, really, really shoddy to you.

That's a good place to be.

Most of the higher-level and intellectual software application design books and classes are kept to languages more commonly used in application development, such as C, C++, and Java.



Take care,

Nik
http://www.bigaction.org/
 
Old March 28th, 2004, 07:58 AM
Registered User
 
Join Date: Mar 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I can't get the view record thing to work. When the new window pops up it contains the same page as where I am. I can also have it blank if I wish but I can't put my own stuff in there.

The view_record function doesn't seem to be doing anything as I can have there whatever I like and it doesn't make any differencece.

Could someone please help me with this.

 
Old March 29th, 2004, 02:44 PM
Authorized User
 
Join Date: Jul 2003
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

pernaveikko, this site has code you can download, if you'd like to do a 'stare and compare' against what you have typed.

http://www.wrox.com/dynamic/books/download.aspx#code

Otherwise, maybe if you could post an error message with the associated code

regards,
Oregon
 
Old April 1st, 2004, 09:55 AM
Registered User
 
Join Date: Mar 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, I can't post an error message as there are no errors. The page simply doesn't do anything.

I have found out that the view_record() function can be even left blank and nothing changes.

I have checked my code against the original ones. It does make you wonder how did the authors manage to get their screenshots... They must have had a working version at some point.
 
Old April 1st, 2004, 03:14 PM
Authorized User
 
Join Date: Jul 2003
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Are you getting an error in the bottom left corner of the browser? You'll need to have the status bar turned on to see it.

Just to clarify, are you on page 443 (the beginning of the view_record() function section?

I struggled with this code as you can see from above ;)

It's working, but I did some tweaking. The javascript could be your problem too?

Don't give up.

Oregon

I keep forgetting that my memory is slipping.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 12 Error with binding Calendar? rsearing BOOK: Beginning ASP.NET 2.0 and Databases 2 October 9th, 2006 07:51 AM
Chapter 12 Code Behind Problem locknload7 BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 1 March 30th, 2005 10:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.