Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Getting one column from MySQL table

    Index.php
    PHP Code:
    <?php

    include 'dbconnect.php';

    $query="SELECT * FROM news";

    $result=mysql_query($query);

    while (
    $row mysql_fetch_array($result))
    {
    extract($row);

    echo 
    "$title <br />";
    echo 
    "$day $month $year <br />";
    echo 
    "$entry <br />";
    echo 
    "Posted in: $category";
    echo 
    "<a href=\"post.php?id=$id\">Permalink</a>";

    }
    ?>
    post.php
    PHP Code:
    <?php

    $id 
    $_GET['id'];

    include 
    'dbconnect.php';

    $getsignle mysql_query("SELECT column FROM table
    WHERE id = $id"
    );

    $row "mysql_fetch_array($getsingle)";

    $title '$row["title"]';
    $entry '$row["entry"]';
    $year '$row["year"]';
    $month '$row["month"]';
    $day '$row["day"]';
    $category '$row["category"]';

    echo 
    "$title <br />";
    echo 
    "$tentry <br />";
    echo 
    "$day ";
    echo 
    "$month ";
    echo 
    "$year <br />";
    echo 
    "$category";

    ?>
    At index.php, I loop all the columns from the mysql table. I have a link that takes you to post.php?id=$id
    At post.php, I want to only display the column where the field id = $id. But when I go to post.php?id=1
    I only get this
    $row["title"]

    $row["day"] $row["month"] $row["year"]
    $row["category"]

  • #2
    New Coder
    Join Date
    Feb 2005
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    $row = "mysql_fetch_array($getsingle)";

    try:

    $row = mysql_fetch_array($getsingle);

  • #3
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I got when I tried that

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/thomas/public_html/news/post.php on line 10
    $row["title"]

    $row["day"] $row["month"] $row["year"]
    $row["category"]

  • #4
    New Coder
    Join Date
    Feb 2005
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    is the name of your column "column" ?

  • #5
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by kaydara
    is the name of your column "column" ?
    Hehe I just noticed

    I got it working now, I just used the extract($row)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •