I鈥檝e learned building a guestbook script using Apache, PHP and Mysql
I build a guestbook script and successfully鈥?after submitting it will send the data to the mysql database.
Name: _________________
Location: ___________________
Email: ______________________
Message: ____________________
But how can I get from MYSQL Database and display it on HTML File.
If I browse the MYSQL Directory鈥? The format of the database is guest.myi and guest.frm inside the phpguest folder.
Sample format of desired html
Name Location Email Message
TonyPhilippines Tony@xxxx.com Hello
IlonahNew York Il@yyy.net Hi, How are You
Can someone give me the source code on the output getting from the a certain database with a format guest.myi and guest.frm
Thank you鈥?
I鈥檝e learned building a guestbook script using Apache, PHP and Mysql... Please send me sample script?
Well, I'll assume certain things:
1. You know how to connect to the database, as you can connect to it to save the data.
2. The data is stored in a table named "guestbook" and the fields are: "name", "location", "email" and "message".
3. You don't need pagination (show the results in more than one page). If you need to, post another question and I'll answer it.
$results = mysql_query("SELECT * FROM guestbook ORDER BY name"); //you can order by whatever you want
while ($result = mysql_fetch_array($results))
{
echo "%26lt;b%26gt;Name:%26lt;/b%26gt; ".$result["name"]."
";
echo "%26lt;b%26gt;Location:%26lt;/b%26gt; ".$result["location"]."
";
echo "%26lt;b%26gt;Email:%26lt;/b%26gt; ".$result["email"]."
";
echo "%26lt;b%26gt;Message:%26lt;/b%26gt; ".$result["message"]."
";
}
The way these results are shown can be different. That is something you can format with HTML (see http://www.htmlquick.com ). The values are stored in the $result["what"] variables.
Reply:$connection = mysql_connect($dbhost, $dbuser, $dbpass) ;
mysql_select_db($dbname) ;
$resultset=mysql_query("select name,emailid,msg from guestbook");
print "%26lt;table%26gt;";
while($row = mysql_fetch_array($resultset, MYSQL_ASSOC)){
print "%26lt;tr%26gt;%26lt;td%26gt;".$row['name']." %26lt;/td%26gt;".
"%26lt;td%26gt; ".$row['emailid']. "%26lt;/td%26gt;".
"%26lt;td%26gt; ". $row['msg']." %26lt;/td%26gt;%26lt;/tr%26gt;";
}
print "%26lt;/table%26gt;";
optionally use limit start,no to list nos in pages as
select name,emailid,msg from guestbook order by name limit $start,10
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment