Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 5th, 2003, 12:25 AM
Authorized User
 
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to vickriz
Default ASP to PHP anbody??

hello there folks, good day..
sorry but i dont know where im gonna post this issue i have..
i found this script interesting in form of asp. but i want it to translate in php script. can anybody help me?

Code:
Forms - Populating a drop down menu with info from a database
--------------------------------------------------------------------------------
 
Below is an example of a basic drop down menu populated from a database.

<% 
' Not neccesary but a good habit
Dim DataConn
Dim CmdPopulateStates
Dim SQL
%>

<%
Set DataConn = Server.CreateObject("ADODB.Connection")
Set CmdPopulateStates = Server.CreateObject("ADODB.Recordset")
%>

Take away the comment on Sytem DSN version below if you want to use a system DSN instead and add a comment to the DSN-LESS connection version below it

<% 
' DataConn.Open "DSN=System_DSN_Name"

DataConn.Open "DBQ=" & Server.Mappath("_database/zipcodes.mdb") &   ";Driver={Microsoft Access Driver (*.mdb)};"

SQL = "SELECT DISTINCT STATE_NAME FROM STATES"
CmdPopulateStates.Open SQL, DataConn
%>

<form method="POST" action="somepage.asp">
<Select Name="STATE_NAME" size="1">
<%While Not CmdPopulateStates.EOF%>

<option value="<%= CmdPopulateStates("STATE_NAME") %>"><%= CmdPopulateStates("STATE_NAME") %></option>

<%
CmdPopulateStates.MoveNext
Wend
%>

<% 
' Not neccesary but a good habit
CmdPopulateStates.Close
Set CmdPopulateStates = Nothing
DataConn.Close
Set DataConn = Nothing
%>

</Select>
<input type="submit" value="Submit">
</form>
iL populate also similar data from postgresql back-end..
thanks in advance.

Mabuhay!!!
__________________
Mabuhay!!!
 
Old August 7th, 2003, 07:23 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Moharo
Default

this is relatively simple... first of all you gonna have to setup database. then do this (code works with mysql database, you can just substitute equivalent postgresql functions):

<?

$conn = mysql_connect('localhost','***','***');
//***, *** username and password to database

mysql_select_db('database_name',$conn);
//selecting database

?>

<form method="POST" action="somepage.php">
    <select name="STATE_NAME" size="1">
    <?

    $sql = "SELECT DISTINCT STATE_NAME FROM STATES";
    $result = mysql_query($sql,$conn);

    while($row = mysql_fetch_object($result)) { ?>

    <option value="<? echo $row->STATE_NAME; ?>"> <? echo $row->STATE_NAME; ?> </option>

    <? } ?>

    </select>
    <input type="submit" value="Submit">
</form>

hope that helped :D:):D:D:D





the genuine genius





Similar Threads
Thread Thread Starter Forum Replies Last Post
Asp/ PHP explore_asp Classic ASP Professional 4 February 23rd, 2013 04:16 AM
ASP.NET vs. PHP Aaron Edwards ASP.NET 2.0 Basics 0 May 6th, 2006 12:51 PM
ASP.NET and PHP Prabhakar_dt VB Components 0 September 9th, 2005 04:44 AM
ASP to php kobalt7 Beginning PHP 1 June 14th, 2005 03:30 PM
php to asp simflex Classic ASP Professional 2 June 10th, 2004 11:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.