SitePoint Sponsor

User Tag List

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

    Another PHP Problem

    Hello,

    Now that I have my script working, something else goes wrong! I have the script below, but it will only show the first record from the database pretaining to that category. I need it to display all the records pretaining to a specific category. Any help is appreciated.
    PHP Code:
    <?
    include("/home/corby/phplib/pass.inc");

    $db_name "justforwebmasters_com";
    $table_name "Categories";
    $pathstring getenv("HTTP_HOST") == "justforwebmasters.com" 
    getenv("PATH_INFO") : $PHP_SELF ;

    $id $id;

    // Allow Slash Marks Instead of Query Strings
    $url_array explode("/",$PATH_INFO);
    $id=$url_array[1];

    $db mysql_select_db($db_name$cnx) or die("Couldn't select database.");


    // Select The Categories From the Categories Table
    $sql "SELECT ID, BigCat, Title, Description FROM $table_name";
    $sql .= " WHERE ID =$id";

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

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

    print 
    "<html>\n";
    print 
    "<head>\n";
    print 
    "   <title>JustForWebmasters > ".$BigCat." > ".$Title."</title>\n";
    print 
    "</head>\n";
    include(
    "http://www.justforwebmasters.com/includes/1.inc");
    print 
    "<a href=\"/".$BigCat.".php\" class=\"WhereYouAre\">".$BigCat." Your Site</a> > ".$Title."\n";
    include(
    "http://www.justforwebmasters.com/includes/2.inc");
    print 
    "<font class=\"Heading\">".$Title."</font><br><br>\n";
    print 
    "<font class=\"RegularText\">";

    print 
    "".$ID."<br>";
    print 
    "".$BigCat."<br>";
    print 
    "".$Title."<br>";
    print 
    "".$Description."<br>";

    // Select Everything Pretaining to the Articles in the Content table
    $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"];

    print 
    "".$ID."<br>";
    print 
    "".$Title."<br>";
    print 
    "".$Author_ID."<br>";
    print 
    "".$Category_ID."<br>";
    print 
    "".$Description."<br><br>";

    $aid "$Author_ID";
    $ArtDesc "$Description";

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

    // Select Everything Pretaining to the Authors
    $authorsql "SELECT ID, Name FROM Authors";
    $authorsql .=" WHERE ID = $aid";

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

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

    }

    print 
    "".$ID."<br>";
    print 
    "".$Name."<br><br>";

    $aname "$Name";

    print 
    "<font size=\"-2\">By: $aname</font><br>";
    print 
    "$ArtDesc";
    print 
    "<br><br>\n\n";

    }

    include(
    "http://www.justforwebmasters.com/includes/3.inc");
    ?>
    Last edited by JustForWebmasters; Jun 12, 2001 at 18:41.
    Corbb O'Connor
    Looking for quality website design or database programming?
    Contact me for more information and a FREE quote!

  2. #2
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you dont want to select a specific article you may want to get rid of the where statement in your sql.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  3. #3
    SitePoint Evangelist
    Join Date
    Dec 2000
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have to have that where statement. It tells the database to only show the records from the specified category.
    Corbb O'Connor
    Looking for quality website design or database programming?
    Contact me for more information and a FREE quote!

  4. #4
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    which specific SQL statement is the one that gets your article list, only post that part of your script.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  5. #5
    SitePoint Evangelist
    Join Date
    Dec 2000
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This part:
    PHP Code:
    // Select Everything Pretaining to the Articles in the Content table
    $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"];

    print 
    "".$ID."<br>";
    print 
    "".$Title."<br>";
    print 
    "".$Author_ID."<br>";
    print 
    "".$Category_ID."<br>";
    print 
    "".$Description."<br><br>";

    $aid "$Author_ID";
    $ArtDesc "$Description";

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

    // Select Everything Pretaining to the Authors
    $authorsql "SELECT ID, Name FROM Authors";
    $authorsql .=" WHERE ID = $aid";

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

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


    Last edited by JustForWebmasters; Jun 12, 2001 at 18:36.
    Corbb O'Connor
    Looking for quality website design or database programming?
    Contact me for more information and a FREE quote!

  6. #6
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $result = mysql_query($authorsql, $cnx) or die("Couldn't execute 2nd query.");

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

    }


    That part is changing $result, which you used at the top also. Change the variable name to something else.

  7. #7
    SitePoint Evangelist
    Join Date
    Dec 2000
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anarchos,

    Thank you, it works now! http://www.justforwebmasters.com/cats.php/7.
    Corbb O'Connor
    Looking for quality website design or database programming?
    Contact me for more information and a FREE quote!


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
  •