Monday, January 18, 2010

Getting Data from MYSQL DB displayed on my page in PHP

The first small project I created to start my site was to be successful in connecting to the database and then displaying the information in php

Step 1- Create a variable the will hold the $_GET variable that will come in from the url.

$pdisplayed = $_GET[‘pid’];

Step 2 - Connect to your database:

$db_connection = mysql_connect('localhost', 'root', '');
if (!
$db_connection) {
die(
'Opps Problem ' . mysql_error());
}

Step 3 – Create the query – you can create the query and store them in variables.

$sqlquery = ‘SELECT id, name, description FROM mysite.product where id = $pdisplayed';

Step 4 - Run the query through the mysql_query() function.

$result = mysql_query($sqlquery);

Step 5 – Now choose with fetch function you will use.

while ($row = mysql_fetch_assoc($result)) {
printf("ID: %s Name: %s", $row[id], $row[name]);
}

or

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf("ID: %s Name: %s", $row[0], $row[1]);
}

or

$row = mysql_fetch_row($result);


The best one to use is the mysql_fetch_assoc

And that should now show you data from the database from the url of the page.

EXAMPLE: www.mysite.com/index.php?pid=2

That 2 would be element two in the databalse.

Tuesday, January 12, 2010

So Lets Try This Out!!

New year, new resolution! I have accepted the fact that I have a short attention span on things that I try to do. I always start and then somewhere along the line, I hit a pebble on the road and there goes my interest completely. Don't get me wrong, I have proven to be successful in my career but I feel the struggle has been great because I have to always remind myself on how important it was for me when I first started.

I am a Web Application Developer by day and a mommy/wife by night. For fun, I create diaper cakes, spin, dance, and sometimes swim. I even collect plush toys. Yes I am nutty like that. I am probably the only 30 something year old that would make my room look like a six year' s old palace of plush toys if it wasn't such an excruciating torture to have my poor husband live in that type of environment.

Anyway, lets get here to the point! This blog is intended to keep my personal reference of my great endeavor of creating my diaper cake web site. I will post all the steps and technology I come across to make sure I continue moving forward. My Mommysdelights blog has successfully made it to its 3rd year. It was first intended to have a one stop log of all my beautiful creations. Now its time to make sure my cakes have a real website.

Now this can be seen as part two of my project. Now not only to learn more technology but follow through with Mommysdelights.com.

OK WISH ME LUCK!!!