How do you select data from two tables with one query?
Posted: Fri May 29, 2009 12:41 am
Heya,
So I pull projects data into my portfolio page from a table called 'project-data'. This has their business name, live site url, feedback, and a few others things. But the clients first and last name are stored in `client-data`. I'm not sure how I write a query that will pull both segments of data for my loop. Can anyone help? Thanks!
So I pull projects data into my portfolio page from a table called 'project-data'. This has their business name, live site url, feedback, and a few others things. But the clients first and last name are stored in `client-data`. I'm not sure how I write a query that will pull both segments of data for my loop. Can anyone help? Thanks!
Code: Select all
$get_portfolio_data = mysql_query("SELECT * FROM `project-data` JOIN `client-data` WHERE `project-status` = 'published' ORDER BY `date-completed` ASC");
while ($show_portfolio_data = mysql_fetch_array($get_portfolio_data, MYSQL_ASSOC)) {
echo "
<table>
<tr valign='top'>
<td><img src='" . $root . "images/project-thumbnails/" . $show_portfolio_data['business-name'] . "-" . $show_portfolio_data['project-name'] . ".png' /></td>
<td>
<h1 style='text-transform: capitalize;'>" . ereg_replace('-', ' ', $show_portfolio_data['business-name']) . "</h1>
<p><span style='color: #333;'>Our Contact:</span> " . $show_portfolio_data['client-first-name'] . " " . $show_portfolio_data['client-last-name'] . "</p>
<p><a target='_blank' href='" . $show_portfolio_data['live-site'] . "'>Live Site</a></p>
<p><span style='color: #333;'>Their overall rating of us:</span> " . $show_portfolio_data['rating-overall'] . " out of 10</p>
<p><span style='color: #333;'>Their overall comments of us:</span> " . $show_portfolio_data['comments-overall'] . "</p>
</td>
</tr>
</table>
";
}