Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. update and view news headline

update and view news headline

Scheduled Pinned Locked Moved Database
databasequestionannouncementphpmysql
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jassim Rahma
    wrote on last edited by
    #1

    I am using this code to view a news headline from mysql table but I want also to add one more thing please... I want to update a field named news_views (int) with +1 everytime someone views this article.. how can I do this please...

    <?php
    $news_id = $_GET['id'];

    $conn = mysql_connect('mysql.jassimrahma.com', 'jassimdb', 'xxxxxxx');
    $sql = "SELECT * FROM news WHERE news_id = '$news_id'";
    mysql_select_db("jassimrahma", $conn) or die(mysql_error());
    $result = mysql_query($sql, $conn) or die(mysql_error());
    $count = mysql_num_rows($result);

    if($count == 1)
    {
    $db_field = mysql_fetch_assoc($result);
    $news_url = $db_field['news_url'];
    $news_title = $db_field['news_title'];
    $news_webpage = file_get_contents($news_url);
    // $news_webpage = file_get_contents('http://www.businessweek.com/ap/financialnews/D9RH5MEO0.htm');
    echo $news_webpage;
    }
    else
    {
    header("location:index.php");
    }
    ?>

    W 1 Reply Last reply
    0
    • J Jassim Rahma

      I am using this code to view a news headline from mysql table but I want also to add one more thing please... I want to update a field named news_views (int) with +1 everytime someone views this article.. how can I do this please...

      <?php
      $news_id = $_GET['id'];

      $conn = mysql_connect('mysql.jassimrahma.com', 'jassimdb', 'xxxxxxx');
      $sql = "SELECT * FROM news WHERE news_id = '$news_id'";
      mysql_select_db("jassimrahma", $conn) or die(mysql_error());
      $result = mysql_query($sql, $conn) or die(mysql_error());
      $count = mysql_num_rows($result);

      if($count == 1)
      {
      $db_field = mysql_fetch_assoc($result);
      $news_url = $db_field['news_url'];
      $news_title = $db_field['news_title'];
      $news_webpage = file_get_contents($news_url);
      // $news_webpage = file_get_contents('http://www.businessweek.com/ap/financialnews/D9RH5MEO0.htm');
      echo $news_webpage;
      }
      else
      {
      header("location:index.php");
      }
      ?>

      W Offline
      W Offline
      Wayne Gaylard
      wrote on last edited by
      #2

      I think you will get more response from the PHP forum. :)

      When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups