Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Adding Vars To A Sql
sparkx
post Jun 17 2007, 02:58 AM
Post #1


Sparkx
Group Icon

Group: [HOSTED]
Posts: 355
Joined: 11-October 06
From: Dana Point, CA, USA
Member No.: 16,496



Well I have been recieving some real good help here at astahost so I decited I just won't even try Yahoo Answers first. OK this is halfway between php and mysql. I want to echo text from MySQL that includes vars. Here is an example:
MySQL Entry
CODE
This is some sql entry. $var

I tryied:
CODE
$var=("It worked");
$row = mysql_fetch_array(mysql_query("SELECT * FROM example WHERE id='5'"));
$output=$row['content'];
echo($output);//Doesnt work
echo<<<END
$output
END;//Still doesnt work

My wanted outcome:
CODE
This is some sql entry. It worked

Do you understand what I am saying? Im sorry but I think I stated the question well.
 Thank you all very much for all the help,
Sparkx
Go to the top of the page
 
+Quote Post
pyost
post Jun 17 2007, 09:46 AM
Post #2


Nenad Bozidarevic
Group Icon

Group: [MODERATOR]
Posts: 1,013
Joined: 7-November 05
From: Belgrade, Serbia
Member No.: 9,500



With just some minor modifications, it should work. Here's how I would do it.

CODE
$var = 'It worked';
$row = mysql_fetch_array(mysql_query('SELECT * FROM example WHERE id=5'));
$output = $row['content'] . $var;
echo $output;


1. No parenthesis
2. If the ID field is numerical, there is no need for quotes
3. Besides the data extracted from the database, we need to output the variable, too
4. Again, no parenthesis

I've also used single quotes instead of double quotes - both are possible, but it's just a habit smile.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Adding A Windows Media Player(0)
  2. Adding Ttf Fonts To Your Linux(0)
  3. Fedora 3: Trying To Setup Ftp/http Server(2)
  4. How To Add A Film Edge To Your Photos(1)
  5. Adding Comma To End Of Line & Concatenating Lines(4)
  6. Photoshop Tutorial: Adding Color To Black And White Photo(6)
  7. Photoshop Tutorial: Adding Color That Wasn't There(4)
  8. Adding East Asian Fonts To Your System(4)
  9. Adding More IDE Ports In Computer(17)
  10. Adding Search Feature To My Site(0)
  11. Adding Static Content To Website...(9)
  12. Need Help Is Adding A PHP Based News Module To My Site(2)
  13. Need Help With Adding Nvidia Drivers In Debian(3)
  14. Need Help adding music to a webpage(9)
  15. Add A Forum To Your Site(23)
  1. Help: Adding My Videos Folder To Start Menu(10)
  2. Friend Networking Script... Help!(1)
  3. Adding Google Adsense(6)
  4. Php Question Re Adding A Link(2)
  5. Php :: Adding Image Over Image(5)
  6. How To Add Spf Records For My Domain(0)
  7. Adding Subdomains With cPanel(6)
  8. Adding Security Enhancements To Php Programs(0)
  9. Problems Dynamically Adding A Table With Dom(4)
  10. Adding Element To Page Issues(0)


 



- Lo-Fi Version Time is now: 14th October 2008 - 01:37 AM