Jump to content

john010117

Members
  • Posts

    492
  • Joined

  • Last visited

    Never

Posts posted by john010117

  1. That means that your username/password to link to the MySQL database is incorrect. Make sure you have the right user/pass. Your connection code should look something like this:

     

    <?php
    
    // Connect to the database
    $host = "localhost"; // db host
    $user = "***"; // db username
    $pass = "***"; // db password
    $db = "***"; // db name
    
    $connection = mysql_connect ($host, $user, $pass) or die ("Unable to connect"); 
    mysql_select_db ($db) or die ("Unable to select database"); 
    ?>
    

  2. I don't believe I'm missing a } at the end of the script (just ran it through Notepad 2). I'm getting the error that I have coded in: "The search failed to find the title of the Bungie Weekly Update story. Please make sure that the title is EXACT and the spelling is correct. Please try again or see the list of all the updates here".

  3. Ok, I've changed that also. But the second page still shows the "not found" message.

     

    <?php
    if ($_GET['type'] == "title") {
    
       if(!isset($_GET['page'])){
           $page = 1;
       } else {
           $page = $_GET['page'];
       }
    
       $max_results = 10;
       $from = (($page * $max_results) - $max_results); 
       $result = mysql_query ("SELECT * FROM bnetupdates WHERE title = '$_GET[word]' LIMIT $from, $max_results");
    
       if(mysql_num_rows($result)>0)
       {
        while ($row = mysql_fetch_assoc($result)) {
           extract($row);
              print "<p><table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">
              <tr><td><img src=\"$image\"></td><td valign=\"center\"><a href=\"archive.php?id=$id\">$title</a><br /><font size=\"1\">Posted on: $date</font></td></tr></table></p>";
           }
    
       $total_results_q = mysql_query("SELECT * FROM bnetupdates");
       $total_results = mysql_num_rows($total_results_q);
       $total_pages = ceil($total_results / $max_results);
       echo "<center>Select a Page<br />";
    
       if($page > 1){
           $prev = ($page - 1);
           echo "<a href=\"".$_SERVER['PHP_SELF']."?word=$word&type=title&page=$prev\"><<Previous</a> ";
       }
    
       for($i = 1; $i <= $total_pages; $i++){
           if(($page) == $i){
               echo "$i ";
               } else {
                   echo "<a href=\"".$_SERVER['PHP_SELF']."?word=$word&type=title&page=$i\">$i</a> ";
           }
       }
    
       if($page < $total_pages){
           $next = ($page + 1);
           echo "<a href=\"".$_SERVER['PHP_SELF']."?word=$word&type=title&page=$next\">Next>></a>";
           }
       }
       else{
            print "<p>The search failed to find the title of the Bungie Weekly Update story. Please make sure that the title is EXACT and the spelling is correct. Please try again or see the list of all the updates <a href=\"archive.php\">here</a>.</p>";
           }
       }
    ?>
    
    Any suggestions?

  4. Try this:

    <?php
    
    // Connect to the database
    $host = "HOST"; // db host
    $user = "USERNAME"; // db username
    $pass = "PASSWORD"; // db password
    $db = "DATABASE NAME"; // db name
    
    $connection = mysql_connect ($host, $user, $pass) or die ("Unable to connect"); 
    mysql_select_db ($db) or die ("Unable to select database"); 
    ?>
    

     

    Remember to replace all the capitalized words with your own.

  5. Ok, I changed that to this:

    if ($_GET['type'] == "title") {
    
       if(!isset($_GET['page'])){
           $page = 1;
       } else {
           $page = $_GET['page'];
       }
    
       $max_results = 10;
       $from = (($page * $max_results) - $max_results); 
       $result = mysql_query ("SELECT * FROM bnetupdates WHERE title = '$word' LIMIT $from, $max_results");
    
       if(mysql_num_rows($result)>0)
       {
        while ($row = mysql_fetch_assoc($result)) {
           extract($row);
              print "<p><table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">
              <tr><td><img src=\"$image\"></td><td valign=\"center\"><a href=\"archive.php?id=$id\">$title</a><br /><font size=\"1\">Posted on: $date</font></td></tr></table></p>";
           }
    
       $total_results_q = mysql_query("SELECT * FROM bnetupdates");
       $total_results = mysql_num_rows($total_results_q);
       $total_pages = ceil($total_results / $max_results);
       echo "<center>Select a Page<br />";
    
       if($page > 1){
           $prev = ($page - 1);
           echo "<a href=\"".$_SERVER['PHP_SELF']."?word=$word&type=title&page=$prev\"><<Previous</a> ";
       }
    
       for($i = 1; $i <= $total_pages; $i++){
           if(($page) == $i){
               echo "$i ";
               } else {
                   echo "<a href=\"".$_SERVER['PHP_SELF']."?word=$word&type=title&page=$i\">$i</a> ";
           }
       }
    
       if($page < $total_pages){
           $next = ($page + 1);
           echo "<a href=\"".$_SERVER['PHP_SELF']."?word=$word&type=title&page=$next\">Next>></a>";
           }
       }
       else{
            print "<p>The search failed to find the title of the Bungie Weekly Update story. Please make sure that the title is EXACT and the spelling is correct. Please try again or see the list of all the updates <a href=\"archive.php\">here</a>.</p>";
           }
       }
    

     

    ...but it still doesn't work. First page (w/o ?page=1 in the URL) shows up fine, but the next page doesn't show up. Can you see any additional problems with the code?

  6. Let me first show you the part of the code I'm having trouble with.

     

    if ($_GET['type'] == "title") {
    
       if(!isset($_GET['page'])){
           $page = 1;
       } else {
           $page = $_GET['page'];
       }
    
       $max_results = 10;
       $from = (($page * $max_results) - $max_results); 
       $result = mysql_query ("SELECT * FROM bnetupdates WHERE title = '$word' LIMIT $from, $max_results");
    
       if(mysql_affected_rows()>0)
       {
        while ($row = mysql_fetch_assoc($result)) {
           extract($row);
              print "<p><table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">
              <tr><td><img src=\"$image\"></td><td valign=\"center\"><a href=\"archive.php?id=$id\">$title</a><br /><font size=\"1\">Posted on: $date</font></td></tr></table></p>";
           }
    
       $total_results_q = mysql_query("SELECT * FROM bnetupdates");
       $total_results = mysql_affected_rows($total_results_q);
       $total_pages = ceil($total_results / $max_results);
       echo "<center>Select a Page<br />";
    
       if($page > 1){
           $prev = ($page - 1);
           echo "<a href=\"".$_SERVER['PHP_SELF']."?word=$word&type=title&page=$prev\"><<Previous</a> ";
       }
    
       for($i = 1; $i <= $total_pages; $i++){
           if(($page) == $i){
               echo "$i ";
               } else {
                   echo "<a href=\"".$_SERVER['PHP_SELF']."?word=$word&type=title&page=$i\">$i</a> ";
           }
       }
    
       if($page < $total_pages){
           $next = ($page + 1);
           echo "<a href=\"".$_SERVER['PHP_SELF']."?word=$word&type=title&page=$next\">Next>></a>";
           }
       }
       else{
            print "<p>The search failed to find the title of the Bungie Weekly Update story. Please make sure that the title is EXACT and the spelling is correct. Please try again or see the list of all the updates <a href=\"archive.php\">here</a>.</p>";
           }
       }
    

     

    It shows the first page of results just fine (without the page variable in the URL). But whenever I go to another page of results, it shows "The search failed to find..." error message. Can anyone help please?

  7. Ok, I have a problem. I have a code (mostly built from the ground-up by myself with a little help from others) to have a simple news system. The two main variables I have problems with are "Date" and "id". I so far have the script set up so that when a user types in "index.php?Date=whatever", it'll show all the news for that date. If a user types in "index.php?id=whatever", it only shows that specific news post. So far so good. Let me show you a part of the script first.

     

    $Date variable script:

    if($_GET['date']) {
      // Get date from _GET param or current date if not available
      $_GET['date'] = @trim(stripslashes($_GET['date']));
      $date = ($_GET['date'] && !empty($_GET['date'])) ? date('Y-m-d', strtotime(trim($_GET['date']))) : date('Y-m-d');
      
      $result = mysql_query('SELECT * FROM news WHERE Date = "' . $date . '" ORDER BY Time');
      $curtime = time();
      if ($result && mysql_num_rows($result)) {
        $numrows = mysql_num_rows($result);
        $rowcount = 1;
             
    while ($row = mysql_fetch_assoc($result)) { 
      print "<b>{$row['Title']}</b><br />
    {$row['News']}<br />
    <span style=\"font-size:10px\"><b>Posted by:</b> {$row['Posted_by']}   ({$row['Date']}   {$row['Time']})   <a href=\"http://www.allaroundhalo.org/index.php?id={$row['id']}\">Permalink</a>)</span><br /><br />"; 
    }      
          print "<br />";
          ++$rowcount;
        }     
    }
    

     

    I need to have the script check today's date and get news for today if the "?date=" part isn't typed in the URL (ex: index.php). BUT I can't allow today's news to show when a user is requesting a specific date or id. Any suggestions? Any help will be appreciated.

  8. Hello.

    I have simple news management system on my index.php page. The following is the code for the main part of the code.

     

    <?php
      
    include 'info.php'; ?>
      
      // Connect to server
      $dbac = mysql_connect($db_host,$db_user,$db_pass); 
      $today = getdate();
      
      // Select database
      mysql_select_db ($db_name) or die ("Cannot connect to database");
      
      // Get date from _GET param or current date if not available
      $_GET['date'] = @trim(stripslashes($_GET['date']));
      $date = ($_GET['date'] && !empty($_GET['date'])) ? date('Y-m-d', strtotime(trim($_GET['date']))) : date('Y-m-d');
      
      $result = mysql_query('SELECT * FROM news WHERE Date = "' . $date . '" ORDER BY Time');
      $curtime = time();
      if ($result && mysql_num_rows($result)) {
        $numrows = mysql_num_rows($result);
        $rowcount = 1;
             
    while ($row = mysql_fetch_assoc($result)) { 
      print "<b>{$row['Title']}</b><br />
    {$row['News']}<br />
    <b>Posted by:</b> {$row['Posted_by']}   ({$row['Date']}   {$row['Time']})<br /><br />"; 
    }      
          print "<br />";
          ++$rowcount;
        }
      
    ?> 
    

     

    I have other pages that have coding related to this, but I believe that this is the main part. It works fine, but it takes a while for the page to load (compared to the loading time without the code, which takes less than a second). Is there any way to speed it up?

  9. Hello.
    I have this code:

    [code=php:0]
    <?php
     
      // Connection information
      $db_host = "localhost";
      $db_user = "**";
      $db_pass = "**";
      $db_name = "**";
     
      // Connect to server
      $dbac = mysql_connect($db_host,$db_user,$db_pass);
      $today = getdate();
     
      // Select database
      mysql_select_db ($db_name) or die ("Cannot connect to database");
     
      // Get date from _GET param or current date if not available
      $_GET['date'] = @trim(stripslashes($_GET['date']));
      $date = ($_GET['date'] && !empty($_GET['date'])) ? date('Y-m-d', strtotime(trim($_GET['date']))) : date('Y-m-d');
     
      $result = mysql_query('SELECT * FROM news WHERE Date = "' . $date . '" ORDER BY Time');
      $curtime = time();
      if ($result && mysql_num_rows($result)) {
        $numrows = mysql_num_rows($result);
        $rowcount = 1;
       
        while ($row = mysql_fetch_assoc($result)) {
         
          while(list($var, $val) = each($row)) {
            extract ($row);
            print "<b>$Title</b><br />$News<br /><font size='2'>$Date &nbsp; $Time</font><br />";
          }
         
          print "<br />";
          ++$rowcount;
        }
      }
     
    ?> 
    [/code]

    I have a table (called news) in a MySQL database with 5 fields: (News, Title, Date, Time). The code works. However, when I display the results, it shows the same thing 5 times.

    This is what shows:

    [quote]
    [b]News system up and running![/b]
    We finally have this news system working. If you want to see older news (by date), just click the arrow on top.
    2007-01-12 13:12:42

    [b]News system up and running![/b]
    We finally have this news system working. If you want to see older news (by date), just click the arrow on top.
    2007-01-12 13:12:42

    [b]News system up and running![/b]
    We finally have this news system working. If you want to see older news (by date), just click the arrow on top.
    2007-01-12 13:12:42

    [b]News system up and running![/b]
    We finally have this news system working. If you want to see older news (by date), just click the arrow on top.
    2007-01-12 13:12:42

    [b]News system up and running![/b]
    We finally have this news system working. If you want to see older news (by date), just click the arrow on top.
    2007-01-12 13:12:42
    [/quote]

    How can I make it so that it only shows a news post ONCE?

    PS: I think it's because of the extract($row) thing.
  10. Ok, I have the following.
    [code]
    <?php
    // Connection information
    $db_host = "localhost";
    $db_user = "**";
    $db_pass = "**";
    $db_name = "**";

    // Connect to server
    $dbac = mysql_connect($db_host,$db_user,$db_pass);

    // Select database
    mysql_select_db ($db_name) or die ("Cannot connect to database");

    $result = mysql_query("SELECT * FROM news WHERE Date");

    if ($result && mysql_num_rows($result)) {
          $numrows = mysql_num_rows($result);
          $rowcount = 1;
           
          while ($row = mysql_fetch_assoc($result)) {
               
            while(list($var, $val) = each($row)) {
                print "<B>$var</B>: $val<br />";
            }
     
            print "<br />";
            ++$rowcount;
          }
      }
    ?>
    [/code]

    I have a table named "news", and 3 fields: "News", "Posted_by", "Date" (in DATE format). I can retrieve the data from the database.

    All I need is a way to only view the news posted for that day using dynamic URL's (index.php?Date=2007-01-07) should only show news posted on Jan. 7, 2007. Can anybody point me the right way?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.