Jump to content

Load Meta data dynamically from mysql database


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?

Link to post
Share on other sites

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 post
Share on other sites

If you have a row that has your meta data.

What. Identifying. Information. Is there.

 

It's not a trick question. How do YOU the person I am talking to...know what data goes with what page?

Link to post
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 post
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 post
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 post
Share on other sites

There you go - you have an id.

 

You would typically use the URL query string to specify the id, then use $_GET to get it.

 

The problem is from here, I will research your suggestions and have a stab at it.

Link to post
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?

Link to post
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 post
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}";
Link to post
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}";

 

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 post
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 post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.