Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 4 123 ... LastLast
Results 1 to 15 of 56
  1. #1
    New Coder
    Join Date
    Apr 2007
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Retrieving records - return all fields in row

    Hello, I am making a drop down box to filter a sql database.

    Code:
    MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
    @mysql_select_db( "$dbName") or die( "Unable to select database");
    
    function secured($val)
     {
      $val = strip_tags(trim(($val))) ;
      $val = escapeshellcmd($val);
      return stripslashes($val);
      }
       if (get_magic_quotes_gpc()) 
       {
        $Manufacturer = $_POST['Manufacturer'];
       } 
        else
        {
        $Manufacturer = addslashes($_POST['Manufacturer']);
        }
        $Manufacturer = secured($Manufacturer);
    
    if ($Manufacturer != "SelectManufacturer") //The Default select value
    {
    $query = "SELECT * FROM bricks WHERE Manufacturer='$Manufacturer'";
    //take off the '1' on Manufacturer as suggested my Nightfire
    //make sure you getting the right values
    $result = mysql_query($query) or die("failed: ".mysql_error());
    $num_rows = mysql_num_rows($result);  
           if(!$num_rows)
            {
                echo "<table><tr><td align='center'>No data found 0 record returned</td></tr></table>";
             }
             else
                 {
                            echo "<table align='center'><tr>";
                            echo "<td align='center'><b>Manufacturer</b></td>";
                            echo "<td align='center'><b>Colour</b></td>";
                            echo "<td align='center'><b>Texture</b></td>";
                            echo "<td align='center'><b>Manufacturing Process</b></td>";
                            echo "</tr>";
                            
                            while($row = mysql_fetch_array($result, MYSQL_ASSOC))
                            echo "<tr><td align='center'>".$row["Manufacturer"]."</td>";
                            echo "<td align='center'>".$row["Colour"]."</td>";
                            echo "<td align='center'>".$row["Texture"]."</td>";
                            echo "<td align='center'>".$row["Manufacturing Process"]."</td>";
                             echo "</tr>";
    
                          }
                     echo "</table>";
          }
    ?>
    At the moment it only returns the manufacturer name and not the rest of the details in that row. How can i make it do that?

    .........

    Choose Manufacturer 1 and it will bring the results up.. but only the manufacturer name.

    Any help appreciated
    Last edited by firepages; 07-15-2007 at 02:23 AM. Reason: removed url on user request

  • #2
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Isn't this a repost?

    Verify the data exists in the database and make sure your fields are correct. Caps count.

  • #3
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Do this, do a print_r($result) and post that information up.

  • #4
    New Coder
    Join Date
    Apr 2007
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Resource id #2
    thats what comes up

  • #5
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    sorry do print_r($row) in your loop

  • #6
    New Coder
    Join Date
    Apr 2007
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Same table .... nothing else printed but the Manufacturer

  • #7
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Show me the results.

  • #8
    New Coder
    Join Date
    Apr 2007
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Manufacturer Colour Texture Manufacturing Process
    Manufacturer1
    Manufacturer1
    Manufacturer1

  • #9
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    OHH i think I see your problem

    Change this
    PHP Code:
                            while($row mysql_fetch_array($resultMYSQL_ASSOC))
                            echo 
    "<tr><td align='center'>".$row["Manufacturer"]."</td>";
                            echo 
    "<td align='center'>".$row["Colour"]."</td>";
                            echo 
    "<td align='center'>".$row["Texture"]."</td>";
                            echo 
    "<td align='center'>".$row["Manufacturing Process"]."</td>";
                             echo 
    "</tr>";

    //to this
                            
    while($row mysql_fetch_array($resultMYSQL_ASSOC)) {//notice the bracket
                            
    echo "<tr><td align='center'>".$row["Manufacturer"]."</td>";
                            echo 
    "<td align='center'>".$row["Colour"]."</td>";
                            echo 
    "<td align='center'>".$row["Texture"]."</td>";
                            echo 
    "<td align='center'>".$row["Manufacturing Process"]."</td>";
                             echo 
    "</tr>";
    }
    //notice the bracket 

  • #10
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    format you code better so you can keep track of brackets. I'm how did that even work?

  • #11
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Also do this to check your values
    PHP Code:
    while($row mysql_fetch_array($resultMYSQL_ASSOC)) {
        
    print_r($row);

    Then paste that up too.

  • #12
    New Coder
    Join Date
    Apr 2007
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    lol gotta love php


    Parse error: syntax error, unexpected $end in /************************8/results.php on line 56

    i changed the above to

    while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {//notice the bracket
    echo "<tr><td align='center'>".$row["Manufacturer"]."</td>";
    echo "<td align='center'>".$row["Colour"]."</td>";
    echo "<td align='center'>".$row["Texture"]."</td>";
    echo "<td align='center'>".$row["Manufacturing Process"]."</td>";
    echo "</tr>";

    Do I need to close bracket?
    Last edited by firepages; 07-15-2007 at 02:24 AM.

  • #13
    New Coder
    Join Date
    Apr 2007
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    YES! i closed the bracket and it worked thanks guys

  • #14
    New Coder
    Join Date
    Apr 2007
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How hard would it be for me to move on to making the drop downs for colour , texture to work also? Or should i just quit while im ahead and settle for a manufacturer drop down only.

  • #15
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I posted that info on your other thread, you need to build out your query. Check out the other thread.


  •  
    Page 1 of 4 123 ... LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •