Author Topic: query problems  (Read 260 times)

yguyjosh

  • New Member
  • *
  • Posts: 4
  • Karma: 0
    • View Profile
query problems
« on: February 20, 2012, 09:14:03 AM »
So for some, probably very obvious reason, this is only giving me the first result from the database even though there are more that meet the criteria.  Could someone please tell me what I'm doing wrong.  I know it must be something simple but I'm totally stumped. 

Code: [Select]
[php]
$query1 = "SELECT interest
FROM interests
WHERE profileid = '{$profileid}'
";
$result1 = mysql_query($query1, $connection) or die(mysql_error());
$savedinterests = mysql_fetch_assoc($result1);
print_r($savedinterests);
[/php]

jj-dr

  • Senior Member
  • ****
  • Posts: 216
  • Karma: 3
    • View Profile
Re: query problems
« Reply #1 on: February 20, 2012, 01:09:25 PM »
Try removing the curly brackets in this query:
PHP Code: [Select]
WHERE profileid '{$profileid}'

It should be
PHP Code: [Select]
 WHERE profileid '$profileid'


If that doesn't do the trick I would add a WHILE loop.


PHP Code: [Select]

$query1 
=    "SELECT interest
         FROM interests
         WHERE profileid = '
{$profileid}'
         "
;
$result1 mysql_query($query1$connection) or die(mysql_error());

WHILE (
$savedinterests mysql_fetch_assoc($result1)){
print 
$savedinterests;
}

« Last Edit: February 20, 2012, 01:26:40 PM by jj-dr »