これらのコード行をじっと見つめ、複数のコーディング フォーラムで何時間も調査した後、完全には機能しない自分のコードに行き詰まりました。この PHP スクリプトを正常に実行して、テキストの引用を MySQL テーブルからランダムにクエリし、Web サイトのフッターに表示できるようにしようとしています。見積もりは、ユーザーが Web サイトを更新するたびに変更する必要があります。また、各引用が表示された回数を数えようとしています。特定の引用が私のウェブサイトに表示されると、その特定の引用が何回表示されたかをサイトのユーザーに知らせます。これまでの私のコードは次のとおりです。
<?php
include('Includes/inc_connect.php');
$DBName = 'database';
if (!@mysql_select_db($DBName, $DBConnect))
echo "<p style='text-align:center'>There are no quotes to view!</p>";
else {
$TableName = "randomquote";
$SQLstring = "SELECT quote FROM $TableName";
//executes the query
$QueryResult = @mysql_query($SQLstring, $DBConnect);
if ($QueryResult === false)
{
echo "<p>Unable to retrieve the data.</p>" . "<p>Error code: " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "</p>";
}
else
{
$quote_array = array();//Creates a blank array
//use a while loop to extract the data from the database table into an indexed array
while(($Row = mysql_fetch_row($QueryResult)) !== FALSE)
{
$quote_array = $Row[0];
}
}
//assign the contents of the table to an array variable
$quote_count=count($quote_array);
$RandomArrayIndex = rand(0, $quote_count-1);
$quote = stripslashes($quote_array[$RandomArrayIndex]);
$SQLString = "UPDATE randomquote SET display_count " . " = display_count + 1 WHERE quote = " . $quote_array[$quote];
$SQLString = "SELECT display_count from randomquote WHERE quote = " . $quote_array[$quote];
$display_count = @mysql_query($SQLString, $DBConnect);
//display the random quote on the Web page
echo "<p style='text-align:center;font-style:italic'><strong>" . $quote . "</strong></p>\n";
echo "<p style='text-align:center>This quote has displayed " . $display_count . " times.</p>/n";
}
else
{
//specify that the comments cannot be read
echo "<p>The quote cannot be displayed at this time</p>\n";
}
else
{
//specify that there are no quotes
echo "<p>There are no quotes to display.</p>\n";
}
私は PHP と MySQL の両方の学生であるため、すべてのヘルプとアドバイスは大歓迎です。本当にありがとう!