Jump to content
DevFuse Forums

Data from different tables


ShaneV

Recommended Posts

Hi,

 

I had this problem before (sort of) here: http://www.devfuse.com/forums/index.php?s=...post&p=8810

 

I need data from different tables

 

You can search on userid or username, i want to display results like this:

 

In Forum: In Topic: Topic starter: Topic start date:

Forumname Title (url) Author name 0000-00-00 00:00

 

I get no results, page keeps loading and loading and stops after a while.

 

													while( $row7 = $this->ipsclass->DB->fetch_row() )
												{
													$startdate = date("d-m-Y", $row7['post_date']);

													$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'topics', 'tid' => $row7['topic_id'] ) );
													$this->ipsclass->DB->simple_exec();
													$row8 = $this->ipsclass->DB->fetch_row();

													$output .= "<tr>
														<td class='row1' valign='top'></td>
														<td class='row2' valign='top'>".$row8['title']."</td>
														<td class='row1' valign='top'>".$row7['author_name']."</td>
														<td class='row1' valign='top'>".$startdate."</td>								
													  </tr>";
												}

 

And i need another query for getting the name of the forum i guess? Is there a better way? :s

Thx

Link to comment
Share on other sites

  • Management
Hi,

 

I had this problem before (sort of) here: http://www.devfuse.com/forums/index.php?s=...post&p=8810

 

I need data from different tables

 

You can search on userid or username, i want to display results like this:

 

In Forum: In Topic: Topic starter: Topic start date:

Forumname Title (url) Author name 0000-00-00 00:00

 

I get no results, page keeps loading and loading and stops after a while.

 

													while( $row7 = $this->ipsclass->DB->fetch_row() )
												 {
													 $startdate = date("d-m-Y", $row7['post_date']);

													 $this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'topics', 'tid' => $row7['topic_id'] ) );
													 $this->ipsclass->DB->simple_exec();
													 $row8 = $this->ipsclass->DB->fetch_row();

													 $output .= "<tr>
														 <td class='row1' valign='top'></td>
														 <td class='row2' valign='top'>".$row8['title']."</td>
														 <td class='row1' valign='top'>".$row7['author_name']."</td>
														 <td class='row1' valign='top'>".$startdate."</td>								
													   </tr>";
												 }

 

And i need another query for getting the name of the forum i guess? Is there a better way? :s

Thx

 

If you going to be pulling from multiple tables might be best to do it something like this

 

	$this->ipsclass->DB->build_query( array( 'select'   => 't.*',
										 'from'	 => array( 'topics' => 't' ),
										 'where'	=> "starter_id='1'",
										 'add_join' => array(
															   1 => array( 'select' => 'f.id, f.name',
																			 'from'   => array( 'forums' => 'f' ),
																			 'where'  => 'f.id=t.forum_id',
																			 'type'   => 'left' )
															  ),
										 'order'	=> "t.start_date DESC",
										 'limit'	=> array( 0, 10 ) ) );

$this->ipsclass->DB->exec_query();

if ($this->ipsclass->DB->get_num_rows())
{
	while ($r = $this->ipsclass->DB->fetch_row())
	{
		echo $r['title']." - ".$r['name']."<br />";
	}
}

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...