Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 5th, 2003, 12:25 AM
Authorized User
 
Join Date: Jun 2003
Location: Quezon City, NCR, Philippines.
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!!!
Reply With Quote
  #2 (permalink)  
Old August 7th, 2003, 07:23 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:11 PM.


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