PHP Question

Discussion in 'PHP' started by dean5000v, Jul 8, 2008.

  1. #1
    ok well ive managed to do PHP script to insert data into the database e.g. stock codes, descriptions and price. i have then created scripts to print this information onto the page.

    I normally have to manually add in the HTML & PHP for each item in order for the information to be displayed on a page i was wondering how would i do it so it dynamically adds in the HTML & PHP so the new items can be displayed on the screen without doing it manually i kinda guess you would use MYSQL to store the HTML but i can't find any good examples to learn of.

    if anyone could possibly guide me in the right way that would be great.
     
    dean5000v, Jul 8, 2008 IP
  2. singh.ajit05

    singh.ajit05 Peon

    Messages:
    83
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you can take reference from php.net website
    Here you found complete documenation in doc file just download and start study..
    You will get so many exampe in that documentation

    It's really help to learn how to manipulate dynamic text............
     
    singh.ajit05, Jul 8, 2008 IP
  3. dean5000v

    dean5000v Peon

    Messages:
    201
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    the idea that i have about it is that i would use a loop for so each stock item found i would echo the HTML code, but im not to sure if this wld be the best way to do it.
     
    dean5000v, Jul 8, 2008 IP
  4. ayaw

    ayaw Peon

    Messages:
    164
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #4
    it's called database bro...
    the general way to make it work in php is using a form to submit.

    then, process it by retrieving the form variables using $_GET and store it using mysql_query
     
    ayaw, Jul 8, 2008 IP
  5. dean5000v

    dean5000v Peon

    Messages:
    201
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i just want a example which would like basically loop through all of the item codes in the database and then echo the html each time, and then just once it has run out of stock codes. obviously i dnt want people to do it for me just a small example i can do the rest myself.
     
    dean5000v, Jul 8, 2008 IP
  6. ayaw

    ayaw Peon

    Messages:
    164
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i usually use combination of mysql_query, "while" loop and mysql_fetch_assocc.
    the example on php.net is clear... just enter the mysql section.
     
    ayaw, Jul 8, 2008 IP
  7. maneetpuri

    maneetpuri Active Member

    Messages:
    152
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #7
    Hi,

    Below is a small PHP script you can use: -

    I assume that the name of the table is prod_table and it has following fields - stock_code, desc and price. The PHP script below will fetch all the records from this table and show it on the screen

    <?
    $qstr = "select * from prod_table";
    $qry = mysql_query($qstr);

    while ($arr = mysql_fetch_assocc($qry)) {
    echo "Stock Code: " . $arr["stock_code"] . "<br>";
    echo "Description: " . $arr["desc"] . "<br>";
    echo "Price: " . $arr["price"] . "<br>";
    }
    ?>

    Hope this helps.

    -Maneet
     
    maneetpuri, Jul 8, 2008 IP
  8. Mozzart

    Mozzart Peon

    Messages:
    189
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I'm guessing what you are looking for is a template engine, have you looked at http://smarty.php.net ?
     
    Mozzart, Jul 8, 2008 IP
  9. dean5000v

    dean5000v Peon

    Messages:
    201
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    thanks that helped i got this working.


    
    <?php
    $query = "SELECT * from stock";
    $result = mysql_query($query);
    
    
    while ($row = mysql_fetch_assoc($result)) {
        echo "<div id=\"test\" style=\"height: 50px; width: 100px;\">" .$row["item_code"] .$row["item_desc"] ."</div><br>";
    }
    ?>
    
    
    Code (markup):
    :D
     
    dean5000v, Jul 8, 2008 IP