Forums
This topic is locked
Converting Asp.Net Code To PHP
Posted 07 Sep 2006 18:20:51
1
has voted
07 Sep 2006 18:20:51 Fouad Akhtar posted:
i need to convert this while statement to php, its seems very simple to me in asp.net but in php i have no idea since i am new
i hope i will get help soon
Dim myconn As New ADODB.Connection()
Dim myrs As New ADODB.Recordset()
Dim mySQL As String
Dim myrows As Long
Dim DeptID As Integer
mySQL = "select max(deptid) as Max from Dept"
myrs.Open(mySQL, myconn)
myrows = myrs.RecordCount
While Not myrs.EOF
If IsDBNull(myrs("Max".Value) Then
DeptID = 1
Else
DeptID = myrs("Max".Value + 1
End If
myrs.MoveNext()
End While
myrs.Close()
Thanks in Advance
Replies
Replied 08 Sep 2006 10:13:21
08 Sep 2006 10:13:21 Patrick Woldberg replied:
A quick translation to php would result in:
<pre id=code><font face=courier size=2 id=code>$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
or die('Could not connect: ' . mysql_error());
mysql_select_db('my_database') or die('Could not select database');
// Performing SQL query
$query = 'select max(deptid) as Max from Dept';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
if ($line['Max'] == null) {
$DeptID = 1;
} else {
$DeptID = $line['Max'] + 1;
}
}
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);</font id=code></pre id=code>
Haven't tested
--------------------------------------------------
Patrick Woldberg
Web Developer at Dynamic Zones
Administrator at DMXzone.com, FLzone.net, FWzone.net and DNzone.com
--------------------------------------------------
<pre id=code><font face=courier size=2 id=code>$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
or die('Could not connect: ' . mysql_error());
mysql_select_db('my_database') or die('Could not select database');
// Performing SQL query
$query = 'select max(deptid) as Max from Dept';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
if ($line['Max'] == null) {
$DeptID = 1;
} else {
$DeptID = $line['Max'] + 1;
}
}
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);</font id=code></pre id=code>
Haven't tested
--------------------------------------------------
Patrick Woldberg
Web Developer at Dynamic Zones
Administrator at DMXzone.com, FLzone.net, FWzone.net and DNzone.com
--------------------------------------------------
Replied 08 Sep 2006 18:47:03
08 Sep 2006 18:47:03 Fouad Akhtar replied:
i really appreciate your help,
the problem is fixed