Jump to content


Photo

PHP code problem - unexpected T VARIABLE


  • Please log in to reply
4 replies to this topic

#1 Broomy

Broomy
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 18 October 2006 - 10:44 AM

Hi. I have this code that someone wrote for me, but it gives me an error if I try and use it as follows:

Parse error: syntax error, unexpected T_VARIABLE

The line with the error refers to $sql = "

I'm useless at PHP but i'm hoping that someone might be able to point out what the problem might be.

Thanks for any help.

<?php

$currentNodeCreated = $node->created;
$taxonomyTerm = 2 //this should not be hardcoded, it should be pulled from the node details for the current node taxonomy

$sql = "
  SELECT node.title, node.nid 
  FROM {node}, {term_node} 
  WHERE node.nid = term_node.nid 
  AND node.tid = $taxonomyTerm 
  AND node.created < $currentNodeCreated 
  AND node.status = 1 
  ORDER BY node.created DESC 
  LIMIT 1";
$result = db_query($sql);
if($row = db_fetch_result($result) {
  $output .= l($row->title, "node/".$row->nid);
}
?>


#2 chris9902

chris9902
  • Members
  • PipPip
  • Member
  • 14 posts
  • LocationUK

Posted 18 October 2006 - 10:54 AM

the problem line is: "$taxonomyTerm = 2"

you need a ";" after 2

so it should be "$taxonomyTerm = 2;"

#3 Broomy

Broomy
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 18 October 2006 - 11:40 AM

Thanks for the help, I appreciate it. That problem is now fixed but i'm not met with this error:

Parse error: syntax error, unexpected '{' on the line that refers to this:

if($row = db_fetch_result($result) {

Any more help would be great,

Thanks again.

#4 phil88

phil88
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts

Posted 18 October 2006 - 11:49 AM

if($row = db_fetch_result($result) {

Should be;


if($row = db_fetch_result($result)) {

You just missed off a bracket :)

#5 Broomy

Broomy
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 18 October 2006 - 12:13 PM

Ah, i'm good at this!  :-\

Thanks for that.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users