Problem retrieving results from database

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

    Problem retrieving results from database

    Hi all,

    I'm trying to retrieve fields from my database with following mysql
    statement:

    $query = SELECT g_games.Title FROM g_collections, g_personal_revi ews,
    g_games WHERE (g_games.ID=g_p ersonal_reviews .G_ID AND
    g_collections.U _ID = '" . $data1['ID'] . "' AND g_personal_revi ews.C_ID
    = '" . $data2['ID'] . "' ) ";
    $resultset = mysql_query($qu ery);
    $data = mysql_fetch_arr ay($resultset);


    3 Rows in my database comply with the above statement... though I only
    get 1 to show up on my php page? How can I show all of them?

    This is the php code I'm using to write the results:

    while ($data= mysql_fetch_arr ay($resultset))
    {
    echo $data[Title]." ";
    }

    My tables are as followed:
    g_games
    g_collections
    g_personal_revi ews > this table connects all others with G_ID ("game
    ID"), C_ID ("Collection_ID "), U_ID ("User ID)...
    users

  • Jan Pieter Kunst

    #2
    Re: Problem retrieving results from database

    evetommy wrote:[color=blue]
    > Hi all,
    >
    > I'm trying to retrieve fields from my database with following mysql
    > statement:
    >
    > $query = SELECT g_games.Title FROM g_collections, g_personal_revi ews,
    > g_games WHERE (g_games.ID=g_p ersonal_reviews .G_ID AND
    > g_collections.U _ID = '" . $data1['ID'] . "' AND g_personal_revi ews.C_ID
    > = '" . $data2['ID'] . "' ) ";
    > $resultset = mysql_query($qu ery);
    > $data = mysql_fetch_arr ay($resultset);
    >
    >
    > 3 Rows in my database comply with the above statement... though I only
    > get 1 to show up on my php page? How can I show all of them?
    >
    > This is the php code I'm using to write the results:
    >
    > while ($data= mysql_fetch_arr ay($resultset))
    > {
    > echo $data[Title]." ";
    > }
    >
    > My tables are as followed:
    > g_games
    > g_collections
    > g_personal_revi ews > this table connects all others with G_ID ("game
    > ID"), C_ID ("Collection_ID "), U_ID ("User ID)...
    > users
    >[/color]

    Two things: don't do this

    $data = mysql_fetch_arr ay($resultset);

    and this

    while ($data= mysql_fetch_arr ay($resultset)) {
    echo $data[Title]." ";
    }

    both. If you execute both of these statements, the first row never gets
    echo'd. But this would give you two rows in the while loop if the total
    is three. So you should also check if the query actually returns the
    three rows, by doing something like this:

    echo $query;die;

    .... and then copying and pasting the query into the mysql commandline
    client and checking what the actual result is.

    JP

    --
    Sorry, <devnull@cauce. org> is a spam trap.
    Real e-mail address unavailable. 5000+ spams per month.

    Comment

    Working...