Page Titles Created From Mysql Database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fosters82
Forum Newbie
Posts: 2
Joined: Wed Feb 16, 2011 10:22 pm

Page Titles Created From Mysql Database

Post 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!
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Page Titles Created From Mysql Database

Post 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).
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
fosters82
Forum Newbie
Posts: 2
Joined: Wed Feb 16, 2011 10:22 pm

Re: Page Titles Created From Mysql Database

Post 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?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Page Titles Created From Mysql Database

Post 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
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply