Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143
This is the forum to discuss the Wrox book Beginning PHP 6, Apache, MySQL 6 Web Development by Timothy Boronczyk, Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz; ISBN: 9780470391143
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 20th, 2010, 10:09 AM
Authorized User
Points: 152, Level: 3
Points: 152, Level: 3 Points: 152, Level: 3 Points: 152, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2010
Location: Bra - Italy
Posts: 36
Thanks: 1
Thanked 1 Time in 1 Post
Default Chp 10: mysql command question

Hi, i've a question about mysql command in the chp 10 (and not only).

I don't understand the syntax of this:
PHP Code:
if ($character_id != 0) {
    
$query 'SELECT
        c.alias, c.real_name, c.alignment,
        l.address, z.city, z.state, z.zipcode_id
        FROM
            comic_character c, comic_lair l, comic_zipcode z
        WHERE
            z.zipcode_id = l.zipcode_id AND
            c.lair_id = l.lair_id AND
            c.character_id = ' 
$character_id;
    
$result mysql_query($query$db) or die (mysql_error($db)); 
I mean the "c." , "l." , "z." and the "comic_character c, comic_lair l, comic_zipcode z", why i have to insert c, l and z? how it works?

Thanks
Reply With Quote
  #2 (permalink)  
Old July 22nd, 2010, 06:36 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Those are just "aliases". A far *BETTER* way to write that would be:
Code:
   $query = 'SELECT 
       c.alias, c.real_name, c.alignment, 
       l.address, z.city, z.state, z.zipcode_id 
       FROM 
           comic_character AS c, comic_lair AS l, comic_zipcode AS z 
       WHERE 
           z.zipcode_id = l.zipcode_id AND 
           c.lair_id = l.lair_id AND 
           c.character_id = '. $character_id; 
So that the AS clearly says "this is an alias I am using."

That is, those are "shortcut" names given to those tables, for convenience.


That code is 100% equivalent to
Code:
   $query = 'SELECT 
       comic_character.alias, comic_character.real_name, comic_character.alignment, 
       comic_lair.address, comic_zipcode.city, comic_zipcode.state, comic_zipcode.zipcode_id
       FROM comic_character, comic_lair, comic_zipcode 
       WHERE 
           comic_zipcode.zipcode_id = comic_lair.zipcode_id AND 
           comic_character.lair_id = comic_lair.lair_id AND 
           comic_character.character_id = ' . $character_id; 
You see? It makes the code easier to read, but other than that it has *ZERO* impact on the query.
Reply With Quote
The Following User Says Thank You to Old Pedant For This Useful Post:
DMatt (July 26th, 2010)
  #3 (permalink)  
Old July 26th, 2010, 08:39 AM
Authorized User
Points: 152, Level: 3
Points: 152, Level: 3 Points: 152, Level: 3 Points: 152, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2010
Location: Bra - Italy
Posts: 36
Thanks: 1
Thanked 1 Time in 1 Post
Smile

Perfect! Thanks!
Reply With Quote
  #4 (permalink)  
Old October 3rd, 2010, 07:38 PM
Authorized User
 
Join Date: Sep 2010
Posts: 20
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Why the hell would they put that in a beginners book, suddenly, without ANY explanation whatsoever? It really pisses me off!!! The same thing a few pages before, where they casually inject the sprintf() function into the code with literally ZERO explanation.
Reply With Quote
  #5 (permalink)  
Old October 4th, 2010, 05:58 PM
Authorized User
Points: 152, Level: 3
Points: 152, Level: 3 Points: 152, Level: 3 Points: 152, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2010
Location: Bra - Italy
Posts: 36
Thanks: 1
Thanked 1 Time in 1 Post
Default

I asked to me the same things... Now i'm at chp 16 and more and more script are totaly WRONGS. The funny thing is that in the book there are images that show the correct work of the scripts just writings.. the problem is that doesn't works.. so the real working script where are??? In the book sure not! Make fun of us!
Reply With Quote
  #6 (permalink)  
Old October 6th, 2010, 03:52 PM
Authorized User
 
Join Date: Sep 2010
Posts: 20
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Did you ever get this application to work? The only thing that doesn't work for me is if I click on one of the aliases in "list_characters.php" to edit. It goes to the edit page but none of the character's data is entered into the form fields like it is supposed to. I think it has something to do with the MySQL query in your first post.

Were you able to edit characters?
Reply With Quote
  #7 (permalink)  
Old October 6th, 2010, 04:33 PM
Authorized User
Points: 152, Level: 3
Points: 152, Level: 3 Points: 152, Level: 3 Points: 152, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2010
Location: Bra - Italy
Posts: 36
Thanks: 1
Thanked 1 Time in 1 Post
Default

Hi, i don't remind exactly what i done for fix the problem but is fixed, i can add-remove-edit any characters i want.. however, i fixed a lot of problems found in the book... not only this one... so boring..
Reply With Quote
  #8 (permalink)  
Old October 6th, 2010, 04:49 PM
Authorized User
 
Join Date: Sep 2010
Posts: 20
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Did you remember if you used the exact MySQL code in your first post? (this one:)

Code:
 $query = 'SELECT 
       c.alias, c.real_name, c.alignment, 
       l.address, z.city, z.state, z.zipcode_id 
       FROM 
           comic_character AS c, comic_lair AS l, comic_zipcode AS z 
       WHERE 
           z.zipcode_id = l.zipcode_id AND 
           c.lair_id = l.lair_id AND 
           c.character_id = '. $character_id;
Reply With Quote
  #9 (permalink)  
Old October 6th, 2010, 05:02 PM
Authorized User
Points: 152, Level: 3
Points: 152, Level: 3 Points: 152, Level: 3 Points: 152, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2010
Location: Bra - Italy
Posts: 36
Thanks: 1
Thanked 1 Time in 1 Post
Default

Yes, in edit_character.php is the same, i have just checked

Code:
if ($character_id != 0) {
    $query = 'SELECT
        c.alias, c.real_name, c.alignment,
        l.address, z.city, z.state, z.zipcode_id
        FROM
            comic_character c, comic_lair l, comic_zipcode z
        WHERE
            z.zipcode_id = l.zipcode_id AND
            c.lair_id = l.lair_id AND
            c.character_id = ' . $character_id;
    $result = mysql_query($query, $db) or die (mysql_error($db));
the problem is not in these rows... if you describe to me exactly what's the output generated by the script i help you to found it, or if you want i can post the whole script..

-EDIT-

hey take care about the "AS"... don't include that in the rows!!
Reply With Quote
  #10 (permalink)  
Old October 6th, 2010, 05:48 PM
Authorized User
 
Join Date: Sep 2010
Posts: 20
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I isolated just the MySQL query exactly as written (without the AS) and put it in another file with an echo statement to see if it works like this:

Code:
<?php
require 'includes/db.inc.php'; 
$db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or die ('Unable to connect');
mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db));
         $query = 'SELECT 
       c.alias, c.real_name, c.alignment, 
       l.address, z.city, z.state, z.zipcode_id 
       FROM 
           comic_character c, comic_lair l, comic_zipcode AS z 
       WHERE 
           z.zipcode_id = l.zipcode_id AND 
           c.lair_id = l.lair_id AND 
           c.character_id = '. $character_id;

$result = mysql_query($query, $db) or die(mysql_error($db));

if (mysql_num_rows($result) > 0) {
	$action = 'Edit';
	$character = mysql_fetch_assoc($result);
	echo $character['alias'];
}
?>
And I keep getting this error:

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 9"

So there's something weird going on with that MySQL code...

If you have your version of edit_character.php handy I would appreciate it very much if you would post it. Thanks!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
About a SELECT command to execute in my MysQL Database Carcinosi MySQL 1 November 29th, 2009 02:18 AM
Booking System Chp 10, ObjectDataSource, and DataSets dev101 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 March 9th, 2009 12:41 PM
Vusial Basic 6, Mysql and Crystal Report 10 Samuel Banda Access VBA 1 December 20th, 2006 08:31 AM
show just the column names from a MySQL command crmpicco MySQL 5 December 7th, 2006 08:34 AM
TEST THE MYSQL IN THE COMMAND PROMPT jhan316 SQL Server 2005 0 June 25th, 2006 09:16 AM



All times are GMT -4. The time now is 10:16 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.