Still newbie warning.
My jokedatabase is now getting to be almost the way i like it. But i still would like to add two new functions.
Q: I would like to add a field to the mySQL DB called E.g "counter", then would like to increase this number by one every time the record i viewed by a user.
My php page looks like:
Code: Select all
<?php
/* Connect to the DB, and retrive some simple variables, like $navbar etc. */
include ("funksjoner.php");
/* Find the record matching the Joke requested by the user */
$sql="SELECT * FROM vitser WHERE ID = '$rec_ID'";
$mysql_result=mysql_query($sql,$connection);
$num_rows=mysql_num_rows($mysql_result);
if ( $num_rows == 0 )
{
echo "Sorry, the record could not be found";
}
else
{
while ($row=mysql_fetch_array($mysql_result))
{
/* Tranlsated DB fields: tittel = Title, kategori = category, gittav = sendt by (name), epost = Email, innhold= content */
$tittel=$rowї"tittel"];
$kategori=$rowї"kategori"];
$gittav=$rowї"gittav"];
$epost=$rowї"epost"];
$innhold = nl2br($rowї"innhold"]);
$ID=$rowї"ID"];
# SHOW RESULT
echo "$software - $version";
echo "<br><br>";
echo "$navbar";
echo "JokeNr: $ID - <b>$tittel</b><br> (<i>$gittav - $epost</I>)<br><br>";
echo "$innhold<br><hr><br>";
}
} # END ELSE
mysql_close($connection);
?>1: See if the value is set, if not set it to 1 (if it has not been viewed before)
2: Find the current value, and increase it be one.
3: Save the new information back to the record with new values.
I'm i going about this all wrong, or is what I'm trying to do easy? Hope someone can help out, and that i have learned something when it comes to commenting and coding since the last time.