Page 1 of 1

ASP --> PHP

Posted: Fri Sep 02, 2005 12:36 pm
by quadoc
I've the following code in ASP and I want to convert it to PHP but not quite know how. Could someone good with PHP and ASP show me how? Thanks... :?

Code: Select all

<% 
dim tmpcity
dim tmpcity
						
if Request.Form("hidCity") <> "" then
   tmpcity= Request.Form("hidCity")
else
   tmpcity=0
end if 
%>

<SCRIPT LANGUAGE=javascript>

function selcity(obj)
{
document.getElementById("hidCity").value=obj.options[obj.options.selectedIndex].value

   if(document.getElementById("hidCity").value!=0)
   {					
      document.getElementById ("frmcity").submit()
   } 
}
</SCRIPT>
<form name="frmcity" id="frmcity" method="post" action="findapub.asp">
<input type="hidden" name="hidCity" id="hidCity" value="<%= tmpcity%>">
</form>

<form id="frmnew" name="frmnew" method="post" action="publist.asp">

City:-
<%
dim rscity
set rscity = GetRecordSet("SELECT * FROM Cities order by cityname")
%>
<select name="dropbox3" ID="SelectCity" onchange="javascript:selcity(this)">
<option value="">Select a City</option>
   <%while not rscity.EOF %>
      <option value="<%= rscity("cityid")%>" <%if cint(tmpcity) = cint(rscity("cityid")) then%> selected <%end if%>><%= rscity("cityname")%>
      </option>
   <%rscity.movenext : wend%>
</select>

Area-
<%
dim rsarea
set rsarea = GetRecordSet("SELECT Areas.areaid, Areas.City, Areas.Area FROM Areas WHERE Areas.City=" & tmpcity)
%>

<select NAME="dropbox">
   <option value="Area0">Any</option>
   <%while not rsarea.eof%>
         <option value="<%= rsarea("areaid")%>"><%= rsarea("Area")%></option>
   <%rsarea.movenext : wend%>
</select>

Posted: Fri Sep 02, 2005 12:51 pm
by timvw
You might want to show the part where you have trouble.. because it seems pretty trivial do "translate"..

http://phplens.com/phpeverywhere/node/view/30 gives a nice side-by-side introduction ;)

Posted: Fri Sep 02, 2005 1:00 pm
by feyd
here's a start

Code: Select all

<?php

$tmpcity = (empty($_POST['hidCity']) ? '' : $_POST['hidCity']);

?>
<SCRIPT LANGUAGE=javascript>

function selcity(obj)
{
document.getElementById("hidCity").value=obj.options[obj.options.selectedIndex].value

   if(document.getElementById("hidCity").value!=0)
   {                    
      document.getElementById ("frmcity").submit()
   }
}
</SCRIPT>
<form name="frmcity" id="frmcity" method="post" action="findapub.asp">
<input type="hidden" name="hidCity" id="hidCity" value="<%= tmpcity%>">
</form>

<form id="frmnew" name="frmnew" method="post" action="publist.asp">

City:-
<?php

$rscity = mysql_query('SELECT * FROM Cities order by cityname') or die(mysql_error());

?>
<select name="dropbox3" ID="SelectCity" onchange="javascript:selcity(this)">
<option value="">Select a City</option>
<?php
while($row = mysql_fetch_assoc($rscity))
{
  echo '      <option value="'.$row['cityid'].'" '.(intval($tmpcity) == intval($row['cityid']) ? 'selected' : '').'>'.$row['cityname'].'</option>'."\n";
}
?>
</select>
you can figure out from that the rest ;)

Posted: Fri Sep 02, 2005 7:14 pm
by quadoc
Thanks a lot for the quick tips guys. I'll give it a try... :D