PHP Detail Page

Discussion in 'OT Technology' started by frustrated inc., May 2, 2005.

  1. In a populated table, there is a field called movie_image

    On the PHP page, movies are listed within a table. Some movies have a value for movie_image, but not all of them. For the ones that do have a value, I want to display a link that goes to the item's detail page.

    Question:

    How can I have a link visible only if a field within a database holds a value?
     
  2. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,923
    Likes Received:
    11
    Location:
    Los Angeles
    Code:
    $sql = "SELECT movie_image FROM movies";
    $query = mysql_query(mysql_fetch_array($sql));
    if (isset($query["movie_image"])) {
          echo "your link";
    }
    
     
  3. Thanks for the help..

    Code:
    $query = mysql_query(mysql_fetch_array($sql));
    This little bit is giving me arguement errors.. Ive tried rearranging the placement of the code (though it shouldn't matter).. but no matter where it's going, same argument error.
     
  4. MrMan

    MrMan New Member

    Joined:
    Jul 13, 2004
    Messages:
    308
    Likes Received:
    0
    try $query=mysql_query($sql, $conn);

    where $conn is
    $conn = mysql_connect("servername", "database_name", "password")

    ...

    Another solution is using the query as
    $query = "SELECT movie_image FROM movies WHERE movie_image != NULL
    or
    $query = "SELECT movie_image FROM movies WHERE movie_image != ""

    depending on how you defined the blank value.

    kingtoad's method retrieves all movie_image values, and then filter them out using PHP.

    this method only selects the movie_image values not blank, letting mysql handle the work.
     
  5. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,923
    Likes Received:
    11
    Location:
    Los Angeles
    :werd: That's probably a better way to do it. Although, I do think the not equal to operator is '<>'
     

Share This Page