Jump to content

Help with database fields


Tesign

Recommended Posts

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);

?>

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.