SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <HTML>
    <HEAD>
    <TITLE>List</TITLE>
    </HEAD>
    <BODY><br><Br><br>
    <basefont face="verdana"><font size="2">
    <table width="60%" align="center">
    <tr><td>
    <?php

    include("articles.inc");
    mysql_select_db('petesmc_articles');

    // SELECT

    $select = mysql_query("SELECT AID, PID, articles.Description, Title, Name FROM articles, title, authors " .
    " WHERE TID=title.ID AND AuthorID=authors.ID AND SubID=$id ");

    if (!$select) {
    echo("<P>Error retrieving category from database!<BR>".
    "Error: " . mysql_error());
    exit();
    }

    // WRITE ARRAY AND DISPLAY

    while ($list= mysql_fetch_array($select)) {
    $aid = $list["AID"];
    $pid = $list["PID"];
    $name = $list["Name"];
    $title = $list["Title"];
    $description = $list["Description"];
    echo("<p><a href='article.php?aid=$aid&pid=$pid'><font size='+1'><b>$title</b> " .
    "</font></a><br><font size='1' color='#3366FF'>By $name</font><br>$description");
    }
    ?>

    </td></tr></table>
    </font></body></html>


    Example of the script, doesn't work obviously, it should display a record:

    http://216.74.101.27/list.php?id=1

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where's the username/password? Is it in the articles.inc file?

  3. #3
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, make sure the user/pass is present.

    And also, in this query:

    $select = mysql_query("SELECT AID, PID, articles.Description, Title, Name FROM articles, title, authors WHERE TID=title.ID AND AuthorID=authors.ID AND SubID=$id");

    Try typing that query in PHPMyAdmin, and see if any results comes up.

    You might have to use:

    SELECT AID, PID, articles.Description, Title, Name FROM articles, title, authors WHERE articles.TID=title.ID AND articles.AuthorID=authors.ID AND articles.SubID=$id

    Notice in the WHERE bit, I define the table's name in both the column names, you might have to do that when there's 2+ tables.

    Also, try putting the WHERE queries in the same order as the FROM queries. eg:

    FROM articles, title, authors WHERE articles.tid=title.id AND articles.authorID=authors.ID

    Not:

    FROM articles, title, authors WHERE articles.authorID=authors.ID AND articles.tid=title.id



  4. #4
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, username and pass are in articles.inc

    In PHPMyAdmin i get the error:

    Error
    SQL-query:

    mysql_query("SELECT AID, PID, articles.Description, Title, Name FROM articles, title, authors WHERE TID=title.ID AND AuthorID=authors.ID AND SubID=$id");

    MySQL said: You have an error in your SQL syntax near 'mysql_query("SELECT AID, PID, articles.Description, Title, Name FROM articles, t' at line 1



    <Edited by petesmc on 01-04-2001 at 05:08 PM>

  5. #5
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  6. #6
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In:

    SELECT AID, PID, articles.Description, Title, Name FROM

    Define which table those fields are in, like:

    SELECT articles.aid, articles.pid, articles.description... FROM...

  7. #7
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OKay, done that. In PHPMyAdmin is get an error saying that:

    SQL-query:

    SELECT articles.AID, articles.PID, articles.Description, title.Title, authors.Name FROM articles, title, authors WHERE articles.TID=title.ID AND articles.AuthorID=authors.ID AND articles.SubID=$id
    MySQL said: Unknown column '$id' in 'where clause'

    Here is my current code:

    --------------

    <?php

    include("articles.inc");
    mysql_select_db('petesmc_articles');

    // SELECT

    $text = "SELECT articles.AID, articles.PID, articles.Description, title.Title, authors.Name FROM articles, title, authors WHERE articles.TID=title.ID AND articles.AuthorID=authors.ID AND articles.SubID=$id";

    $select = mysql_query($text);

    if (!$select) {
    echo("<P>Error retrieving category from database!<BR>".
    "Error: " . mysql_error());
    exit();
    }

    // WRITE ARRAY AND DISPLAY

    while ($list= mysql_fetch_array($select)) {
    $aid = $list["AID"];
    $pid = $list["PID"];
    $name = $list["Name"];
    $title = $list["Title"];
    $description = $list["Description"];
    echo("<p><a href='article.php?aid=$aid&pid=$pid'><font size='+1'><b>$title</b> " .
    "</font></a><br><font size='1' color='#3366FF'>By $name</font><br>$description");
    }
    ?>

  8. #8
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx allot guys, i got it working

  9. #9
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can have $id in the PHPMyAdmin command, 'cos $id is a variable, and you can define it in PHPMyAdmin, replace it with a number instead.

    But if the query was done in a php file, and the id had been defined, then it should work. like filename.php?id=2

  10. #10
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx so much

  11. #11
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just need help with another script that no one could figure our earlier........if you wanna help just ask me..



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
  •