Jump to content

Recommended Posts

Ok Im making a forum there are three Tables forum_cat forum_question forum_answer and i want to show a users most recent posts so a users post could be a question or answer so there is 2 sql commands

<?php 
$sql="SELECT * FROM forum_question WHERE username = '$req_user' ";
$sql2="SELECT * FROM forum_answer WHERE username = '$req_user' ";

that grabs the data is there any way to combine the data and limit the amout show of rows to say 6 the Loop

$result=mysql_query($sql);
while($row = mysql_fetch_array($result)){

echo $row['fname'];
  

Link to comment
https://forums.phpfreaks.com/topic/150610-combining-search-results/
Share on other sites

Try something like:

 

$sql = "SELECT * FROM forum_question fq LEFT JOIN forum_answer fa ON fq.id = fa.id WHERE fa.username = q_user'  ORDER BY date DESC LIMIT 6";

 

You have to join on the common columns to prevent duplicates.  It also ORDERS BY date DESC (if you have a date field or something similar) so it will grab the most recent posts and finally does LIMIT 6 which only grabs 6 records.  Hope this is what you're looking for.

I think this will work but im haveing trouble under standing your syntax

These are the question and answers tables

Question

   id int(4)        
  topic varchar(255)                 
  detail    
  name varchar(65)         
  datetime varchar(25)              
  view int(4)         
  reply int(4)                
  cat varchar(6)             
      

Answers

  question_id int(4)      
  a_id int(4)             
  a_name varchar(65)                 
  a_email varchar(65)                 
  a_answer                 
  a_datetime varchar(25)                 
  cat varchar(6)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.