php - Search multiple tables and display as multiple tables -
i want users search database return data 2 different tables have done using union want not search 2 tables display 2 tables..how can go doing this?
$result .= "<table border='1'>"; $result .="<tr><td>cater</td><td>part</td><td>gids</td></tr>"; while ($row = mysql_fetch_array($sql)){ $result .= '<tr>'; $result .= '<td>'.$row['name'].'</td>'; $result .= '<td>'.$row['part'].'</td>'; $result .= '<td>'.$row['gid'].'</td>'; $result .= '</tr>'; } $result .= "</table>"; $result .= "<table border='1'>"; $result .="<tr><td>cater</td><td>dish</td><td>gids</td></tr>"; while ($row = mysql_fetch_array($sql)){ $result .= '<tr>'; $result .= '<td>'.$row['name'].'</td>'; $result .= '<td>'.$row['dish'].'</td>'; $result .= '<td>'.$row['gid'].'</td>'; $result .= '</tr>'; } $result .= "</table>";
if you're going way, need way tell first results end , second start. easy way add column in result set:
select 0 resultset, name, part, gid parts union 1, name, dish, gid dishes order resultset -- i'm not sure if need this, or whether free
then need break out of first loop if you've moved second result set. also, column names in union reflect first part, i've changed dish part. have deal possibility either or both of parts of union may return nothing.
$result .= "<table border='1'>"; $result .="<tr><td>cater</td><td>part</td><td>gids</td></tr>"; while ($row = mysql_fetch_assoc($sql) && $row['resultset'] === 0) { $result .= '<tr>'; $result .= '<td>'.$row['name'].'</td>'; $result .= '<td>'.$row['part'].'</td>'; $result .= '<td>'.$row['gid'].'</td>'; $result .= '</tr>'; } $result .= "</table>"; $result .= "<table border='1'>"; $result .="<tr><td>cater</td><td>dish</td><td>gids</td></tr>"; while ($row){ $result .= '<tr>'; $result .= '<td>'.$row['name'].'</td>'; $result .= '<td>'.$row['part'].'</td>'; $result .= '<td>'.$row['gid'].'</td>'; $result .= '</tr>'; $row = mysql_fetch_assoc($sql); } $result .= "</table>";
Comments
Post a Comment