kylew00f Posted September 12, 2007 Share Posted September 12, 2007 Hello, I am using MySQL Server version: 4.0.16 This is the SQL code in my php script: SELECT * FROM item_details WHERE model=$id I am trying to get information from a row for when the column "model" equals a variable. The database, table, row, & column do exist. I assume my WHERE syntax is incorrect since I have been able to display information from rows when using SELECT * FROM tablename before. below is the complete script and the output i get <?php include "../php/item_login.php"; //connects to database server & selects database// if ($connection=1) { echo "connected to database.......<br><br>"; } $id=$_GET['id']; $sql = ("SELECT * FROM item_details WHERE model=$id"); $result = mysql_query($sql); $row = mysql_fetch_row($result); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print"; } ?> <br><br><br> model#: <? echo $id; ?><br> height: <? echo $row[2]; ?> http://www.site.com/item.php?item=10-10 this is the output displayed on the page connected to database....... No rows found, nothing to print model#: 10-10 height: this is the output i want connected to database....... model#: 10-10 height: 10 any help would be appreciated. thank you Quote Link to comment Share on other sites More sharing options...
Azu Posted September 12, 2007 Share Posted September 12, 2007 Try replacing the "SELECT * FROM item_details WHERE model=$id" with "SELECT * FROM item_details WHERE model" and see what happens. It SHOULD select everything. If it doesn't select anything or if it gives an error, then there probably isn't a column called "model" and that's the problem. Quote Link to comment Share on other sites More sharing options...
Illusion Posted September 12, 2007 Share Posted September 12, 2007 that might be due to the php varible is not interpreted. try this $sql = ("SELECT * FROM item_details WHERE model='$id' "); Quote Link to comment Share on other sites More sharing options...
kylew00f Posted September 12, 2007 Author Share Posted September 12, 2007 Thank you, Mr. Illusion. Problem solved 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.