Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    May 2005
    Posts
    5
    Member #
    9893
    hello

    I make a page for news partal and I make a database named (newsdb) contain a table named (news) with four fields (index_id,date,title,news text) and show them on a page named (news.php) and have no proplem on this, but I don't know how to make a link for the news text when someone click the title.
    I write this code:

    $top=mysql_db_query("newsdb","select*from news order by index_id DESC");
    while($row=mysql_fetch_array($top)){

    print "<p><pre><b><font color=red>$row[index_id]</font> <font color=blue>$row[date]</font> <font color=green><a href=view.php>$row[title]</a></font> $row[newstext]</b></pre></p>";


    but it don't work:

    <a href=view.php>$row[title]</a>

    when I click the link it only open a page (view.php) with nothing on it.

    on the news websites when I click the title link a new window will open with the full news text and I don't know how to make the same thing, please help because I am new on php script.

    thanks.

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    The code for view.php should be something like:
    PHP Code:
    <?php

    $id 
    $_GET['id'];
    $id trim($id);
    if(!
    is_numeric($id))
      exit;

    $select_q "SELECT * FROM news WHERE index_id = '$id'";
    $result mysql_query($select_q) or die("Error in select - " mysql_error());

    if(
    mysql_num_rows($result) > 0)
       {
          while 
    $row mysql_fetch_array(result))
             {
                 
    extract($row);
                 echo 
    "<p>$date</p>";
                 echo 
    "<p>$title</p>";
                 echo 
    "<p>$newstext</p>";
             }
        }
    ?>
    An example url to that file: file.php?id=123

  4. #3
    Junior Member
    Join Date
    May 2005
    Posts
    5
    Member #
    9893
    thank you very much bfsog, Coder, yes it work finally!! only I faced one error :

    "5Error in select - No Database Selected"

    So I put "mysql_conect" and it work very good, and I want to post the full script so maybe some php beginner like me will find it useful:

    A simple news php page:

    First page "show.php":

    <!doctype html public "-//W3C//DTD HTML 4.0 //EN">
    <html>
    <head>
    <title>Title here!</title>
    </head>
    <body>
    <?
    $link = mysql_connect("localhost","root");

    $top=mysql_db_query("newsdb","select*from news order by index_id DESC");

    while($row=mysql_fetch_array($top))
    {
    print "<p><pre><b><font color=red>$row[index_id]</font> <font color=blue>$row[date]</font> <font color=green><a href=view.php?id=$row[index_id]>$row[title]</a></font> $row[newstext]</b></pre></p>";
    }
    ?>
    </body>
    </html>


    second page "view.php":

    <!doctype html public "-//W3C//DTD HTML 4.0 //EN">
    <html>
    <head>
    <title>Title here!</title>
    </head>
    <body>
    <?php
    $id = $_GET['id'];
    $id = trim($id);
    $link = mysql_connect("localhost","root");
    $db_selected = mysql_select_db('newsdb', $link);
    if (!$db_selected) {
    die ('Can\'t use newsdb : ' . mysql_error());
    }


    $select_q = "SELECT * FROM news where index_id = '$id'";

    $result = mysql_query($select_q) or die("Error in select - " . mysql_error());

    if(mysql_num_rows($result) > 0)
    {
    while ($row = mysql_fetch_array($result))
    {
    extract($row);
    echo "<p>$date</p>";
    echo "<p>$title</p>";
    echo "<p>$newstext</p>";
    }
    }
    ?>
    </body>
    </html>


    And I wish some php pro will post a real pro news portal script.

    Thanks.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:30 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com