Tesign Posted January 2, 2010 Share Posted January 2, 2010 For a school project I am trying to set up a template system for my website. I am using a database to store the pieces of html code tha I need to load in my site. My problem is that I need to use multiple fields on the same page. This is the code I have this far but I can't get it to load multiple id's please help me. <?php include("./include/connect.php"); include("./include/spotlightfotos.php"); if(!isSet($_GET['id'])){ $_GET['id'] = 4; } $sqlStr = "SELECT naam, content, id FROM tb_content WHERE id =" . $_GET['id']; $ref = mysql_query($sqlStr); $resultaat = mysql_fetch_array($ref); $template = file_get_contents("../template.html"); if( ! mysql_error()){ $login = $resultaat['content']; $template = str_replace("%login%",$login,$template); $tekst = $resultaat['content']; $template = str_replace("%content%",$tekst,$template); $foto = getSpotlightPictures(0); $template = str_replace("%spotlight%",$foto,$template); echo $template; } //print_r($resultaat); ?> Quote Link to comment Share on other sites More sharing options...
Tranceflux Posted January 3, 2010 Share Posted January 3, 2010 Hi Tesign, Do you mind elaborating what you want to achieve/ have in mind? Quote Link to comment Share on other sites More sharing options...
Tesign Posted January 3, 2010 Author Share Posted January 3, 2010 What I am trying to achieve is that when I press a button in the html website loaded into php that it will change the id number so that it loads in the content as shown into my database. But with the script I have this far it only can load content from one id and I need from multiple id's. So that I can have for example in id 1 the content for home in id 2 the content for the header, so when I press a button in the header it goes to id 3 wich is the content for a different page. but now I can only load content out of one id at a time. Quote Link to comment Share on other sites More sharing options...
Catfish Posted January 4, 2010 Share Posted January 4, 2010 If, when you say "press a button to load a different ID" you mean clicking a hyperlink or a form button to load a new page, you can add the value of the $_GET['id'] into the <a href> tag's value. Like: <a href="http://www.mysite.com/yourScript.php?id=X">Go to page X</a> X is the value of $_GET['id'] when the script runs on the server (when the page is loaded). if you wanted, you could make multiple links on one page, to load different data from your database: <a href="http://www.mysite.com/yourScript.php?id=1">Go to page 1</a> <a href="http://www.mysite.com/yourScript.php?id=2">Go to page 2</a> etc. If you mean, you want to load for example: id number 1's, id number 2's, and id number 5's data from the database into one page this is totally different. You need an array to hold the values of the ids you want loaded. $_GET['id'] can be made an array but I only know how to do that if using a form, not <a href> links. Quote Link to comment Share on other sites More sharing options...
Tesign Posted January 4, 2010 Author Share Posted January 4, 2010 Thank you for the response, I contacted my php teacher at school about this and he wil help me with it. Thank you again for the response though. Quote Link to comment Share on other sites More sharing options...
crabfinger Posted January 4, 2010 Share Posted January 4, 2010 isSet is not a function so every time you call it it is going to be false which means you will always get $_GET['id'] = 4; unless you change isSet() to isset(). You may also want to add " && is_numeric($_GET['id'])" to the if statement just to make sure that nobody is submitting some extra sql shit in there. Quote Link to comment 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.