Menu
How exactly do you generate a new HTML page with database content when your database is updated?
[code=php]
<html><head><title>Test</title></head><body>
<h1>This title always prints</h1>
<?php
if(!empty($_GET['page']))
{
mysql_connect('localhost', 'user', 'password') or die(mysql_error());
mysql_select_db('db_name') or die(mysql_error());
$sql = "SELECT * FROM table_name WHERE page = " . (int)$_GET['page'];
$result = mysql_query($sql) or die(mysql_error());
if(($row = mysql_fetch_assoc($result)) !== false)
{
echo "<h2>" . htmlentities($row['title']) . "</h2>n";
echo "<p>" nl2br(htmlentities($row['content'])) . "</p>n";
}
else
{
echo "<p class='error'>Invalid page specified.</p>n";
}
}
else
{
?>
<p>This only gets displayed if no page was specified in URL.</p>
<?php
}
?>
</body>
</html>
[/code]
[code=php]
$_GET = array(
'user' => 123,
'page' => 5,
'style' => 2
);
[/code]
What exactly do you mean by "URL query?"[/QUOTE]
<i>
</i>http://www.example.com/directory/page.php?[color=red]var1=one&var2=two[/color]#part2
...the part in red is the URL query string being used to pass "get" data to the page. "var1" would be the first variable name with a value of "one", and "var2" would be the second name with a value of "two". The ampersand ("&") is used to separate each name=value pair.[code=php]
<html><head><title>Test</title></head><body>
<h1>This title always prints</h1>
<?php
if(!empty($_GET['page'])) <--grabs page number from url
{
mysql_connect('localhost', 'user', 'password') or die(mysql_error());
mysql_select_db('db_name') or die(mysql_error());
$sql = "SELECT * FROM table_name WHERE page = " . (int)$_GET['page']; <--queries database by page number
$result = mysql_query($sql) or die(mysql_error());
if(($row = mysql_fetch_assoc($result)) !== false) <--assoc array return of contents
{
echo "<h2>" . htmlentities($row['title']) . "</h2>n"; <-- prints title from database
echo "<p>" nl2br(htmlentities($row['content'])) . "</p>n"; <--prints contents from database.
}
else
{
echo "<p class='error'>Invalid page specified.</p>n"; <-- bad page number.
}
}
else
{
?>
<p>This only gets displayed if no page was specified in URL.</p>
<?php
}
?>
</body>
</html>
[/code]
I've got two PHP books. A basic one that I've finished, and an intermediate one that I'm about half-way through with.
So is page like the primary key in the database table?[/QUOTE]
So if it's the primary key, would that mean that it's an integer and most likely just used for the ID of the information?[/QUOTE]
0.1.9 — BETA 5.8