Search code examples
phpdatabaseloopsrecordset

php: iterate recordset - easier way?


i've just changed from ASP to php and i'm a bit confused about the way php is handling recordsets. i'd like to know if there's an easier way to iterate a recordset by creating a php class. here's the ASP syntax to show what i mean:

sq = "select * from myData"
set rs = db.execute(sq)
do while not rs.eof
    response.write rs("name")  // output data (response.write = echo)
    rs.movenext
loop

any ideas? thanks


Solution

  • You'd pretty much do the same thing...

    $sql = "select * from myData";
    $result = mysql_query($sql) or die(mysql_error()); //executes query
    while($row = mysql_fetch_array($result)){ //will automatically return false when out of records
        echo $row['name'];
    }