开发者

Two questions about possible mysql and php functionalities (maybe javascript?), and where I should look to learn more

First, is it possible for when I insert a record onto my mysql table, a page is automatically generated using the new record in some way. EXAMPLE: My column "image" is on autoincrement, so my image names are always numbers. Furthermore, is it possible for when I insert a record, I automatically generate a page with my image name. So basically, I submit record 367, the image name is 367, and my site will automatically generate mysite.com/367? I want to go in more details but you get the point. Is it possible? If not, what's the closest thing possible?

Also, is there someway to automatically update my page periodically. Such as I set it so at 5pm, it'll automatically insert a code. 5:30pm, it'll insert a different code, which I preprogrammed to do. This is useful, for say I'm on vacation but I still want to update my site regularly.

Can you guys point me to any specific tutorial/terminology/methods/programs/codes/anything? All help would be appreciated!

EDIT: Code I have so far (just want to show to Nick)

<html>
<head>
<title>tgh</title>
</head>
<body>
    <?php
        $objConnect = mysql_connect("localhost","root","") or die(mysql_error());
        $objDB = mysql_select_db("thegoodhumor");
        $strSQL = "SELECT * FROM gallery";
        if (!isset($_GET['Page']))  $_GET['Page']='0';
        $objQuery = mysql_query($strSQL);
        $Num_Rows = mysql_num_rows($objQuery);

        $Per_Page = 16;   // Per Page

        $Page = $_GET["Page"];
        if(!$_GET["Page"])
        {
            $Page=1;
        }

        $Prev_Page = $Page-1;
        $Next_Page = $Page+1;

        $Page_Start = (($Per_Page*$Page)-$Per_Page);
        if($Num_Rows<=$Per_Page)
        {
            $Num_Pages =1;
        }
        else if(($Num_Rows % $Per_Page)==0)
        {
            $Num_Pages =($Num_Rows/$Per_Page) ;
        }
        else
        {
            $Num_Pages =($Num_Rows/$Per_Page)+1;
            $Num_Pages = (int)$Num_Pages;
        }

        $strSQL .=" order  by GalleryID ASC LIMIT $Page_Start , $Per_Page";
        $objQuery  = mysql_query($strSQL);
$cell = 0;
echo '<table border="1" cellpadding="2" cellspacing="1"><tr>';
while($objResult = mysql_fetch_array($objQuery))
{
  if($cell % 4 == 0) {
    echo '</tr><tr>';
  }

if($cell == 2) {
    echo '<td>RESERVED</td>';
} elseif ($cell == 3) {
    echo '<td>The other cell</td>';
} else {
    echo '<td><img src="https://s3.amazonaws.com/imagetitle/' . $objResult["Picture"] . '" />' .
    $objResult["GalleryName"] . '</td>'; }
    $cell++;
}
echo '</tr></table>';
    ?>

        <br>
view more:
<?php
        if($Prev_Page)
        {
            echo " <a href='$_SERVER[SCRIPT_NAME]?Page开发者_如何学C=$Prev_Page'>prev</a> ";
        }
            {
                echo "|";
        }
        if($Page!=$Num_Pages)
        {
            echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>next</a> ";
        }
        ?>
</body>
</html>
<?php
mysql_close($objConnect);
?>


It sounds like you want a dynamic web page. To make a dymaic webpage I'd suggest using PHP which would interact with the mysql server.

For example, a user would visit 'mysite.com/info.php?image=367' and the php script would get the information 'image=367'. Your PHP script could do a select query against the mysql database 'SELECT paragraph FROM table WHERE image_id = 367' and then write that data out to the user's web browser.

As far as the user is concerned they just visited 'mysite.com/info.php?image=367', but in the background, PHP dynamically created the webpage content after it got that request.

More basic info about dynamic webpages: http://way.clicktracks.com/help/en/pr650/index.html?dynamicwebsiteshowtheywork.htm

Simple Intro to PHP:
http://www.tizag.com/phpT/

http://www.w3schools.com/php/php_intro.asp

Here is a head start I wrote for you, feel free to use it.

<?php

  if (!isset($_GET['imageNumber'])) 
    die("You must specify an image number");

  $image_requested = mysql_real_escape_string($_GET['imageNumber']);  //sanitizes input

  $dbhost = 'localhost';    //TODO: Set this to the ip address of your mysql server if it is not on the same machine
  $dbuser = 'root';     //TODO: Set the username you use to access your mysql db here
  $dbpass = 'password';     //TODO: Set the password you use to access your mysql db here

  $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

  $dbname = 'database_name_here';  //TODO: Set the database name here 
  mysql_select_db($dbname);

  $query = "SELECT paragraph FROM table_name WHERE image_id = " . $image_requested; //TODO: Set table_name, column to get, and image_id to the correct column name

  $result = mysql_query($query);

  $row = mysql_fetch_array($result) or die(mysql_error());

  echo "Here is the paragraph of text" . $row['paragraph'];  //TODO: Set paragraph to the same column you retrieved 3 lines above.

  mysql_close($conn);

?>

As for the second part of your question, it can also be done with PHP

<?php

$specifictime = strtotime("tuesday 3pm");
if (time("now") > $specifictime)
{
 echo " its after 3pm on tuesday"; 
}
else { 
 echo " not 3pm on tuesday yet"; 
}

?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜