Showing data too many times

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Igor Slivka

    Showing data too many times

    New problem ;). I got script running and showing projects, now i'm trying to
    show category for every project from another table. I want to do this in new
    page. Everything is fine except ;))... it shows the data in according with
    how many projects i have. So if i have 3 project da data from category table
    is shown three times, if two projects it's shown two times etc.
    The code is following:

    <?php
    require('config .php');
    $conn = mysql_connect(S QL_HOST, SQL_USER, SQL_PASS) or
    die ('Could not connect to MySQL database.' .mysql_error()) ;
    mysql_select_db (SQL_DB, $conn);


    $display_block = "<h1>$project_n ame</h1>
    <P>Select a Category to see details.</P>";

    //validate category
    $cat_id_info = isset($_GET['id']) ? intval($_GET['id']) : 0;
    $get_info = "SELECT
    category.id,
    category.projec t_id,
    category.cat_na me,
    category.cat_de sc,
    project.project _name,
    project.id
    FROM
    category,
    project
    WHERE
    category.projec t_id = $cat_id_info
    ORDER BY category.cat_na me";
    $result = mysql_query($ge t_info) or die (mysql_error()) ;
    $num_category = mysql_num_rows( $result);

    $display_block .= "<a href=\"proba_li nk.php\">Back</a></strong></p>";


    if (mysql_num_rows ($result) < 1) {
    $display_block = "<P><em>BLABLA. </em><br>
    <a href=\"proba_li nk.php\">Back</a></strong></p>";
    } else {

    while ($cat = mysql_fetch_arr ay($result)) {
    $cat_id = $cat[id];
    $cat_name = strtoupper(stri pslashes($cat[cat_name]));
    $cat_desc = stripslashes($c at[cat_desc]);

    $display_block .= "<p><strong>$ca t_name</strong>
    <br>$cat_desc </p>";



    }
    }
    ?>
    <HTML>
    <HEAD>
    <TITLE>Navtec Marine</TITLE>
    </HEAD>
    <BODY>
    <?

    print $display_block;

    ?>
    </BODY>
    </HTML>



    Tnx in advance, best regards
    Igor Slivka


  • Colin McKinnon

    #2
    Re: Showing data too many times

    Igor Slivka wrote:
    [color=blue]
    > New problem ;). I got script running and showing projects, now i'm trying
    > to show category for every project from another table. I want to do this
    > in new page. Everything is fine except ;))... it shows the data in
    > according with how many projects i have. So if i have 3 project da data
    > from category table is shown three times, if two projects it's shown two
    > times etc. The code is following:
    >[/color]
    <snip>[color=blue]
    > $get_info = "SELECT
    > category.id,
    > category.projec t_id,
    > category.cat_na me,
    > category.cat_de sc,
    > project.project _name,
    > project.id
    > FROM
    > category,
    > project
    > WHERE
    > category.projec t_id = $cat_id_info
    > ORDER BY category.cat_na me";[/color]

    You haven't joined the category and project tables so your getting a
    cartesian product. Guessing the structure of your data, I would try adding
    AND project_id=proj ect.id
    in the where clause.

    '$cat_id_info' is badly named since it references a project not a category
    (either that or the names of your other fields are bad).

    HTH

    C.

    Comment

    Working...