having trouble showing table categories on php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashraf02
    New Member
    • Feb 2008
    • 53

    having trouble showing table categories on php

    basically i am trying to create an online storefront. i have three seperate tables where which i want to show on the page. three table are linked to one table called Smart. when i execute the code and try to click on the category only one out of three of the tables show the others show tell me no records to show when they actually have data in them can some one please help. here's the code.

    [PHP]$display_block = "<h1>Smartegori es</h1>
    <p>select Smart to see items.</p>";

    $get_Smarts = "SELECT Smart_ID, Smart_title, Smart_descripti on
    FROM Smart
    ORDER BY Smart_title";

    $get_Smart_res = mysql_query ($get_Smarts) or die (mysql_error()) ;

    if (mysql_num_rows ($get_Smart_res ) < 1) {
    $display_block = "<p><em>Sor ry no Smarts to browse</em></p>";
    } else {

    while ($Smarts = mysql_fetch_arr ay ($get_Smart_res )) {
    $Smart_ID = $Smarts [Smart_ID];
    $Smart_title = strtoupper (stripslashes ($Smarts[Smart_title]));
    $Smart_desc = stripslashes ($Smarts [Smart_descripti on]);

    $display_block .= "<p><strong >
    <a href=\"$_SERVER[PHP_SELF]?Smart_ID=$Smar t_ID\">$Smart_t itle</a></strong>
    <br>$Smart_desc </p>";

    if ($_GET[Smart_ID] == $Smart_ID) {
    $get_suits = "SELECT Suit_ID, Suit_Brand, Suit_Price FROM
    Suits WHERE Smart_ID = '$Smart_ID'
    ORDER BY Suit_Brand";

    $get_suit_res = mysql_query ($get_suits) or die (mysql_error()) ;

    if (mysql_num_rows ($get_suit_res) < 1 ) {
    $display_block = "<p><em>Sor ry no items in this Smart</em></p>";
    } else {

    $display_block .= "<ul>";

    while ($Suits = mysql_fetch_arr ay($get_suit_re s)) {
    $Suit_id = $Suits[Suit_ID];
    $Suit_title = stripslashes($S uits[Suit_Brand]);
    $Suit_price = $Suits[Suit_Price];

    $display_block .= "<li>
    <a href=\"showitem .php?Suit_ID=$S uit_id\">$Suit_ title</a>
    </strong> (£$Suit_price)" ;

    }

    $display_block .= "<ul>";
    }

    $get_shirts = "SELECT shirt_ID, shirt_Brand, shirt_Price FROM
    shirts WHERE Smart_ID = '$Smart_ID'
    ORDER BY shirt_Brand";

    $get_shirt_res = mysql_query ($get_shirts) or die (mysql_error()) ;

    if (mysql_num_rows ($get_shirt_res ) < 1 ) {
    $display_block = "<p><em>Sor ry no items in this Smart</em></p>";
    } else {


    while ($shirts = mysql_fetch_arr ay($get_shirt_r es)) {
    $shirt_id = $shirts[shirt_ID];
    $shirt_title = stripslashes($s hirts[shirt_Brand]);
    $shirt_price = $shirts[shirt_Price];

    $display_block .= "<li>
    <a href=\"showitem .php?shirt_ID=$ shirt_id\">$shi rt_title</a>
    </strong> (£$shirt_price) ";
    }


    $display_block .= "<ul>";
    }

    $get_Trousers = "SELECT Trouser_ID, Trouser_Brand, Trouser_Price FROM
    Trousers WHERE Smart_ID = '$Smart_ID'
    ORDER BY Trouser_Brand";

    $get_Trouser_re s = mysql_query ($get_Trousers) or die (mysql_error()) ;

    if (mysql_num_rows ($get_Trouser_r es) < 1 ) {
    $display_block = "<p><em>Sor ry no items in this Smart</em></p>";
    } else {


    while ($Trousers = mysql_fetch_arr ay($get_Trouser _res)) {
    $Trouser_id = $Trousers[Trouser_ID];
    $Trouser_title = stripslashes($T rousers[Trouser_Brand]);
    $Trouser_price = $Trousers[Trouser_Price];

    $display_block .= "<li>
    <a href=\"showitem .php?Trouser_ID =$Trouser_id\"> $Trouser_title</a>
    </strong> (£$Trouser_pric e)";
    }


    $display_block .= "<ul>";
    }
    }
    }
    }
    ?>[/PHP]

    I am desperate as time is running out for me. any help would be greatly appreciated.
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    I see no form or any $_GET handling, so how did you put the ID in the $_GET array here[php]if ($_GET[Smart_ID] == $Smart_ID) {[/php]From the url? From a form? How is this script invoked?

    Ronald

    Comment

    • ashraf02
      New Member
      • Feb 2008
      • 53

      #3
      doesn't it just fetch it from the database. i've copied the code from a book making the right adjustments according to my project. in the book it doesn't indicate the use of any forms. it works for the suit section but not the others so i'm assuming it works.

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Never copy any code from a book when you don't know what you are copying!

        This code won't work because the content of the $_GET array is nil. That array is filled only via a HTTP GET request, and I don't think you do that. So re-think that code and adapt it or try to write your own.

        Ronald

        Comment

        • ashraf02
          New Member
          • Feb 2008
          • 53

          #5
          i know wat i am copying and if it works for one there is no harm in copying from it. wat i'm trying to say if it can be done for one table that is connected to another it should be able to work for three table connected to one.

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            Then you made the wrong adjustments! This line returns nothing, it is always false, because you do not have a $_GET[Start_ID] anywhere in your code, It is not passed via the URL and it is not passed via a submitted form as you said yourself. The nwhy are you using this $_GET array variable? [php] if ($_GET[Smart_ID] == $Smart_ID) {[/php]Ronald

            Comment

            • ashraf02
              New Member
              • Feb 2008
              • 53

              #7
              don't worry bout it ronald i do appreciate ur time tho. i have figured out the problem and sorted it out. it happens that capital letters have to be the same from mysql table and the php code.

              if u want i can show u the whole code .... but it does work.

              Comment

              Working...