PHP/MySQL array w/zero results

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Akhenaten

    PHP/MySQL array w/zero results

    This sql query is good but I'm having trouble echoing the results with
    php (no data echoed). Suggestions?

    *************
    $open_C = 'select * '
    . ' from questions , users '
    . ' where users . username = "X" LIMIT 0, 30 ';

    // Fetch each row of the results into an array $q_row
    while ($q_row = @mysql_fetch_ar ray($open_C))
    {
    echo "ID:\t{$q_r ow['question']}\n";

    }

    *************

    Thank you.

  • Schraalhans Keukenmeester

    #2
    Re: PHP/MySQL array w/zero results

    At Wed, 16 May 2007 12:37:29 -0700, Akhenaten let his monkeys type:
    This sql query is good but I'm having trouble echoing the results with
    php (no data echoed). Suggestions?
    >
    *************
    $open_C = 'select * '
    . ' from questions , users '
    . ' where users . username = "X" LIMIT 0, 30 ';
    >
    // Fetch each row of the results into an array $q_row
    while ($q_row = @mysql_fetch_ar ray($open_C))
    {
    echo "ID:\t{$q_r ow['question']}\n";
    >
    }
    >
    *************
    >
    Thank you.
    You have to open a connection to the db and execute the query first, then
    fetch rows on the result resource:

    <?PHP
    $conn = @mysql_connect( $host,$user,$pa ss)
    or die (mysql_error()) ;
    @mysql_select($ dbname)
    or die (mysql_error()) ;
    $result = mysql_query($op en_C, $conn)
    or die (mysql_error()) ;
    while ($row = mysql_fetch_ass oc($result))
    // use mysql_fetch_ass oc to get the associative array only.
    {
    echo "ID:\t{$q_r ow['question']}\n";
    }
    ?>

    HTH
    Sh.

    Comment

    Working...