Fork me on GitHub

PHP Questions  Bottom

  • I kinda picked up on it a bit from trying to figure postnuke/pagesetter plugins out but there's some things that confuse me and I havent found answers to on other sites, I'll post them as I come accross them but the stuff is way sloppy cause my scripting sucks, so hoping if any you experts can give me advice on PHP too that would be cool


    Here's one major issue I'm facing n dunno how to fix, if a mysql query returns nothing I get an error, what's the proper way to handle an empty query?

    my unorthodox metho icon_lol

    Code

    $query = mysql_query("SELECT pg_author, pg_pid FROM nuke_pagesetter_pubdata1 WHERE pg_author='Admin'") or die(mysql_error());

    $exists = mysql_result($query,0,"pg_author");

    if ($exists == "Admin") {
    do this because the query returned a result
    } else {
    do nothing
    }


    i get this error sometimes even t hough everything still works
    mysql_result(): Unable to jump to row 0 on MySQL result index
  • Here's how I've done it in an application I'm working on:

    Code

    function view_current() {

      $FF_Y = date(Y);

      $result = mysql_query("SELECT * FROM ff_data WHERE ff_date = '$FF_Y'")
            or die ("SELECT error: ".mysql_error());

      //TAKES CARE OF A ZERO $result BY RETURNING FALSE
      if(mysql_num_rows($result) < 1) return false;
     
      // ONLY RETURNS $result IF $result > 0
      return $result;

    }


    Hope that helps...
  • that just what I needed, I've used numrows a few times but never thought of using it for that. Thx!
  • Glad to help.

This list is based on users active over the last 60 minutes.