Jump to content

[SOLVED] Creating Dynamic PHP Pages from a MySQL Database


Gates_of_Janus

Recommended Posts

I’ve only worked with basic PHP tricks up to this point and have only just begun to try to add the MySQL element so I’m no doubt missing something obscenely straightforward. I’m in the process of converting a large, previously fully HTML site to PHP/MySQL so that I can stop working with a million and one separate HTML pages and have a dynamic page set up. I know what I want to do and I know it’s one of the main reasons people use the PHP/MySQL combo, but I’m no less at a loss as to how to proceed.

 

Basically I want to create pages such as this:

http://www.dreamravendesigns.com/hellmouth_alliance/Jude.html

 

But in PHP and have the Name, Age, ect. field information be referenced from a MySQL database that contains all the info for all the characters rather than building a separate HTML page for each one. I know how to create the database, what I don’t know is how to get the information from the database to be dynamically displayed into a PHP template – such as you would with a product page in an online catalog.

 

If someone could assist in pointing me in the right direction it would be immensely appreciated.

 

Thanks,

Amanda

Link to comment
Share on other sites

Hi..

        For that you have to embed code and write coding in php with mysql function and getting all records

and you have to echo/print those one's..

 

        you can use this page as template and in that you can go ahead with php,mysql interaction for data fetching and displaying..

 

Regards,

Vijay

Link to comment
Share on other sites

Hello Vijay,

 

Thank you very much for your reply. I'm familiar with printing data from MySQL using the echo command for individual fields on a specific page but am unclear on how to make the leap from doing individual concrete pages to dynamically created template ones - as in how to make a template that would be filled with the respective character's info without having to create an individual page for each character and code the specific echo field commands into each slot.

 

Say I have my MySQL database:

Name    Age  Involvement

Jude    32    Tammy

Bobby  45    Widower

Jimmy  12    None

 

And my empty PHP template:

Name:

Age:

Involvement:

 

How do I go about programming it to fill out Jude's info for the whole template when that info is requested by a visitor and that have that same template without any coding changes call up Bobby's info and so forth?

 

Thanks again,

Amanda

Link to comment
Share on other sites

Here's some my sql / php code to use as an example. You will have to modify to fit your server and database structure.

 

<?php
$conn= mysql_connect("localhost" ,"username" ,"pwwd" ) ; 
if(!$conn) {
echo "Unable to connect to DB: " . mysql_error(); 
exit;
} 
if (!mysql_select_db("YourDatabaseName")) { 
echo " Unable to select Your DatabaseName Database: " . mysql_error() ; 
exit; 
} 
//  SELECT Query to display a specific record: directory 

$sql ="SELECT * FROM Your DatabaseName WHERE id = ". $HTTP_GET_VARS["id"];  // There are other options than this GET 
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
// sample output format 

<?php echo $row["id"] ?> 
<?php echo $row["date"] ?> 
<?php echo $row["f_name"] ?> 
<?php echo $row["m_name"] ?> 
<?php echo $row["l_name"] ?> 
<?php echo $row["title"] ?> 
<?php echo $row["email"] ?> 
<?php echo $row["phone"] ?> 
<?php echo $row["fax"] ?> 
<?php echo $row["expertise"] ?>  

 

Best

Link to comment
Share on other sites

Here is a very simple, very basic option

 

<?php

// your connection here

$page = $_GET['page']; // yourpage.php?page=1
$query = mysql_query("SELECT name,age FROM tablename WHERE id='$page'") or die(mysql_error());
$row = mysql_fetch_assoc($query) or die(mysql_error());
$name = $row['name'];
$age = $row['age'];
echo "Name: {$name}<br />";
echo "Age: {$age}";

?>

 

This is obviously just a template so make it better and safer ;D

 

~ Chocopi

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.