nubble Posted October 10, 2006 Share Posted October 10, 2006 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 Link to comment https://forums.phpfreaks.com/topic/23548-newbie-question/ Share on other sites More sharing options...
matte Posted October 10, 2006 Share Posted October 10, 2006 what is the syntax error you get? Link to comment https://forums.phpfreaks.com/topic/23548-newbie-question/#findComment-106873 Share on other sites More sharing options...
HuggieBear Posted October 10, 2006 Share Posted October 10, 2006 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]RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/23548-newbie-question/#findComment-106914 Share on other sites More sharing options...
nubble Posted October 10, 2006 Author Share Posted October 10, 2006 Huggie - You rule so much.... so friggin much.... ;D Link to comment https://forums.phpfreaks.com/topic/23548-newbie-question/#findComment-106941 Share on other sites More sharing options...
HuggieBear Posted October 10, 2006 Share Posted October 10, 2006 Glad to have been of assistance ;)Huggie Link to comment https://forums.phpfreaks.com/topic/23548-newbie-question/#findComment-106944 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.