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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vohyndra
Forum Newbie
Posts: 2
Joined: Tue May 13, 2008 9:24 am

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

Post 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
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

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

Post 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
Post Reply