Hi there,
I have a template that looks as follows:
<tr>
<td>
[NAME1]
</td>
<td>
[NAME2]
</td>
<td>
[NAME3]
</td>
</tr>
Those NAME1, NAME2, NAME3 etc are supposed to be replaced by the results from the DB. The code I currently have works for one TD, but I'm at a loss as to how to make it work for three.
// Format the results to specified
// standards
while($search_array = mysql_fetch_array($this->results)) {
// Create temp_start to store each html entity in
$this->temp_html = $this->formatted_results;
// Create a name without spaces
$search_array['nameurl'] = urlencode($search_array['name']);
// Go through the search array,
// replacing each item.
foreach($search_array as $key => $value) {
$this->temp_html .= str_replace("[".strtoupper($key)."]", $value, $this->temp_html);
}
$html .= $this->temp_html;
}
$this->formatted_results = $html;
Now I thought about using $i++ etc to work out the numbers, then after each three, reset $i back to 0 to start a new row. I think this would work, but then, if the database doesn't contain a third row, one of those fields will be left showing [NAME3] rather than just being left blank...
Any help would be appreciated. 🙂
Thanks,
Chris