Jump to content

Drop Down from sql table


nashsaint

Recommended Posts

Hi,  I wanted to populate a drop down menu from sql table but my code doesn't work.. help please.

 

 

Here's my Code:

<select name="select">';
     // default is 0, no entry will be selected.
     db_createlist($linkID,0,"select pull_id, pc from job_log_pull","Please select one ...");

</select>

 

 

 

And here's the function:

function db_createlist($linkID,$default,$query,$blank)
{
    if($blank)
    {
        print("<option select value=\"0\">$blank</option>");
    }

    $resultID = pg_exec($linkID,$query);
    $num       = pg_numrows($resultID);

    for ($i=0;$i<$num;$i++)
    {
        $row = pg_fetch_row($resultID,$i);

        if($row[0]==$default)$dtext = "selected";
        else $dtext = "";

        print("<option $dtext value=\"$row[0]\">$row[1]</option>");
    }
}

Link to comment
https://forums.phpfreaks.com/topic/107311-drop-down-from-sql-table/
Share on other sites

I tried unidox code but I couldn't get it to work.  I tried another approach and it seems to be working but now I don't know how to capture the user's selection from the select, since this form is under another Form statement.

Any help how to extract the user selection?

 

Thanks.

                        $pcquery = "SELECT pull_id, pc FROM job_log_pull";
                        $pcresult = @mysql_query($pcquery);
                        echo '<form action=blah method=Post>
                        <select name=category>';
                            // get resultset as object
                            while ($pcrow = mysql_fetch_object($pcresult))
                                {
                            echo "<option value=" . $pcrow->pull_id . ">" . $pcrow->pc .  "</option><br>";
                                }
                        echo '</select>
                        </form>';
                        mysql_free_result($pcresult);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.