SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2000
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mysql call within a Mysql call?

    Hello,

    Is it possible to have a Mysql call within another Mysql call? For example:
    PHP Code:
    $sql "SELECT ID, Title, Author_ID, Category_ID, Date, Visible, Description FROM Content";
    $sql .= " WHERE Category_ID =$id";

    $result mysql_query($sql$cnx) or die("Couldn't execute 2nd query.");

    while (
    $row = @mysql_fetch_array($result))       {
    $ID $row["ID"];
    $Title $row["Title"];
    $Author_ID $row["Author_ID"];
    $Category_ID $row["Category_ID"];
    $Description $row["Description"];

    $aid "$AuthorID";
    $ArtDesc "$Description";

    print 
    "<a href=\"/article.php/".$ID."\"><b>".$Title."</b></a><br>\n";

    $sql = \"SELECT ID, Name FROM Authors\";
    $sql .= \" WHERE ID =$aid\";

    while (
    $row = @mysql_fetch_array($result))       {
    $Name = $row[\"Name\"];

    }

    print "
    <font size=\"-2\">by Author Name</font><br>\n";

    print 
    "$ArtDesc";
    print 
    "<br><br>\n\n";


    Any help would be appreciated.
    Corbb O'Connor
    Looking for quality website design or database programming?
    Contact me for more information and a FREE quote!

  2. #2
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, you just need to change the variable names so they don't conflict with each other. Remember that an sql query is a one of thing, it happens and is then finished (you might still be connected to the database but it is finished). When you are looping through results it is not like you are reading directly from a database but are reading from an array of results that have already been returned to your script. So yes, nested sql calls are perfectly fine so long you change variable names to avoid conflict.


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
  •