473,396 Members | 2,057 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Retrieve php content from mysql

Hi,

I am relatively new to php however I am working on a site and appear to be
getting on quite well. Most of my pages are coded in php and work fine
however what I would like to do is be able to retrieve my content from a
mysql database. The set up is as follows:

Database contains several fields, but for this example I will only require
the Page Name and the Content fields. In page name I have the page name
i.e. whatson.php and I then have the entire contents of the page that I
worked on in my editor pasted in to the Content field.

I then create a basic php page that makes a connection to the database and
just searches for the page I want i.e. whatson.php and stores the result in
a variable called result.

I then echo out result but for some reason it just displays the php code and
does not appear to have interpreted it, can anyone help?. Sample code is
below:

<?php
// Create connection to database
$db = mysql_connect("localhost", "username","password") or die("Could not
connect : " . mysql_error());
mysql_select_db("myweb",$db);
$sql = "SELECT Content FROM pages WHERE PageName = 'whatson.php'" ;
$sql_result = mysql_query($sql,$db) or die("Couldn't execute query, please
notify webmaster.");
$result = mysql_query($sql);

//Main loop below which draws the screen
while ($row = mysql_fetch_array($sql_result)) {
echo $row[0]
}
?>
I am new to php so be nice :)

Thanks in advance

Rigga
Jul 17 '05 #1
2 2409
.oO(RiGGa)
Database contains several fields, but for this example I will only require
the Page Name and the Content fields. In page name I have the page name
i.e. whatson.php and I then have the entire contents of the page that I
worked on in my editor pasted in to the Content field.

I then create a basic php page that makes a connection to the database and
just searches for the page I want i.e. whatson.php and stores the result in
a variable called result.

I then echo out result but for some reason it just displays the php code and
does not appear to have interpreted it, can anyone help?.


You're looking for eval().

Micha
Jul 17 '05 #2
Michael Fesser wrote:
.oO(RiGGa)
Database contains several fields, but for this example I will only require
the Page Name and the Content fields. In page name I have the page name
i.e. whatson.php and I then have the entire contents of the page that I
worked on in my editor pasted in to the Content field.

I then create a basic php page that makes a connection to the database and
just searches for the page I want i.e. whatson.php and stores the result
in a variable called result.

I then echo out result but for some reason it just displays the php code
and does not appear to have interpreted it, can anyone help?.


You're looking for eval().

Micha

Thank you, it now works!

regards

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: theonlydrayk | last post by:
the script that show image is : <?php include('dbinfo.inc.php'); mysql_connect($localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query =...
16
by: Daniel Tonks | last post by:
First, please excuse the fact that I'm a complete MySQL newbie. My site used forum software that I wrote myself (in Perl) which, up until now, has used flat files. This worked fine, however...
5
by: Roy Gourgi | last post by:
Hi, I am used to working in Visual FoxPro and I would like to be able to create a database and store and retrieve information from it. What is the simplest way to do it and what should I be...
13
by: no.mail.pls | last post by:
Hiya, How do i retreive fields with similar values from 2 tables? I tried to use (1) "SELECT * FROM $table1 as o , $table2 as p WHERE o.name like '%p.name%'"; but it retrieves nothing at...
2
by: webmechanic | last post by:
I was able to insert images into mysql stored as binary data. How do I retrieve it. Please provide thorough explanation. Thanks.
3
by: bazubwabo | last post by:
hi everybody , could u please help me to find out the error on my asp codes,i can't retrieve the inserted values. Here is below the code: <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <!DOCTYPE...
3
by: JM | last post by:
Before storing information from a form in database I perform follwing operations on it : $path = mysql_real_escape_string(strip_tags(trim(urldecode($_POST)))); $summary =...
3
by: alexseow | last post by:
<img src="image.asp?id=1"> --------------------------------------------------------------- <%Option Explicit%> <!-- #include file="IMS/includes/dbconn.asp"--> <% dim MyConn,SQL Set MyConn...
12
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I am a newbie to Struts and JSP...I have been working on the code below for 5 hours now..I googled a lot but couldn't get much help so finally I am here.. Hoping of getting my problem solved. Please...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.