SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    E-business guru Eirik's Avatar
    Join Date
    Nov 2000
    Location
    Oslo, Norway
    Posts
    413
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi guys,

    I use the following SQL query to fetch some information about the chapter and the articles the belong to of those which haven't been edited:

    $sql = "SELECT Chapter.Name, Article.Name, Number, Chapter.AID FROM Chapter, Article WHERE Edited !=1;";

    $result = mysql_query($sql);

    Now, when I try to save the information into variables, that's when the problems start. I thought maybe that I could use the same names including the dot to access the variables through the result array, but that yield no result. Then I tried just the names after the dot, like this:

    while ($row = mysql_fetch_array($result)) {
    $chaptername = $row["Name"];
    $articlename = $row["Name"];
    $number = $row["Number"];
    $theartid = $row["AID"];
    }

    However, not too surprisingly, that returned the same result to both the $chaptername and @articlename variable (which was the article name). So, my question is this:

    How can I get a hold of the chapter name. In what variable is it stored, if any at all?

    Thanks in advance !
    Sincerely,

    Eirik Johansen
    Netmaking AS

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One way would be to alias the field like
    (remove the bolded semicolon also)
    $sql = "SELECT Chapter.Name as chaptername, Article.Name as articlename, Number, Chapter.AID FROM Chapter, Article WHERE Edited !=1;";

    while ($row = mysql_fetch_array($result)) {
    $chaptername = $row["chaptername"];
    $articlename = $row["articlename"];
    $number = $row["Number"];
    $theartid = $row["AID"];
    }
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    E-business guru Eirik's Avatar
    Join Date
    Nov 2000
    Location
    Oslo, Norway
    Posts
    413
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, man! It worked like charm. Then again, I guess you knew it would.

    Thanks again !
    Sincerely,

    Eirik Johansen
    Netmaking AS


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
  •