Re: Problem retrieving results from database



evetommy wrote:
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_reviews,
g_games WHERE (g_games.ID=g_personal_reviews.G_ID AND
g_collections.U_ID = '" . $data1['ID'] . "' AND g_personal_reviews.C_ID
= '" . $data2['ID'] . "' )  ";
$resultset = mysql_query($query);
$data = mysql_fetch_array($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_array($resultset))
{
echo $data[Title]." ";
}

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


Two things: don't do this

$data = mysql_fetch_array($resultset);

and this

while ($data= mysql_fetch_array($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@xxxxxxxxx> is a spam trap.
Real e-mail address unavailable. 5000+ spams per month.
.



Relevant Pages

  • Re: Problem with SQL and Recordset
    ... This assumes that the name of the subform control on the parent form is the ... NextSuffix field from the "query" to be entered into the Suffix field on ... Dim mySQL As String ...
    (microsoft.public.access.modulesdaovba)
  • Re: [Q]Problems related to the MySQL linked Server.
    ... The error messge when I query data with following SQL. ... select @v_intUserNo = uno ... where userid = 'testid' ... I have two questions about the linked server for the MySQL. ...
    (microsoft.public.sqlserver.odbc)
  • Re: Performance MySQL
    ... schicke erst den Query an die Datenbank ab, ... Möglichkeit von Concurrent Inserts nur MyISAM Storages ein. ... > MySQL bis jetzt noch nichts zu bieten. ... Welcher Tabellentyp? ...
    (de.comp.datenbanken.mysql)
  • Re: where to get mySQL questions answered?
    ... After resolving some performance issues with mysql in building initial ... soon as I add an OR to my WHERE x LIKE '%blah%' type queries. ... My php code dynamically builds an sql query. ...
    (comp.lang.php)
  • Re: Copying Binary data from one table to another
    ... only if you use parameters for user inputs - in other words don't ask the ... I'm not sure of the syntax used in MySQL to update a ... This email account is my spam trap so I ...
    (microsoft.public.inetserver.asp.db)