• Welcome to The Cave of Dragonflies forums, where the smallest bugs live alongside the strongest dragons.

    Guests are not able to post messages or even read certain areas of the forums. Now, that's boring, don't you think? Registration, on the other hand, is simple, completely free of charge, and does not require you to give out any personal information at all. As soon as you register, you can take part in some of the happy fun things at the forums such as posting messages, voting in polls, sending private messages to people and being told that this is where we drink tea and eat cod.

    Of course I'm not forcing you to do anything if you don't want to, but seriously, what have you got to lose? Five seconds of your life?

PHP/MySQL questions

Lorem Ipsum

Member
Pronoun
x
For my Westminster RPG, I'm coding a website to enhance the Election Night. Basically, I enter the results of the election into a MySQL database, and I can recall that with no problem. But, I want to do something different with it: is it possible to create a completely new HTML page for each set of data?

So, for example if I entered a set of data about the constituency Glasgow South-West, could I use PHP to create a page called glasgowsouthwest.php for the viewing of that constituency's individual data?

Any help would be very much appreciated!
 
What I think he means is, if you're going to have the same information on the page for each constituency, wouldn't it make sense for there to be just one script that would take the location as the input and then display a page with values it had taken from your database plugged into some kind of predetermined template.

Think of, for example, the user profiles on these forums: they all contain the same "kind" of information (username, avatar, personal pic, VM's) for each individual, and they're all spit out by the "member.php" script, which takes a userid (?u=somenumber) and looks up information on that userid to plug into a generic template.

So rather than creating something like glassgowsouthwest.php, you would create a generic script like "constituency.php" and then just pass it the name or id of the constituency you wanted displayed. Not difficult, but it does require some basic knowledge of how to get PHP to interact with a database and templates. A decent PHP book or tutorial should give you enough of the basics to do it, no problem.
 
Ah, I see what you mean - that would be far neater as well. Unfortunately though I have tried several searches and looked over several PHP tutorials and can find nothing talking about it - is there anything you recommend?
 
What I learned of PHP I got out of books because I couldn't find any good tutorials online, and honestly I wouldn't recommend any of the books I used, either. You might look at your local library (better if you have access to an academic library; they tend to have more technical stuff). I just picked up what I know here and there, so I can't really give you much help, sorry.
 
I've found what I think you're talking about - query strings. I've got the code, but it's not returning anything when I run the script, so I can't help but think that I've done something wrong.

Theoretically, going to http://ukgovsim.hostzi.com/bbc/constituency.php?id=1 should return information about Aldershot. But it doesn't.

Help?

Code:
<html>
<body><?php

$mysql_host = censored;
$mysql_database = censored;
$mysql_user = censored;
$mysql_password = censored;

mysql_connect($mysql_host,$mysql_user,$mysql_password);

@mysql_select_db($mysql_database) or die("Unable to select database");

$myvar = $_POST['querystring'];
$result = mysql_query("SELECT * FROM constituencies WHERE id='$myvar'");

while($row = mysql_fetch_array($result))
  {
  echo $row['name'];
  echo "<br>";
  echo "Conservative" . $row['connum'] . " (" . $row['conper'] . ")";
  echo $row['labnum'] . " (" . $row['labper'] . ")";
  }

?></body></html>

Sorry if I'm sounding like a noob - this is probably a very easy problem to solve that I'm overlooking D:
 
QUERY_STRING is an environment variable; you should be using $_POST['id'] or $_GET['id'] or the php equivalent. and you should sanitize your database inputs. somebody might type in "'; drop table constituencies; --" and that would be Bad.
 
Back
Top Bottom