Jump to content

Link two tables but limit results


adzie

Recommended Posts

Hello all,

 

Appreciate your advice as i've hit a wall now

 

Table 1 - user_awards

award_id

award_title

 

Table 2 - awards

user_id

(a column for each award_id) 0 = no, 1 = yes

 

 

I'd like to ideally create a result where it then displays all the records where the column in table 2 is 1 but I want to limit it to say 5 where the user_awards table = 1, however at present it counts five including entries where its 0.  This is where i'm getting unstuck so appreciate any advice.  Code snippet below.

 

 

 

  $awardCodes = mysql_query("SELECT * FROM `user_awards` WHERE `user_id` = 1"); 
  $awardsres = mysql_fetch_assoc($awardCodes);
  $awards = mysql_query("SELECT * FROM `awards` ORDER BY 'award_id' ASC LIMIT 4");  

  // Loop through award codes
  while ($ac2 = mysql_fetch_assoc($awards)) {  
  $ac22 = db_entry_check($awardsres[$ac2[award_id]])? 1 : 0; 
   
  if ($ac22 != $actual && $ac22 == 1) {
  
echo "$ac22[award_title]";

   }
   
   }

 

Link to comment
https://forums.phpfreaks.com/topic/257620-link-two-tables-but-limit-results/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.