473,395 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

rewritting a short ASP script to PHP

The following is a short ASP script and I would like to change it into
a PHP script. The script of off of the W3 Schools wep
site(http://www.w3schools.com/ajax/ajax_database.asp). I am not sure
what would need to be changed to fit into the PHP syntax. Alright, here
is the short script I need help with. Have at it if you want to help
me. Thanks in advanced to any help at all.

sql="SELECT * FROM CUSTOMERS WHERE CUSTOMERID="
sql=sql & request.querystring("q")

set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
rs.Open sql, conn

response.write("<table>")
do until rs.EOF
for each x in rs.Fields
response.write("<tr><td><b>" & x.name & "</b></td>")
response.write("<td> & x.value & "</td></tr>")
next
rs.MoveNext
loop

response.write("</table>")

Mar 20 '06 #1
4 1317
brad wrote:
The following is a short ASP script and I would like to change it into
a PHP script. The script of off of the W3 Schools wep
site(http://www.w3schools.com/ajax/ajax_database.asp). I am not sure
what would need to be changed to fit into the PHP syntax. Alright, here
is the short script I need help with. Have at it if you want to help
me. Thanks in advanced to any help at all.

sql="SELECT * FROM CUSTOMERS WHERE CUSTOMERID="
sql=sql & request.querystring("q")
$sql = 'SELECT * FROM customers WHERE customerid='.intval($_GET['q']);
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
This stuff you'd need to use the correct connection functions in php. If
you're using ODBC for connection, check on this page:
http://www.php.net/odbc (odbc_connect)

Be sure to skim the user-submitted notes as well at the bottom of the page.
set rs = Server.CreateObject("ADODB.recordset")
rs.Open sql, conn
This part requires the use of a query function. I believe that odbc_exec
is the one you'll need for that.
response.write("<table>")
do until rs.EOF
for each x in rs.Fields
response.write("<tr><td><b>" & x.name & "</b></td>")
response.write("<td> & x.value & "</td></tr>")
next
rs.MoveNext
loop

response.write("</table>")


You may be able to use odbc_result_all to do this...

I've never used ODBC stuff myself, and I've never connected PHP with an
Access database (nor will I ever want to).

HTH

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Mar 20 '06 #2
I'm sorry. I didn't notice that it wase an Access database, which is
not what I am going to use. I will be using a MySQL database. Sorry
about that. With that in mind, MySQL, how would I code the second part
in PHP..of creating the table. This part:
response.write("<table>")
do until rs.EOF
for each x in rs.Fields
response.write("<tr><td><b>" & x.name & "</b></td>")
response.write("<td> & x.value & "</td></tr>")
next
rs.MoveNext
loop

response.write("</table>")

Mar 20 '06 #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

brad wrote:
I'm sorry. I didn't notice that it wase an Access database, which is
not what I am going to use. I will be using a MySQL database. Sorry
about that. With that in mind, MySQL, how would I code the second part
in PHP..of creating the table. This part: response.write("<table>")
do until rs.EOF
for each x in rs.Fields
response.write("<tr><td><b>" & x.name & "</b></td>")
response.write("<td> & x.value & "</td></tr>")
next
rs.MoveNext
loop

response.write("</table>")


$rs = mysql_query($sql,MYSQL_ASSOC);

echo '<table>';
while ($row = mysql_fetch_array($rs))
{
foreach($row as $column_name=>$value)
echo "<tr><td><b>$column_name</b></td><td>$value</td></tr>";
}
echo '</table>';

- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

http://acm.asoc.fi.upm.es/~mr/ ; http://acm.asoc.fi.upm.es/~ivan/
MSN:i_*************************@hotmail.com
Jabber:iv*********@jabber.org ; iv*********@kdetalk.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFEHw303jcQ2mg3Pc8RAuiQAJ93yo7YE1V2o9LMpS+So4 tZNWnYIwCffABp
R8w3Xz0l6eCVp4f0zy9nZnI=
=Gtre
-----END PGP SIGNATURE-----
Mar 20 '06 #4

Iván Sánchez Ortega wrote:
response.write("<table>")
do until rs.EOF
for each x in rs.Fields
response.write("<tr><td><b>" & x.name & "</b></td>")
response.write("<td> & x.value & "</td></tr>")
next
rs.MoveNext
loop

response.write("</table>")


$rs = mysql_query($sql,MYSQL_ASSOC);

echo '<table>';
while ($row = mysql_fetch_array($rs))
{
foreach($row as $column_name=>$value)
echo "<tr><td><b>$column_name</b></td><td>$value</td></tr>";
}


It looks sooooo much nicer in PHP :)

Mar 20 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Johnny Carson | last post by:
I've got this PHP script working on one of my sites and now need an ASP version for my intranet. I don't know ASP, can anyone help out? Know of anyway to NOT have a blank browser window open...
4
by: Jo | last post by:
Is there anyway we can know using JavaScript the Short Date Format used in the Control Panel -> Regional and Language Settings? I know the using the combinations of following we can get the...
4
by: JeffP | last post by:
I want to add a short-cut to a windows app similar to launching from a windows run line a New window, to prevent changing an existing browser window from moving off a current logged in session...
5
by: Frank Borell | last post by:
I'm having a problem retrieving the ShortName from a file that was written by a MAC and only from a Windows 2003 server. I realize the file has a space after it, but I can retrieve the short...
8
by: NilsNilsson | last post by:
I wrote this: short s1 = 0; short s2 = 1; short s3 = s1 + s2; And gor this compile error message: Cannot implicitly convert type 'int' to 'short' What is wrong here?
4
by: stefano | last post by:
hi, I want to show some message in a box when the mouse is over a button (examples: undo, save, open, ecc ) like in some interface. I don't want to display the mesage in an alert window. Someone...
2
by: Dino | last post by:
dear all, i got this script form a customer. in general, it recieves data which is send via http to a server and generates a .xml file from this data. because i'm not familar with .asp, i'm...
2
by: windsorben | last post by:
I'd like to have an image appear after the student answers each short answer question correctly. I can't seem to get it to work properly. See code below. Thanks! <html> <head>...
8
by: comp.lang.php | last post by:
I installed WAMP5 on my WinXP box which works just fine on its own, and I found a practical way of handling my short-tag PHP script via .htaccess: php_flag short_open_tag on To ensure my...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.