SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    Made with a Mac! philm's Avatar
    Join Date
    Sep 2001
    Location
    Portsmouth, UK
    Posts
    735
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool Echo a variable from a Table join?

    Hi all, just going through Kev's famous book. On page 73 there is an example of a TABLE join, which i understand and can get to work in phpMyAdmin np. But being the meddler i am, i wanted to actually see it and work with it to make sure i don't forget it

    The code works to a point but i'm having trouble actually Echo'ing the result onto the page
    PHP Code:
    <?php
      
      $jokelist 
    = @mysql_query"SELECT Email FROM JokeAuthors, JokeEMails WHERE 
                                  Name='Phil' AND AID=JokeAuthors.ID"
    );

      if (!
    $jokelist) {
        echo(
    "<p>Error performing query: " mysql_error() . "</p>");
        exit();
      }

      while (
    $joke mysql_fetch_array($jokelist)) {
        
    $email $joke["EMail"];
      
        
    // Display the 2 email addresses for Author 'Phil'
        
    echo( "$email<br>" );
      }

    ?>
    The 2 email addresses which result from the query don't show up

    Please excuse any obvious noobi mistakes LOL

  2. #2
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    first look at the code it seems this

    $email = $joke["EMail"];


    should be

    $email = $joke["Email"];


    try that.
    http://redgoals.com ... my site ... nuff said

  3. #3
    Made with a Mac! philm's Avatar
    Join Date
    Sep 2001
    Location
    Portsmouth, UK
    Posts
    735
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx redgoals that did the trick ......... but........ why?
    PHP Code:

    #
    # Table structure for table JokeEMails
    #

    CREATE TABLE JokeEMails (
       
    ID int(11) DEFAULT '0' NOT NULL auto_increment,
       
    EMail varchar(100),
       
    AID int(11) DEFAULT '0' NOT NULL,
       
    PRIMARY KEY (ID)
    ); 
    I was putting in the correct Column name. The name 'EMail' is taken straight from the book. I thought I had to use Column Names exactly as per the TABLE schema or PHP would not find em?

    Are there many of these types of 'Variables-That-Break-The-Rules' type thing a noobi should look out for in future?

  4. #4
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you see in your first attempt in the query you had:

    SELECT Email FROM JokeAuthors, JokeEMails

    then when extracting a row you used

    $email = $joke["EMail"];

    obviousely the "email" vars dont match.

    im not sure but correct me if im wrong, mysql doesnt mind which case the query is in.
    http://redgoals.com ... my site ... nuff said

  5. #5
    Made with a Mac! philm's Avatar
    Join Date
    Sep 2001
    Location
    Portsmouth, UK
    Posts
    735
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh yeh, hehehe

    Thanx......... maybe a bit too much PHP/MySQL overload all at once to begin with LOL

  6. #6
    Custom User Title v1.0 FireFly's Avatar
    Join Date
    Aug 2001
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by redgoals
    im not sure but correct me if im wrong, mysql doesnt mind which case the query is in.
    It only matters when it comes to table/database names, and only on *nix systems.

  7. #7
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, yes, firefly....databases and *nix systems, but all of PHP is case sensitive...even on Win32 systems.

    sketch
    Aaron Brazell
    Technosailor



  8. #8
    Custom User Title v1.0 FireFly's Avatar
    Join Date
    Aug 2001
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, but he said "mysql doesnt mind", and I was just backing him up.

  9. #9
    Made with a Mac! philm's Avatar
    Join Date
    Sep 2001
    Location
    Portsmouth, UK
    Posts
    735
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey guys!!!!

    I think your all great!

    Don't fight over me, muwhahaha


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •