Re: Strange bahavior with mysql_fetch_array($result)

From: Date: Fri, 21 Nov 2003 02:44:55 +0000
Subject: Re: Strange bahavior with mysql_fetch_array($result)
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-31683@lists.php.net to get a copy of this message
Hi Evan, Try something like this instead: $query = mysql_query("SELECT product_id, product_name, purchase_date from MyTable ORDER BY product_id DESC"); if(!$query) { echo mysql_errno() . ": " . mysql_error() . "\n"; die; } else { //Now, for fun, display the results in a table with the results linked to a product information page print "<table>"; while($row=mysql_fetch_array($query)) { print "<tr>"; print "<td><a href=product_details.php?product_id="$row["product_id"]">" . $row["product_name"] . " " . $row["purchase_date"] . "</a></td>"; print "</tr>"; } print "</table>"; } ?> NOTE: this is not a tested example, and I didn't check it for accuracy. I just threw something together to give you some good ideas of where to go with your code. I strongly urge you to use the manual (php.net) just to browse through the available functions. Good luck! HTH, Kirk "Evan Panagiotopoulos" <epanagio@pcsd.k12.ny.us> wrote in message news:78440-220031152115426406@pcsd.k12.ny.us... > I am searching a table and have the following php code with my > comments: > > $result = mysql_query($query); > print "The result == $result"; > // it returns The result == Resource id #2" > if (!mysql_fetch_array($result)) { > ... > } else { > while ($row = mysql_fetch_array($result)) { > ... > } > } > Neither the if nor the while get executed. > Can you make any suggestions? Obviously I'm new to this. > > Evan

« previous php.db (#31683) next »