PHPLeader Posted August 14, 2011 Share Posted August 14, 2011 I have a MySQL Database set up. I have tested it, and I have been able to access my database, table and row successfully. I have a banner at the top of my page, which is a DIV. Its ID is "Banner". I would like it to insert the result into the DIV. The code I have echo's the result, but I want it to insert the result into the DIV. Here is my code: <?php // Make a MySQL Connection mysql_connect("localhost", "*****", "*****") or die(mysql_error()); // Yes its stared out, but the real code has got correct info mysql_select_db("mastermovies_co") or die(mysql_error()); // Retrieve all the data from the "example" table $result = mysql_query("SELECT * FROM note") or die(mysql_error()); // store the record of the "example" table into $row $row = mysql_fetch_array( $result ); // Print out the contents of the entry echo "".$row['text'] ?> What would I change the echo to? And also, where do I put the PHP code? Head? Body? Im quite new to PHP, as I prefer Javascript, but in this case I had to learn some PHP and MySQL. Quote Link to comment https://forums.phpfreaks.com/topic/244766-insert-text-from-mysql-into-an-object/ Share on other sites More sharing options...
doomdude Posted August 14, 2011 Share Posted August 14, 2011 Put your php at the top of your page. Also try: <div id="banner"> <?php echo "".$row['text'] ?> </div> As longas your php code is before you call the echo it should work. Quote Link to comment https://forums.phpfreaks.com/topic/244766-insert-text-from-mysql-into-an-object/#findComment-1257199 Share on other sites More sharing options...
voip03 Posted August 14, 2011 Share Posted August 14, 2011 you code should be top of the page <div id= "Banner"> <? echo "".$row['text']; ?> </div> Quote Link to comment https://forums.phpfreaks.com/topic/244766-insert-text-from-mysql-into-an-object/#findComment-1257200 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.