Jump to content

Load Meta data dynamically from mysql database


Skorpio
Go to solution Solved by Skorpio,

Recommended Posts

Guru is not a person, it's our badge.

 

If you can't explain how you relate the data in the database with the page how do you expect to code it?

 

well ok, thanks Barrand, as he was the only person at the time of writing he knew I was thanking him.  As far as relating to the database, I know what I want to do but unsure how to do it, hence coming into this forum asking for help and advice.  As you will see from the very start of this thread I had made attempts at getting started but was not getting anywhere again hence me coming into a forum and asking the questions I have been asking.

Link to comment
Share on other sites

At the moment I don't because I am unsure how to write in the correct syntax, the only thing I can think of is that I need to write an if statement but then I still have the same problem because I do not know how to ensure the correct record is called for the corresponding page.

Link to comment
Share on other sites

So I have tested the SELECT statement, changed $id to 2 to see if it would call the right record 'contact.php' and it did but I am no better off in getting the right syntax.  I can only think of a load of if statements but surely that is not the way to go as this would mean every time I add a new page I would need to add to the if statements.

 

$sql = "SELECT * FROM meta_data WHERE meta_id = 2";

 

gave me the correct record from the DB

Link to comment
Share on other sites

If you don't know how can we help you?

 

Again. It's not a trick question, it should have a simple answer. Something like an id or a page name.

 

If you have two sets of data how do YOU KNOW when you look at them which set goes with which page? If you really don't know then the data is meaningless!!!

Link to comment
Share on other sites

Well at the moment I am not getting any further.  The first proble I have is that now I have given meta_id a number, to pick up a specific record, I now need to work out how to substitute the number so that the right page details are used.

 

$sql = "SELECT * FROM meta_data WHERE meta_id = 2 LIMIT 1";

 

Query string still doesn't mean anything to me despite reading and watching a couple of tutorials as I cannot put it into context for my use.

 

Any suggestions please?

 

Would I be better to use if statements but surely the downside to this is if adding or removing pages from site means editing this if statement?

Edited by Skorpio
Link to comment
Share on other sites

Yes maybe for you it is easy to solve this problem but as you are aware I clearly do not have the skills in this case to resolve the issue.

 

I understand what you are saying about the url should look like page.php?id=2 but it is how I get it to that state, currently I have the url as 

 

../content/contact.php
Link to comment
Share on other sites

At the top of each page you create for example, "contact.php" "index.php" "about.php" etc etc...you need to set a variable $page_id with the ID number of the page in the database, I personally would use the page name as the identifying value, but that's a different kettle of fish altogether.

 

Top of a page: (THIS IS JUST AN EXAMPLE)

 

<?PHP
  //### Set the page ID to retrieve data from database
  $page_id = 1;
?>

 

Then use something like this to fetch that data:

$sql = "SELECT * FROM `meta_data` WHERE `meta_id` = {$page_id}";
Edited by PaulRyan
Link to comment
Share on other sites

  • Solution

 

At the top of each page you create for example, "contact.php" "index.php" "about.php" etc etc...you need to set a variable $page_id with the ID number of the page in the database, I personally would use the page name as the identifying value, but that's a different kettle of fish altogether.

 

Top of a page: (THIS IS JUST AN EXAMPLE)

 

<?PHP
  //### Set the page ID to retrieve data from database
  $page_id = 1;
?>

 

Then use something like this to fetch that data:

$sql = "SELECT * FROM `meta_data` WHERE `meta_id` = {$page_id}";

 

Thanks for that Paul, that worked a treat.  I know how the corresponding data being delivered to the correct page.

 

So as long as I ensure the page id matches the meta_id everything will work

Link to comment
Share on other sites

Hardcoding lookup ids and repeating the same code on every PHP page - probably about the worst possible way to create a dynamic site.

 

You're still going to have to update your pages every time you make a new one. All you have done is create MORE work for yourself with absolutely no benefit.

 

Don't get pissy with me because you can't wander a simple question. I'm not being sarcastic at all in any of my posts. The solution you've come up with is time wasting and offers no benefit. If you could bother to stop and think, and answer a simple question I asked you or try the solution I was suggesting, you might actually code something useful.

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.