Jump to content

[SOLVED] Querying MySQL database using WHERE condition


kylew00f

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.