Skor Posted October 11, 2006 Share Posted October 11, 2006 ???Yes, I'm a newbie. Trying to teach myself PHP. Ran into a roadblock yesterday.I've been pouring over various books and web docs to to use the _get along with a database query. The best I can get is the column names to appear. I have a very similar query on another page that works just fine, the addition of the $_get is throwing it off. My goal is to create dynamic pages based on the prodID. Looking to see where I veered off.<?php$host="localhost";$user="user";$password="pw";$db_name ="products";$db_table="table";//check connection to dbmysql_connect($host, $user, $password) or die ("Unable to connect to server");mysql_select_db($db_name)or die ("Couldn't retrieve database information");$Prodid = $_GET['Prodid'];print($Prodid); //to make sure you're getting what you wanted$query = "SELECT Prodid, Name, Category, Price FROM testdb WHERE Prodid = '".$_GET['Prodid']."' AND Status = 'A'";$result = mysql_query($query) or die('Query failed: ' . mysql_error());?><table border ="2"><?phpecho '<tr><td>Prodid</td><td>Name</td><td>Category</td><td>Price</td></tr>';$cols = mysql_num_fields( $result );while ($row = mysql_fetch_array($result)) {echo "<tr>";echo "<td>".$row['Item_no']."</td>";echo "<td>".$row['Name']."</td>";echo "<td>".$row['Category']."</td>";echo "<td>".$row['Price']."</td>";echo "</tr>";}?></table>This results in the following being displayed: netted in a table with only labels being displayed.<table border ="2"><tr><td>Prodid</td><td>Name</td><td>Category</td><td>Price</td></tr></table>Thanks in advance, I'm baffled. Quote Link to comment Share on other sites More sharing options...
hostfreak Posted October 11, 2006 Share Posted October 11, 2006 Give this a try:[code]<?php$host="localhost";$user="user";$password="pw";$db_name ="products";$db_table="table";//check connection to dbmysql_connect($host, $user, $password)or die ("Unable to connect to server");mysql_select_db($db_name)or die ("Couldn't retrieve database information");$Prodid = $_GET['Prodid'];print($Prodid); //to make sure you're getting what you wanted$query = "SELECT Prodid, Name, Category, Price FROM testdb WHERE Prodid = '$Prodid' AND Status = 'A'";$result = mysql_query($query) or die('Query failed: ' . mysql_error());?><table border ="2"> <tr> <td>Prodid</td> <td>Name</td> <td>Category</td> <td>Price</td> </tr><?php$cols = mysql_num_fields( $result );while ($row = mysql_fetch_array($result)) { $Item_no = $row['Item_no']; $Name = $row['name']; $Category = $row['Category']; $Price = $row['Price']; echo "<tr>"; echo "<td>$Item_no</td>"; echo "<td>$Name</td>"; echo "<td>$Category</td>"; echo "<td>$price</td>"; echo "</tr>";}?></table>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.