Hi,
I have set up an environment on my Vista laptop comprising of Apache 2.2,
MySQL Server 5.1 and Php 5.2.5.
I'm using a simple php program that I found in a PHP/SQL book. The PHP
program queries a MySQL table and uses a WHILE loop to traverse the results
array of the query and display on screen. However, there seems to be a
problem with my environment and using a WHILE loop as every time I run the
program I get the error "*Apache HTTP server stopped working and was closed*
".
I have no problems using a FOR loop but every time I use a WHILE loop Apache
seems to crash. Please see below for the code I have used.
I would be extremely for any suggestions of why this is happening and any
solutions offered.
Thanks.
> *<?php
> /* Program: petDisplay.php
> * Desc: Displays all pets in selected category.
> */
> ?>
> <html>
> <head><title>Pet Catalog</title></head>
> <body>
> <?php
>
> $user="root";
> $host="localhost";
> $password="PASSWORD";
> $database = "am";
> $cxn = mysqli_connect($host,$user,$password,$database)
> or die ("couldn't connect to server");
> $pettype = "horse"; //horse was typed in a form by user
> $query = "SELECT * FROM Pet WHERE petType='$pettype'";
> $result = mysqli_query($cxn,$query)
> or die ("Couldn't execute query.");
>
> /*Display results in a table */
> $pettype = ucfirst($pettype)."s";
>
> echo "<h1>$pettype</h1>";
> echo "<table cellspacing='15'>";
> echo "<tr><td colspan='3'><hr /></td></tr>";
> while($row = mysqli_fetch_assoc($result))
> {
> extract($row);
>
> $f_price = number_format($price,2);
> echo "<tr>\n
> <td>$petName</td>\n
> <td>$petDescription</td>\n
> <td style='text-align: right'>\$$f_price</td>\n
> </tr>\n";
> echo "<tr><td colspan='3'><hr /></td></tr>\n";
> }
> echo "</table>\n";
> ?>
> </body></html>
> *