Page 1 of 1

Page Titles Created From Mysql Database

Posted: Wed Feb 16, 2011 10:28 pm
by fosters82
Hi, hopefully someone can help me out as I've been trying to do this for several hours now! :banghead:

Basically I know very little about PHP, but what I'm trying to achieve (probably something VERY simple to most) is page titles created from a part of mysql...

I have 2 parts to my mysql table:

f0 & f1

Basically I need the page titles created from f0

Where do I start? can anyone help? I've tried so any different bits of code with no avail....

Many thanks in advance!

Re: Page Titles Created From Mysql Database

Posted: Thu Feb 17, 2011 2:14 am
by social_experiment
You probably start with selecting the data. It's easier to get assistance if you paste some of your example code, ;) don't forget the php tags (button called PHP Code).

Re: Page Titles Created From Mysql Database

Posted: Thu Feb 17, 2011 6:00 am
by fosters82
Thanks for replying, to be honest I really don't have much code to supply :(
I really am not good with php....
As I am trying to use the data from "f0" in mysql Ive tried something like this:

Code: Select all

<title><?php echo $f0; ?></title>
But this did not work

any ideas?

Re: Page Titles Created From Mysql Database

Posted: Thu Feb 17, 2011 11:26 am
by social_experiment
To select data from a database you use the SELECT statement : SELECT fields FROM table. If you wanted to select all the fields you're query would look similar to this

Code: Select all

<?php
 // the * indicates all fields to be selected
 $query = "SELECT * FROM myTable";
 // 
 $sql = mysql_query($query);
?>
To display this data you use functions like mysql_fetch_row(), mysql_fetch_array() or mysql_fetch_object(). To keep it simple, use mysql_fetch_array()

Code: Select all

<?php
 while ($displayArray = mysql_fetch_array($sql)) {
  // display results
  echo $displayArray['field1'];
  echo $displayArray['field2'];
  // etc
} ?>
If you aren't sure about these functions you can take a look at w3schools.com, they offer good information if you are just starting out.
Hth