Hiya

I know its a simple question and you're all probably rolling in the aisles, but I have looked EVERYWHERE. It seems everyone does it differently. I didnt want to have a count and keep incrementing and counting, i just wanted a simple while.. do loop like I would use in ASP. Such as:

while not recordset.eof do
blahblahblahbab
recordset.movenext
loop

Is there an equivalent to this in PHP, using a Mysql db? I have about 3 textbooks here, and the whole internet, and I still cant manage to find what I'm looking for. Id like it to be nice and simple 🙁

Thanks
bella.

    Remember also than when you use ASP you are using an object that is instantiated from a class (“ADODB.Recordset”) and has properties and methods built in for you to use.

    PHP is a bit different and you have to think about it a little different. You do not have the benefit of an ADO like object and must use functions to extract the query results as associative or numeric arrays. Read up on MySql functions, those links that Steve Yelvington posted will provide all you need to know.

    You’ll end up with something like:

    while($myRecords = mysql_fetch_array($result)){
    blaBlaBlaBla
    }

      Thank you 🙂
      I'll have a look at these links.

        Basically if you want to list results from a query you do this:

        <?php
        // establish connection
        $link = mysql_connect("localhost","username","password");
        // select database
        mysql_select_db("daname",$link);
        // query datbase
        $result = mysql_query("SELECT * FROM table",$link);
        // loop through result set
        while($row = mysql_fetch_array($result))
        {
        // print a field from the row
        // the row is held in an array
        print $row[fieldname];
        }
        // close connection
        mysql_close($link);
        ?>

          Write a Reply...