Jump to content

Skorpio

Members
  • Posts

    52
  • Joined

  • Last visited

Everything posted by Skorpio

  1. I now have the 2nd box functioning as expected however the third, a textarea is a whole other matter. If someone could steer me in the right direction I would appreciate it? Thanks The previous links to the code hold the updated code.
  2. MySQL server version: 5.1.60-rel13.1 "SELECT `id`, `sub_topic`, `url`, `info` FROM `links No errors are being thrown. The structure of my database is visible here == Table structure for table links |------ |Column|Type|Null|Default |------ |//**id**//|int(11)|No| |topic|varchar(150)|No| |sub_topic|varchar(150)|No| |info|text|No| |url|varchar(255)|No| == Dumping data for table links Hi, after completing a dropdown tutorial I am trying to convert code for my purpose which is dropdown1 make selection from topics which upon valid selection triggers dropdown2 to be enabled and populate with subtopics then upon selection from dropdown2 (final choice) a textarea will be populated with the relevant information and hyperlink. The issue at the moment is that I am getting all information in sub_topics rather than the ones linked to the main topic selected in dropdown1 which means my statement is incorrect but I cannot work out what I am missing. I know what I want to do but not sure how to get it/write it. I have been working on this for several hours, my statement started out as SELECT * FROM `categories` WHERE `master` = ? from the tutorial to SELECT `id`, `topic`, `sub_topic`, `info`, `url` FROM `links` WHERE `id` = ? GROUP BY `topic` Reasoning for the GROUP BY was that I wanted to remove duplicates, for example I have 'web design' as a topic but this is same for over 20 records, I don't want 'web design' in the list 20+ times. I went through a few other statements before I got to "SELECT `id`, `topic`, `sub_topic`, `url`, `info` FROM `links Now this has meant that I am getting data populating the 2nd box and the trigger is enabling the box however now I am getting all the records (everything). I realise I have not got the statement right but cannot work out how to write it. Link to the code being used. The MySQL db I would appreciate it if someone could advise as to where I have gone wrong and possibly how I correct it so only the correct options show in the 2nd box. Thanks
  3. 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
  4. A very informative answer, I thank you for your arrogance and sarcasm
  5. 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
  6. 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?
  7. The problem is from here, I will research your suggestions and have a stab at it.
  8. 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.
  9. 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
  10. 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
  11. 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.
  12. 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.
  13. I dont know at the moment because if I were to hazard a guess my current code only gives me the first record in the database
  14. This is part of my original question, Guru has kindly given me what I have so far but this was part of the original problem I had when I came in here, I am unsure how to specify the page. What I did in my previous code thinking it may solve the issue did nothing at all so on this part I am back to the drawing board. Do I need to continue with the code Guru provided, i.e. unset ($row['page_title']) ; // so it clears the previous title Then I was thinking maybe adding to the foreach loop but that didn't work so I am stumped at the moment.
  15. That is my intention eventually, I have already put a very basic one together through a tutorial and have ideas of how to plan my own out but first wanted to get this working before I even think of going any further.
  16. As it stands at this moment in time, I am getting data from the database into the correct fields but there is only 1 set of data being used from the database. I think it is because although I have the variables set up that I am not telling what page should be associated with which id etc, the code so far is // getmetadata.php include 'connect.php'; $id = 'meta_id'; $title = 'page_title'; $pname = 'page_name'; $desc = 'meta_description'; $key = 'meta_keywords'; $aut = 'author'; $copyr = 'copyright'; $email = 'email'; $rating = 'rating'; $robots = 'robots'; $visit = 'revisit'; $exp = 'expires'; $dist = 'distribution'; $sql = "SELECT * FROM meta_data WHERE meta_id = $id"; $query = $db->query($sql); $row = $query->fetch(PDO::FETCH_ASSOC); unset ($row['meta_id']) ; // discard that one foreach ($row as $desc => $content) { echo "<meta name=\"$desc\" content=\"$content\" />\n" ; } The home page is as follows <!-- home.php --> <!DOCTYPE HTML> <html> <head> <link rel="apple-touch-icon" href="apple_touch_icon.png"/> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <?php include_once('../includes/fetchmetadata.php'); ?> <link rel="shortcut icon" href="favicon.ico" type="image/icon" /> <!-- favicon for browser, the image is .ico file in root directory--> <title></title> </head> <body> </body> </html> Together the output from home.php is <!DOCTYPE HTML> <html> <head> <link rel="apple-touch-icon" href="apple_touch_icon.png"/> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>page_title</title> <!-- not getting the title of the page but entering the dbase field name --> <meta name="page_name" content="home" /> <meta name="page_title" content="Home Page" /> <!-- this should be going in the html title tags and need to delete this from the php script --> <meta name="meta_description" content="introduction to our products and services offered at competitive prices" /> <meta name="meta_keywords" content="web design, bespoke websites, dynamic websites, web packages" /> <meta name="author" content="author" /> <meta name="copyright" content="© Organisations Name, 2013" /> <meta name="email" content="organisations email" /> <meta name="rating" content="General" /> <meta name="robots" content="INDEX,FOLLOW" /> <meta name="revisit" content="7 Days" /> <meta name="expires" content="Tue, 24 dec 17:20:00 GMT" /> <meta name="distribution" content="Global" /> <link rel="shortcut icon" href="favicon.ico" type="image/icon" /> <!-- favicon for browser, the image is .ico file in root directory--> </head> <body> </body> </html> I tried an if statement to get the title but all that gave me was the same as what I was getting at the start, page_title inbetween the html title tags. Guru has got me 3/4 of the way there but just need another nudge to get the title working and then the meta information to work dynamically depending on the page that is chosen. Thanks Guru for getting me this far.
  17. Ok so worked out my first mistake, removed all the meta data from the home page and then included the php file in the right location, so now I get <!DOCTYPE HTML> <html> <head> <link rel="apple-touch-icon" href="apple_touch_icon.png"/> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="page_name" content="home" /> <meta name="page_title" content="Home Page" /> <meta name="meta_description" content="introduction to our products and services offered at competitive prices" /> <meta name="meta_keywords" content="web design, bespoke websites, dynamic websites, web packages" /> <meta name="author" content="author" /> <meta name="copyright" content="© organisations name, 2013" /> <meta name="email" content="organisations email" /> <meta name="rating" content="General" /> <meta name="robots" content="INDEX,FOLLOW" /> <meta name="revisit" content="7 Days" /> <meta name="expires" content="Tue, 24 dec 17:20:00 GMT" /> <meta name="distribution" content="Global" /> <link rel="shortcut icon" href="favicon.ico" type="image/icon" /> <!-- favicon for browser, the image is .ico file in root directory--> <title></title> </head> <body> </body> </html> However if I view say the contact page I am getting the exact same details and the html <title></title> is still blank, instead I am getting <meta name="page_title" content="Home Page" />
  18. Ok so now I have <?php // fetchmetadata.php include 'connect.php'; $id = 'meta_id'; $title = 'page_title'; $pname = 'page_name'; $desc = 'meta_description'; $key = 'meta_keywords'; $aut = 'author'; $copyr = 'copyright'; $email = 'email'; $rating = 'rating'; $robots = 'robots'; $visit = 'revisit'; $exp = 'expires'; $dist = 'distribution'; $sql = "SELECT * FROM meta_data WHERE meta_id = $id"; $query = $db->query($sql); $row = $query->fetch(PDO::FETCH_ASSOC); unset ($row['meta_id']) ; // discard that one foreach ($row as $desc => $content) { echo "<meta name=\"$desc\" content=\"$content\" />\n" ; } ?> When I view the page I get the following returned from the dbase, bearing in mind these are sample keywords etc as have data to input once I have this working <meta name="page_name" content="home" /> <meta name="page_title" content="Home Page" /> <meta name="meta_description" content="introduction to our products and services offered at competitive prices" /> <meta name="meta_keywords" content="web design, bespoke websites, dynamic websites, web packages" /> <meta name="author" content="name" /> <meta name="copyright" content="© organisations name, 2013" /> <meta name="email" content="organisations email" /> <meta name="rating" content="General" /> <meta name="robots" content="INDEX,FOLLOW" /> <meta name="revisit" content="7 Days" /> <meta name="expires" content="Tue, 24 dec 17:20:00 GMT" /> <meta name="distribution" content="Global" /> So far so good, now I come to the physical pages on the site, i.e. home/index.php, I have removed all the php from the homepage bar the include 'fetchmetadata.php'; for the fetchmetadata.php page and when I view the source of the homepage I now get <meta name="page_name" content="home" /> <meta name="page_title" content="Home Page" /> <meta name="meta_description" content="introduction to our products and services offered at competitive prices" /> <meta name="meta_keywords" content="web design, bespoke websites, dynamic websites, web packages" /> <meta name="author" content="author" /> <meta name="copyright" content="© organisations name, 2013" /> <meta name="email" content="organisations email" /> <meta name="rating" content="General" /> <meta name="robots" content="INDEX,FOLLOW" /> <meta name="revisit" content="7 Days" /> <meta name="expires" content="Tue, 24 dec 17:20:00 GMT" /> <meta name="distribution" content="Global" /> <!DOCTYPE HTML> <html> <head> <link rel="apple-touch-icon" href="apple_touch_icon.png"/> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="description" content="distribution" /> <!-- info should be here --> <meta name="keywords" content="" /> <meta name="copyright" content="" /> <meta name="author" content="" /> <meta name="email" content="" /> <meta name="Distribution" content="" /> <meta name="Rating" content="" /> <meta name="Robots" content="" /> <meta name="Revisit-after" content="" /> <meta name="expires" content="" /> <link rel="shortcut icon" href="favicon.ico" type="image/icon" /> <!-- favicon for browser, the image is .ico file in root directory--> <title></title> </head> <body> </body> </html> The home page php/html is as follows <?php include_once('../includes/fetchmetadata.php'); ?> <!DOCTYPE HTML> <html> <head> <link rel="apple-touch-icon" href="apple_touch_icon.png"/> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="description" content="<?php echo $desc; ?>" /> <!-- info should be here --> <meta name="keywords" content="" /> <meta name="copyright" content="" /> <meta name="author" content="" /> <meta name="email" content="" /> <meta name="Distribution" content="" /> <meta name="Rating" content="" /> <meta name="Robots" content="" /> <meta name="Revisit-after" content="" /> <meta name="expires" content="" /> <link rel="shortcut icon" href="favicon.ico" type="image/icon" /> <!-- favicon for browser, the image is .ico file in root directory--> <title></title> </head> <body> </body> </html> As I say I removed the php tags from all but 1 field until it is working as now I have duplicated the info for some reason.
  19. As that snippet stands I am sure I am getting closer but I am getting the following returned Notice: Undefined variable: meta_id in C:\xampp\htdocs\MyLatestSite\includes\fetchmetadata.php on line 19 Notice: Undefined variable: query in C:\xampp\htdocs\MyLatestSite\includes\fetchmetadata.php on line 23 Fatal error: Call to a member function fetch() on a non-object in C:\xampp\htdocs\MyLatestSite\includes\fetchmetadata.php on line 23 Line 23 being $row = $query->fetch(PDO::FETCH_ASSOC); and 19 being $sql = "SELECT * FROM meta_data WHERE meta_id = $meta_id";
  20. Sorry I must not be explaining myself, I know what you are saying about the database and normalisation however as you have seen from the original post all the fields have names relevant to the data stored within it and yes I realise I could go through naming all the fields in the select statement but as I am using all the fields I used the * as the DBASE has 13 fields it just keeps the code tidier (in my opinion for what it is worth). My fields are meta_id page_name page_title meta_description meta_keywords author copyright email rating robots revisit expires distribution all of those fields are going to be called hence the * in the select statement As the following returns the data, all be it everything in the table, I am just unsure of how to pick the relevant elements for the right page. include 'connect.php'; $title = 'page_title'; $pname = 'page_name'; $desc = 'meta_description'; $key = 'meta_keywords'; $aut = 'author'; $copyr = 'copyright'; $email = 'email'; $rating = 'rating'; $robots = 'robots'; $visit = 'revisit'; $exp = 'expires'; $dist = 'distribution'; $query = $db->query("SELECT * FROM meta_data"); while ($row = $query->fetch(PDO::FETCH_ASSOC)){ echo $row[$pname] . '<br>'; echo $row[$title]. '<br>'; echo $row[$desc]. '<br>'; echo $row[$key]. '<br>'; echo $row[$aut]. '<br>'; echo $row[$copyr]. '<br>'; echo $row[$email]. '<br>'; echo $row[$rating]. '<br>'; echo $row[$robots]. '<br>'; echo $row[$visit]. '<br>'; echo $row[$exp]. '<br>'; } // this is just for testing and it works but using what I have already what do I need to add to get the relevant data fed to the correct page? Thanks
  21. <?php echo $title; ?> outputs the following source <title>page_title</title> and echo $row[$title] when embedded into the php pages gives me <title></title> As I say I cannot work out why when I use echo $row[$title] on the query page I get oputput echoed out but on the individual pages I get nadda. The echo statements in the php file with the query give me all the data from all the fields as expected.
  22. When I enter echo $row[$title] into the title field I do not get any data in the title field although I have included the selectdata.php (attatched to post #1) file which has the "SELECT * FROM meta_data" query
  23. I realise that echo $row[$desc] will give me the data but what I cannot work out is how I only get the relevant data for that page. I.e. I only want the title for the home page in the home page title field but I am getting all of the pages title fields. So I guess my question is which is the best way to ensure that the title field data from the mysql database for the home page is the only data that goes into the title field on the homepage? Thanks
  24. The field names are 'page_title'; etc and then I have created variables to store the data from the records
×
×
  • 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.