PDA

View Full Version : im Totally lost on this one


jfrovich
24-06-2006, 12:03/12:03PM
I have 2 databases
i have the mysql installed
but i have NO idea how to get the sql data onto my html or php webpages.

Ive tried , but im not a programmer
i did search for a program to help me, but no luck either?
any ideas

srikanthsh
24-06-2006, 12:29/12:29PM
Hire a PHP programmer, or you learn PHP.

jfrovich
24-06-2006, 12:42/12:42PM
Originally posted by srikanthsh
Hire a PHP programmer, or you learn PHP.

well i tried to learn
so i guess ill hire a programmer

ill start looking thanks.

WebSavvy
24-06-2006, 13:20/01:20PM
It's easy to get the data onto your pages. Firstly, the pages must be .php pages. They cannot be .html, .shtml, and so forth, because they need to parse the php.

Secondly, make a file that you will use as an "include" that holds the sql connection statements to your db.

This file might be called something like connect.php or something along those lines. Note of caution: I would suggest that you never name this file anything to do with conf.php or config.php as it's something a lot of hackers already look for.

Create a folder for your include files. Call the folder something other than includes because again, it's something hackers look for.

Now, the typical connection file will hold the following information in the format shown below:

<?php
$connection = @mysql_connect("localhost" , "db_user" , "db_pass") or die (" Could not connect to the server. ");
$db = @mysql_select_db("db_name" , $connection) or die (" Could not select database. ");
?>


In the above, change ::

db_user
to your database username

db_pass
to your database password

db_name
to the name of your database

We're assuming that you have assigned a username and password to the db in order to grant access to use it. If you have not, then log into your site, and go into the area where you created the db at, and set up a username and password.

There should be fields there to "created a db username"
Once you have created the user/pass, you need to assign them to the db.

You do this by selecting the db user from the drop menu, and then add them to the db. Then it should update and tell you
user "so and so" has been added to db "so and so"

Now, put the db connection file from above in your includes folder once you've edited the information to reflect your db settings.

Now, in the root of your domain where your index page lives, you should have folders and other files -- it is there that you will also place the pages that will be used for the db to get the data.

If the pages already living there are the ones you want to call the data into, they must end in .php, and you would simply add the contents of the file below to these pages.

Note, that all pages where actual programming happens must begin with open php tags and close php tags.

Open php tag is
<?php

Close php tag is
?>

Time to get the data from your db.


<?php

@include("/home/folder/path/to/connection-file.php");

$sql = "SELECT field1, field2, field3, field4 FROM db_table";
$sql_result = mysql_query($sql , $connection) or die ("Couldn't execute query.");

while ($row = mysql_fetch_array($sql_result))
{
$field1 = $row["field1"];
$field2 = $row["field2"];
$field3 = $row["field3"];
$field4 = $row["field4"];

// PUT YOUR INFO HERE

} // close while loop

?>

From the above, change the $field[x] names to reflect your actual db field names. Change db_table to reflect the actual name of the table from your database.

Change /home/folder/path/to/connection-file.php
To reflect the actual file path to your db connection file from the server root.

In the center where you see the following

// PUT YOUR INFO HERE

This is where the content is placed. For example if you wanted to pull out information like a title, description, and keywords to be used in meta tags, you'd simply put the information there as follows:


echo <<<EOF
<title><?=$title?></title>
<meta name="description" content="<?=$description?>">
<meta name="keywords" content="<?=$keywords?>">
EOF;


This should be enough to get you started on the right track.

jfrovich
24-06-2006, 13:31/01:31PM
WOW savvy1
thanks ill will try that at home later tonight:cheers:

WebSavvy
24-06-2006, 13:36/01:36PM
Welcome. Let me know if you're able to get it working or not?

Comeran
24-06-2006, 19:58/07:58PM
Wow Deb you really went all out on this post :p

Maybe you should have a PHP school that you teach, since you like PHP, teaching, and online helping it makes lots of sense... I would take the class.

Comeran-