SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot zook's Avatar
    Join Date
    May 2001
    Location
    Houston, tx
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    while ( problems );

    Alright, I've got a database with multi-part articles. The parts of the article are stored in a table called pages with fields: 'aid'(article id) 'pid'(part id) 'pname'(partname) and 'text'. each part has its own row.

    I'm trying to create a script to display all the parts of a given article.

    i can't seem to get this right, heres the chunk of code:

    PHP Code:
    $sql mysql_query("SELECT pname, text FROM pages WHERE aid=$aid AND pid=$pid");
    while ( 
    $row mysql_fetch_array($sql) ) {
    $pid2 $row["pid"];
    $pname2 $row["pname"];
    $text2 $row["text"];
    echo(
    "<p class=\"subtitle\">Part $pid2$pname2<p>$text2");
    $pid++;

    any suggestions?

  2. #2
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem is you are not selecting all the fields you need, try this

    Code:
    $sql = mysql_query("SELECT * FROM pages WHERE aid=$aid AND pid=$pid");
    while ( $row = mysql_fetch_array($sql) ) {
    $pid2 = $row["pid"];
    $pname2 = $row["pname"];
    $text2 = $row["text"];
    echo("<p class=\"subtitle\">Part $pid2: $pname2<p>$text2");
    }
    BTW which is the primary key, AID or PID?

  3. #3
    SitePoint Zealot zook's Avatar
    Join Date
    May 2001
    Location
    Houston, tx
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BTW which is the primary key, AID or PID?
    neither. aid is the id of the article, pid the the part id. is it neccasarry to set a primary key?

    thanks for pointing out the missing field. i still need to somehow add 1 the pid and then display everything again...thats where im lost.

  4. #4
    SitePoint Zealot zook's Avatar
    Join Date
    May 2001
    Location
    Houston, tx
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes! after testing idea after idea i finally found the problem. see, i was using the WHERE clause with "where aid=$aid and pid=$pid - limiting myself to access to that one particular row, while trying to get multiple rows. i took out the "and pid=$pid" as well as "$pid++;" and it worked fine.

    thanks for your support though!

  5. #5
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    glad I could help


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
  •