Page 1 of 1

New in php, help how to translate from ASP to PHP

Posted: Tue May 13, 2008 9:26 am
by vohyndra
Hello there i need help.
im new with php and i would like to tranlate this code from ASp to PHP

<%
x=1
while (not lBE.Eof)

response.Write "&local"&x&"=" & (lBE.Fields.Item("local").Value) & "&disponible"&x&"=" &(lBE.Fields.Item("disponible").Value) &"&dimension"&x&"=" &(lBE.Fields.Item("dimension").Value)&"&ubicacion"&x&"=" &(lBE.Fields.Item("ubicacion").Value)&"&colinda"&x&"=" &(lBE.Fields.Item("colinda").Value)& "&imagen"&x&"=" &(lBE.Fields.Item("imagen").Value)&"<br>"

lBE.MoveNext
x=x+10
wend
%>


THANKS

Re: New in php, help how to translate from ASP to PHP

Posted: Tue May 13, 2008 11:34 am
by califdon
vohyndra wrote:Hello there i need help.
im new with php and i would like to tranlate this code from ASp to PHP

<%
x=1
while (not lBE.Eof)

response.Write "&local"&x&"=" & (lBE.Fields.Item("local").Value) & "&disponible"&x&"=" &(lBE.Fields.Item("disponible").Value) &"&dimension"&x&"=" &(lBE.Fields.Item("dimension").Value)&"&ubicacion"&x&"=" &(lBE.Fields.Item("ubicacion").Value)&"&colinda"&x&"=" &(lBE.Fields.Item("colinda").Value)& "&imagen"&x&"=" &(lBE.Fields.Item("imagen").Value)&"<br>"

lBE.MoveNext
x=x+10
wend
%>


THANKS
It would be somewhat like this:

Code: Select all

<?php
mysql_connect([host],[user],[password]) or die(mysql_error());
mysql_select_db([database name]) or die(mysql_error());
$sql="SELECT * FROM .....";
$result=mysql_query($sql) or die(mysql_error());
 
while($row=mysql_fetch_assoc($result)) {
   extract($row);
   echo "local=$local disponible=$disponible ";
   echo "ubicacion=$ubicacion colinda=$colinda imagen=$imagen<br>";
}
?>
I included the database connect syntax and the SQL string, since it is integral to the code that follows. I omitted the x variable, since it apparently didn't do anything in the code that you showed.

Aside from connecting to the database, some of the key syntactical differences include:
  1. every PHP variable begins with a $
  2. every PHP statement ends with a ;
  3. echo is equivalent to response.write
  4. mysql_fetch_assoc() gets the next row and advances the pointer
  5. extract() assigns field values to variables named like the fields
  6. $variables are parsed when enclosed in double quotes