PHP array

Discussion in 'Programming' started by dean5000v, May 7, 2008.

  1. #1
    ok well iv'e done a script that adds in a stock code, name and quantity into mysql, next i wont to be able to create a array which grabs the stock_code fields and prints them into a select box, does anyone have any examples i could learn of. thanks :D
     
    dean5000v, May 7, 2008 IP
  2. WhaLberg

    WhaLberg Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can use a simple one like that:

    
    <?php
    
    /**
     * @author    WhaLberg
     * @copyright 2008
     * @site     www.codinglabs.org
     */
    
    // gets the stock codes.
    $query = mysql_query("SELECT stock_code FROM stockcodes");
    while ($result = mysql_fetch_array($query))
    {
    	// assings the stock codes to an array.
    	$codes[] = $result['stock_code'];
    }
    // starts a selectbox.
    echo "<select name=\"stockcode\">";
    foreach ($codes AS $code)
    {
    	// add options for the stock codes.
    	echo "<option value=\"$code\">$code</option>";
    }
    // ends the selectbox.
    echo "</select>";
    
    ?>
    
    PHP:
     
    WhaLberg, May 14, 2008 IP