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.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Apr 2006
    Posts
    111
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Need help with item display

    So, I am trying to make two scripts where the items in a database are selected through the while control statement. The columns from the database are selected and put into an array using mysqli_fetch_array.

    I am able to get rows and things of that nature. I however, don't know how I would take a specific row and define it in the a href link.

    I basically want only one row's strings passed on to the next page.

    I can't remember how to do this, but I wrote what I know in two scripts:

    PHP Code:

    <?php include("header.php"); ?>

    <?php

        
    echo "<ul>";

            echo 
    "<li> {$row['ITEM']} </li>";
            echo 
    "<li> {$row['PRICE']} </li>";
            echo 
    "<li> {$row['ITEMIMAGE']} </li>";

        echo 
    "</ul>";

    ?>

    <?php include("footer.php"); ?>
    PHP Code:

    <?php include("header.php"); ?>

    <?php

        $abc 
    mysqli_connect('localhost','<REMOVED>','<REMOVED>');
        
    mysqli_select_db($abc,'<REMOVED>');

        
    $query mysqli_query($abc"SELECT * FROM ITEMS") or die ("Our database encountered a problem");

        echo 
    "<ul>";

        while (
    $row mysqli_fetch_array($queryMYSQLI_ASSOC)) {

        }

        echo 
    "</ul>";

        
    mysqli_close($abc);

    ?>

    <?php include("footer.php"); ?>
    I know that I am supposed to store all of the items in the array $row.

    I am uncertain about what I mentioned above. If I try to do a $row['ITEMNAME'] or put a key(), I am still clueless about how it's done.

    I hope someone can help me, as I am trying to code a website for my brothers business. Thanks in advance, SKY-PROTOSS

    [/PHP]
    Last edited by ShaneC; 05-30-2011 at 06:14 AM. Reason: Removed sensitive DB credentials

  • #2
    New Coder
    Join Date
    Sep 2010
    Location
    The Twilight Zone
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    I don't think it's a good idea to put your db user name and password on the page- it would be wise to get rid of it first. I'm not sure what you're asking- I'm assuming you just want to display all the items in a row on the page.

    I think you got most of it- here's what it should look like.
    PHP Code:
      echo "<ul>";
        
    //Assuming there will be > 1 result, the while loop will iterate through the $row array, so you simply have to insert your first script within the loop.

        
    while ($row mysqli_fetch_array($queryMYSQLI_ASSOC)) {

            echo 
    "<li>"  . {$row['ITEM']}  . "</li>";
            echo 
    "<li>"  . {$row['PRICE']}  . "</li>";
            echo 
    "<li>" . {$row['ITEMIMAGE']} . "</li>"
            
    //a line break to distinguish each row
            
    echo "<br />";
        }

        echo 
    "</ul>"

  • #3
    Codeasaurus Rex
    Join Date
    Jun 2008
    Location
    Redmond, WA
    Posts
    660
    Thanks
    31
    Thanked 100 Times in 94 Posts
    I've removed the sensitive credentials. Unfortunately I can't guarantee that a crawler didn't snatch them up. As such, I highly recommend changing your database username and password.
    Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
    My posts, comments, code, and suggestions reflect only my personal views.
    Web Portfolio and Code Snippets: http://shanechism.com

  • #4
    Regular Coder
    Join Date
    Apr 2006
    Posts
    111
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by ShaneC View Post
    I've removed the sensitive credentials. Unfortunately I can't guarantee that a crawler didn't snatch them up. As such, I highly recommend changing your database username and password.
    I hope they did not get indexed on google. If that's the case then I will change them.

    So, the idea for this was to display a specific item with a custom url.

    So in other words, I am wanting to run a match with the link you click, to display only one item.

    So if I have:

    <a href="...">{$row['ITEMNAME']}</a>

    what would I put to go directly to that item, since it's just going to display every item?

    There has to be a way to run the item check without being specific? Thanks.


  •  

    Posting Permissions

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