ASP to PHP language trouble...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alistair

    ASP to PHP language trouble...

    Hi there,

    New to PHP. I have always used ASP.
    I am having trouble trying to do the things in PHP the way (or
    similar) i did it in ASP.
    In ASP I used an Access database. I now use a mySQL database.

    I have been able to establish a connection.
    I have figured out how to use include files.

    What I need to know is this:

    I want to create a recordset (?resultset) using a query.
    in ASP I did it like this:
    ............... ............... ............... ....
    <asp code.....

    Dim cnn ' ADO connection
    Dim rst ' ADO recordset
    Dim strDBPath ' path to my Access database (*.mdb) file
    Dim Type ' variable
    Type = CStr(Request.Qu eryString("type ")) 'passing parrameter from URL

    strDBPath = Server.MapPath( "/_database/data.mdb")
    Set cnn = Server.CreateOb ject("ADODB.Con nection")
    cnn.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & strDBPath &
    ";"
    Set rst = cnn.Execute("SE LECT * FROM table WHERE Type ='" & type & ")
    ............... ............... ............... ............... .......
    At this point, I can call any field from my recordset in the html code
    on the page by inserting something like <%=rst.Fields(" whatever
    field").Value%> .
    I could also do a loop by using:
    <%Do While Not rst.EOF%>
    do some stuff......
    <% rstSimple.MoveN ext
    Loop
    %>
    ............... ............... ............... ............... ........

    So, please can you help me by showing the equavilant PHP code for
    this.
    1. How to create a recordset using a query.
    2. Inserting results of the recordset into the html code
    3. Creating a loop.

    Alistair
  • Geoff Berrow

    #2
    Re: ASP to PHP language trouble...

    I noticed that Message-ID:
    <8f744ea8.04031 01409.3a8de05@p osting.google.c om> from Alistair contained
    the following:
    [color=blue]
    >So, please can you help me by showing the equavilant PHP code for
    >this.
    >1. How to create a recordset using a query.
    >2. Inserting results of the recordset into the html code
    >3. Creating a loop.[/color]


    Well it's much easier than ASP

    //connect to db
    $db = mysql_connect(" host", "username", "password")
    mysql_select_db ("database_name ",$db);

    //query db
    $sql="SELECT * from table WHERE somecondition ";
    $result = mysql_query($sq l);

    //loop through results
    while ($myrow = mysql_fetch_arr ay($result)) {
    print $myrow['field1']."<br>";
    print $myrow['field2']."<br>";
    print $myrow['fieldn']."<br>";
    }

    You'll probably want to add error checking, but in a nutshell, that's
    it.

    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    • R. Rajesh Jeba Anbiah

      #3
      Re: ASP to PHP language trouble...

      alistairhay@yah oo.com (Alistair) wrote in message news:<8f744ea8. 0403101409.3a8d e05@posting.goo gle.com>...[color=blue]
      > Hi there,
      >
      > New to PHP. I have always used ASP.
      > I am having trouble trying to do the things in PHP the way (or
      > similar) i did it in ASP.
      > In ASP I used an Access database. I now use a mySQL database.[/color]

      You may be interested in <http://asp2php.naken.c c/>

      --
      "I don't believe in the God who doesn't give me food, but shows me
      heaven!"--Swami Vivekanandha
      Email: rrjanbiah-at-Y!com

      Comment

      Working...