0

Is there anything wrong in this scenario? the result isn't showing. maybe i'm getting the syntax wrong?

    // fetch the latest tweet
$lastTweet = '';
$q2 = "SELECT tweet FROM timel ORDER BY id DESC LIMIT 1";
list($lastTweet) = $conn->get_results($q2);



if(!$lastTweet){  
$lastTweet = "You don't have any tweets yet!";
}
var_dump($lastTweet);

and this on the html body:

<span class="latest"><strong>Latest: </strong><span id="lastTweet"><?.=$lastTweet?></span></span>
6
  • <?.=$lastTweet this dot? Commented Feb 20, 2013 at 21:11
  • By <?.= do you mean <?= ? Commented Feb 20, 2013 at 21:11
  • In <?.=$lastTweet?>, you have a . between ? and =. Remove it. Commented Feb 20, 2013 at 21:14
  • Didn't you forget to execute your query before getting the result? Commented Feb 20, 2013 at 21:17
  • to all: removing the dot still doesn't work though. maybe there is a another way to do this? peterm: the results are fine since i am using a class for executing queries. it works, just that i can't display the results on the html body. assuming i have no tweets yet. Commented Feb 20, 2013 at 21:21

2 Answers 2

2

If you changed your first line to

$lastTweet = array();

And your third line to

$lastTweet = $conn->get_results($q2);

Then you would be able to use

<?php var_dump($lastTweet); ?>

But in your case lastTweet contains a string of text, hence you need to use echo to print it's content.

<?php echo $lastTweet ?>

Nb: i'm not sure about your project details but i'm guessing you'd need to also get the date, maybe id and user_id of the tweet, if that's the case, you might want to make lastTweet an empty array()

Sign up to request clarification or add additional context in comments.

Comments

1

Use this:

<span class="latest"><strong>Latest: </strong><span id="lastTweet">
<?php echo $lastTweet; ?></span>    </span>

Saludos ;)

1 Comment

okidoki. this did the trick! hmmm. so i still do have to use $echo function. thanks a bunch, Robert Rozas. and thank you for the replies, everyone. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.