SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Can I link values in tables?

    Let me explain the situation...

    I have a nice little script that will display the "ID" values associated with a user inputed date.

    PHP Code:
    $query mysql_query("SELECT Day, SoupID FROM DailySoups WHERE Day='$calendar'" );
    if (!
    $query) {
      echo(
    '</table>');
      die(
    '<p>Error retrieving calendar from database!<br />'.
          
    'Error: ' mysql_error() . '</p>');
    }
    while (
    $today mysql_fetch_array($query)) {
      
    $day $today["Day"];
      
    $sid $today["SoupID"];
      echo(
    "$sid<br>");

    BUT... I would rather the user does not see the "SoupID", I would rather they see the SoupName (which is found in a different table). Each SoupName has the same numerical value as the SoupID that is currently displayed.

    So my question to all the brillant programers out there (there's lots), is how to subsitute the SoupID that is showing up for the SoupName that I would like to show up in it's place.

    I can't subsitute the names in the query I already have. I need to build a *new* portion of code that will link these two together.

    You can view the small working portion I have here: http://soupladle.com/admin/calendar.php

    If this makes sense... I beg of your assistance.
    TAKE A WALK OUTSIDE YOUR MIND.

  2. #2
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this query. Echo the soup name using $today["SoupName"]:
    PHP Code:
    "SELECT D.Day, D.SoupID, S.SoupName FROM DailySoups as D, SoupNames as S
      WHERE
        D.Day = '
    $calendar' AND
        D.SoupId = S.SoupId" 
    John

  3. #3
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    I am receiving a Parse Error on Line 30

    PHP Code:
      echo("'$sname'<br>"); 
    I have tried echoing other values such as $today["SoupName"] and $today["S.SoupName"]. Nothing changed the result.

    What am I doing wrong? I have tweaked little things here and there, but no change. It still doesn't work. I understand what you're doing, and I appreciate your help. I am documenting all these tasks so I won't have to bug you in the future.

    Here is the code:

    PHP Code:
    $soups mysql_query("SELECT DISTINCT Day FROM DailySoups");
    $query mysql_query("SELECT D.Day, D.SoupID, S.SoupName FROM DailySoups as D, Soups as S
      WHERE
        D.Day = '
    $calendar' AND
        D.SoupID = S.ID" 
    );
    if (!
    $query) {
      echo(
    '</table>');
      die(
    '<p>Error retrieving calendar from database!<br />'.
          
    'Error: ' mysql_error() . '</p>');
    }
    while (
    $today mysql_fetch_array($query)) {
      
    $day $today["D.Day"];
      
    $sid $today["D.SoupID"];
      
    $sname $today["S.SoupName"]
      echo(
    "'$sname'<br>");

    TAKE A WALK OUTSIDE YOUR MIND.

  4. #4
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hyperbolik
    I am receiving a Parse Error on Line 30
    PHP Code:
    echo("'$sname'<br>" ); 
    I have tried echoing other values such as $today["SoupName"] and $today["S.SoupName"]. Nothing changed the result.

    What am I doing wrong? I have tweaked little things here and there, but no change. It still doesn't work. I understand what you're doing, and I appreciate your help. I am documenting all these tasks so I won't have to bug you in the future. images/smilies/wink.gif

    Here is the code:
    PHP Code:
    $soups mysql_query("SELECT DISTINCT Day FROM DailySoups" );
    $query mysql_query("SELECT D.Day, D.SoupID, S.SoupName FROM DailySoups as D, Soups as S
    WHERE
    D.Day = '
    $calendar' AND
    D.SoupID = S.ID" 
    );
    if (!
    $query) {
    echo(
    '</table>');
    die(
    '<p>Error retrieving calendar from database!<br />'.
    'Error: ' mysql_error() . '</p>');
    }
    while (
    $today mysql_fetch_array($query)) {
    $day $today["D.Day"];
    $sid $today["D.SoupID"];
    $sname $today["S.SoupName"]
    echo(
    "'$sname'<br>" );

    You are missing a semi-colon. I'm not going to tell you where!
    Last edited by PHP John; Apr 28, 2003 at 19:32.
    John

  5. #5
    SitePoint Member insomica's Avatar
    Join Date
    Apr 2003
    Location
    Houston, TX
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?php
    while ($today = mysql_fetch_array($query)) {
    $day = $today["D.Day"];
    $sid = $today["D.SoupID"];
    $sname = $today["S.SoupName"]; // you are missing it here
    echo("'$sname'<br>" );
    }
    ?>

  6. #6
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahhhh..... Insomica, if you make him look for it, he'll remember it better!
    John

  7. #7
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    You guys are AWESOME! John, sorry you didn't get to make me look. To be honest, I would rather I need to look for things than be just told to copy and paste. What is the point of trying to learn PHP if I never write it? Just those little things that I don't always know what to look for. Sorry it may seem tedious to you, but very difficult for me. It is coming, just slowly.

    Anyway, thanks again. It works fantastic!
    TAKE A WALK OUTSIDE YOUR MIND.

  8. #8
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, it's not tedious to teach someone else. I remember very well making the very same mistakes... in fact I did it again this morning!

    The mistakes may come less frequently and the debugging goes faster with the experience gained over time, but they never go away!
    John

  9. #9
    SitePoint Zealot Egghead's Avatar
    Join Date
    Feb 2002
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by PHP John
    The mistakes may come less frequently and the debugging goes faster with the experience gained over time, but they never go away! ![img]images/smilies/eek.gif[/img]
    I hear that! Boy do I hear that!


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
  •