Re: ASP to PHP language problems
| From: | Alistair Hayward | Date: | Wed, 10 Mar 2004 23:08:55 +0000 |
| Subject: | Re: ASP to PHP language problems | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-180064@lists.php.net to get a copy of this message | ||
Richard:
Thank you so much!
Richard Davey wrote:
Hello Alistair, Wednesday, March 10, 2004, 10:26:03 PM, you wrote: AH> dim Type AH> Type = CStr(Request.QueryString("action")) (getting parameter from URL) unset($type); $type = $_GET['action']; (Please note - you don't HAVE to "unset" each variable, but if you are working in a Register Globals ON environment, it's a good safety measure). AH> strDBPath = Server.MapPath("/_database/database.mdb") MySQL doesn't work the same way as MDB files (thank goodness), so you need to create a connection to the MySQL database: $link = mysql_connect('localhost', 'username', 'password'); AH> Set cnn = Server.CreateObject("ADODB.Connection") AH> cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";" mysql_select_db('database_name', $link); AH> Set rst = cnn.Execute("SELECT * FROM table WHERE Type ='" & type & "' AH> order by style") $sql= "SELECT * FROM table WHERE type='$type' ORDER BY style"; $result = mysql_query($sql); You now have the entire "record set" in $result. To obtain the first row of data, do this: AH> <%Do While Not rstSimple.EOF%> AH> do something AH> <% AH> rstSimple.MoveNext AH> Loop A few ways to do this: $total_records = mysql_num_rows($result); for ($i=0; $i < $total_records; $i++) {$data = mysql_fetch_assoc($result); print_r($data);} $data will now be an array holding the first set of information. The print_r line just displays it so you can see it easily. Instead of a FOR loop you could do a "while" loop checking to see the end of the $result set, i.e.: while ($row = mysql_fetch_array($result, MYSQL_NUM)) {// do stuff print_r($row);} AH> <%=rst.fields("whatever").value%> <?=$data['whatever']?>