Jessica Posted March 8, 2013 Share Posted March 8, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/275384-load-meta-data-dynamically-from-mysql-database/page/2/#findComment-1417410 Share on other sites More sharing options...
Skorpio Posted March 8, 2013 Author Share Posted March 8, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/275384-load-meta-data-dynamically-from-mysql-database/page/2/#findComment-1417413 Share on other sites More sharing options...
Jessica Posted March 8, 2013 Share Posted March 8, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/275384-load-meta-data-dynamically-from-mysql-database/page/2/#findComment-1417415 Share on other sites More sharing options...
Skorpio Posted March 8, 2013 Author Share Posted March 8, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/275384-load-meta-data-dynamically-from-mysql-database/page/2/#findComment-1417417 Share on other sites More sharing options...
Jessica Posted March 8, 2013 Share Posted March 8, 2013 So you just have a list of meta data with NO CLUE what page each item goes with? What's the point then? Quote Link to comment https://forums.phpfreaks.com/topic/275384-load-meta-data-dynamically-from-mysql-database/page/2/#findComment-1417418 Share on other sites More sharing options...
Jessica Posted March 8, 2013 Share Posted March 8, 2013 It's like if you had an address book with a bunch of addresses and phone numbers and no way to tell who they belong to... Quote Link to comment https://forums.phpfreaks.com/topic/275384-load-meta-data-dynamically-from-mysql-database/page/2/#findComment-1417420 Share on other sites More sharing options...
Skorpio Posted March 8, 2013 Author Share Posted March 8, 2013 That is the whole point, that was and still is my question in this forum, how do I call the correct record? That is the point Quote Link to comment https://forums.phpfreaks.com/topic/275384-load-meta-data-dynamically-from-mysql-database/page/2/#findComment-1417422 Share on other sites More sharing options...
Skorpio Posted March 8, 2013 Author Share Posted March 8, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/275384-load-meta-data-dynamically-from-mysql-database/page/2/#findComment-1417427 Share on other sites More sharing options...
Jessica Posted March 8, 2013 Share Posted March 8, 2013 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!!! Quote Link to comment https://forums.phpfreaks.com/topic/275384-load-meta-data-dynamically-from-mysql-database/page/2/#findComment-1417428 Share on other sites More sharing options...
Jessica Posted March 8, 2013 Share Posted March 8, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/275384-load-meta-data-dynamically-from-mysql-database/page/2/#findComment-1417429 Share on other sites More sharing options...
Skorpio Posted March 8, 2013 Author Share Posted March 8, 2013 Still trying to find information on the URL query string and its use/syntax as currently that means nothing to me but thanks for pointing me in the direction. Quote Link to comment https://forums.phpfreaks.com/topic/275384-load-meta-data-dynamically-from-mysql-database/page/2/#findComment-1417433 Share on other sites More sharing options...
Skorpio Posted March 8, 2013 Author Share Posted March 8, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/275384-load-meta-data-dynamically-from-mysql-database/page/2/#findComment-1417434 Share on other sites More sharing options...
Skorpio Posted March 8, 2013 Author Share Posted March 8, 2013 (edited) 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 March 8, 2013 by Skorpio Quote Link to comment https://forums.phpfreaks.com/topic/275384-load-meta-data-dynamically-from-mysql-database/page/2/#findComment-1417543 Share on other sites More sharing options...
Jessica Posted March 8, 2013 Share Posted March 8, 2013 If you're viewing page #2, your url should look like page.php?id=2 Then in your code you can do $id = (int) $_GET['id']; Easy. Quote Link to comment https://forums.phpfreaks.com/topic/275384-load-meta-data-dynamically-from-mysql-database/page/2/#findComment-1417546 Share on other sites More sharing options...
Skorpio Posted March 8, 2013 Author Share Posted March 8, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/275384-load-meta-data-dynamically-from-mysql-database/page/2/#findComment-1417550 Share on other sites More sharing options...
Jessica Posted March 8, 2013 Share Posted March 8, 2013 With your keyboard. Quote Link to comment https://forums.phpfreaks.com/topic/275384-load-meta-data-dynamically-from-mysql-database/page/2/#findComment-1417556 Share on other sites More sharing options...
Skorpio Posted March 8, 2013 Author Share Posted March 8, 2013 A very informative answer, I thank you for your arrogance and sarcasm Quote Link to comment https://forums.phpfreaks.com/topic/275384-load-meta-data-dynamically-from-mysql-database/page/2/#findComment-1417561 Share on other sites More sharing options...
PaulRyan Posted March 8, 2013 Share Posted March 8, 2013 (edited) 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 March 8, 2013 by PaulRyan Quote Link to comment https://forums.phpfreaks.com/topic/275384-load-meta-data-dynamically-from-mysql-database/page/2/#findComment-1417564 Share on other sites More sharing options...
Solution Skorpio Posted March 8, 2013 Author Solution Share Posted March 8, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/275384-load-meta-data-dynamically-from-mysql-database/page/2/#findComment-1417567 Share on other sites More sharing options...
Jessica Posted March 8, 2013 Share Posted March 8, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/275384-load-meta-data-dynamically-from-mysql-database/page/2/#findComment-1417594 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.