Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Trouble with geting data

Codes here !

Moderators: macek, egami, gesf

Trouble with geting data

Postby Jakbaehl » Sat Apr 28, 2012 1:23 pm

Hi all gurus and gurettes.

I have tryed to make a bit of code for some time now, but i am just to stoopid to be able to.

This is my code:
Code: Select all
            
$db = JFactory::getDBO();
$query = "SELECT * FROM lbzi4_users INNER JOIN lbzi4_jvarcade ON lbzi4_users.id=lbzi4_jvarcade.userid where userid=42 order by date DESC LIMIT 5";
$db->setQuery($query);
$rows = $db->loadObjectList();
echo "<div class=\"UserGames\"><h6>" .$nfUser. "'s most recent games:</h6><br>";
echo "<table cellspacing='0' cellpadding='0'>";
foreach ( $rows as $row ) {
$theGameId = $row->gameid;
$query2 = "SELECT * FROM lbzi4_jvarcade_games where id='$theGameId'";
$db->setQuery($query2);
$rows = $db->loadObjectList();
foreach ( $rows as $row ) {
echo $row->gamename;
echo "<br>";
}
}

Its from the line that starts with $query2 thats the problem.
This is only my latest try, and i know its wacked, because it, well... don't work :)
I am sure you see what i am trying to do here. Help? Please? Someone?
Jakbaehl
New php-forum User
New php-forum User
 
Posts: 5
Joined: Sat Apr 28, 2012 1:15 pm

Re: Trouble with geting data

Postby minimihi » Sat Apr 28, 2012 2:28 pm

First time you load selection result to $rows and then again, while looping through $rows you redefine it with second selection result.

should be
Code: Select all
foreach ( $rows as $row ) {
   $theGameId = $row->gameid;
   $query2 = "SELECT * FROM lbzi4_jvarcade_games where id='$theGameId'";
   $db->setQuery($query2);
   $rows2 = $db->loadObjectList();
   foreach ( $rows2 as $row2 ) {
      echo $row2->gamename;
      echo "<br>";
      }
   }
User avatar
minimihi
New php-forum User
New php-forum User
 
Posts: 238
Joined: Sat Apr 14, 2012 11:57 am
Location: Vilnius, Lithuania

Re: Trouble with geting data

Postby Jakbaehl » Sun Apr 29, 2012 2:01 am

That fixed everything just fine :D

Thank you minimihi!
Jakbaehl
New php-forum User
New php-forum User
 
Posts: 5
Joined: Sat Apr 28, 2012 1:15 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.