Jump to content

Archived

This topic is now archived and is closed to further replies.

nubble

Newbie question

Recommended Posts

Can't figure out the darn syntax on this... maybe I'm trying to do something that's not possible?  I have a field for snakeID, which is how I identify one critter from another.  I want the page to display just records for that snake on the page, in this case the snakeID is BM05J10.  I can get it to work when I format the query like this:

$sql = "select `snakeID`, `date`, `weight` from `weights` where `snakeID` like 'BM05J10' ORDER BY date DESC";

So what I'd like to do is do is be able to define the snakeID I'm working on in one variable at the top of the page, so I don't have to re-write the code for every critter.

<?php $critter="BM05J10"; ?>
<html>
<head>

When I try to put these two concepts together, I get a syntax error.  I know the problem is in this line of code, but can't figure out what's wrong with it.

$sql = "select `snakeID`, `date`, `weight` from `weights` where `snakeID` like '".$critter."' ORDER BY date DESC";

When I use this, I get no records at all.

I'm sure its something dumb - newbie stuff :(

-Amy

Share this post


Link to post
Share on other sites
Hi Amy,

Don't worry about escaping simple variables in a double quoted string... Use this:

[code]
$critter = "BM05J10";
$sql = "SELECT `snakeID`, `date`, `weight` FROM `weights` WHERE `snakeID` LIKE '$critter' ORDER BY date DESC";
[/code]

Regards
Huggie

Share this post


Link to post
Share on other sites
Huggie - You rule so much.... so friggin much....  ;D

Share this post


Link to post
Share on other sites

×

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.