Hello,
I have a php code which collects info from a database and then display the info in a table with specific details. Anyway, the script works perfectly but I’d like to add another column. Everytime I try, I get an error at the last line of the whole page (Parse error: syntax error, unexpected $end => thus referring to: </html>).
The idea is to have an image and a line of text underneath it in every cell. So it should be:
image1 image2 image3 image4
text1 text2 text3 text4
The script also currently has 4 columns, though the second and fourth are empty. If I do fill them, the info from column one and three is copied into the second and fourth column. That way, I’ll get:
image1 image1 image2 image2
text1 text1 text2 text2
Can someboy please help me out to create four columns with in every column different info from my SQL table?
Here’s my code (I’ve marked the table settings in red):
<?php include ("../Connection.txt"); ?>
<?php
$id = $_GET['id'];
$maxcol = 4;
$result = mysql_query("SELECT * FROM Folders order by id desc") or die (mysql_error());
$count = mysql_num_rows($result);
$rows = ceil($count/$maxcol);
echo "<table>";
$limit = 20;
$table = 'Folders';
//get requested page
$page = empty($_GET['page']) ? 1 : (int) $_GET['page'];
//calculate offset
$offset = ($page - 1) * $limit;
//construct query
$query = "Select SQL_CALC_FOUND_ROWS * from $table order by formaat asc LIMIT $limit OFFSET $offset";
//execute query
$result = mysql_query($query) or die (mysql_error());
$cResult = mysql_query("Select found_rows()") or die(mysql_error());
list($count) = mysql_fetch_array($cResult, MYSQL_NUM);
$pageNavBar = getPages($limit, $count, $page);
//start the output
echo <<<HTML
<style type="text/css">
/*style links */
.pageNav a {text-decoration:none; cursor:crosshair; color: #131d31;}
.pageNav a:visited {text-decoration:none; color: #131d31;}
/*make the page numbering smaller generally */
.pageNav{ font-size:smaller;}
.page{ border: thin dotted #060409; background-color:#fdffeb;}
.navi{ padding: 5px; margin: 2px; width: 2em;}
.prev{}
.last{ background-color:;}
.first{ background-color:;}
.next{}
.active {backround-color:grey; color:red;}
.select select {}
.table {font-family: verdana; font-size: 12px;}
</style>
<table width="100%" border="0" rules="groups" table class="table">
<thead>
</thead>
<tbody>
[COLOR="DarkRed"]HTML;
while ($row = mysql_fetch_assoc($result)){
$row['price'] = round ((($row['price']+5) *1.85),0);
$base_m=5;
$row['price1'] = $base_m*(ceil(($row['price'])/$base_m));
echo <<<HTML
<tr>
<td align="center" width="50%"><img src={$row['thumb_name']}><br>
{$row['name']}<br>
{$row['description']}<br />
{$row['price1']}<br>
</td>
<td align="left" width="0%"></td>
HTML;
$row = mysql_fetch_assoc($result);
if (!$row){
echo "<td> </td><td> </td>";
} else {
echo <<<HTML
<td align="center" width="50%"><img src={$row['thumb_name']}><br>
{$row['name']}<br>
{$row['description']}<br />
{$row['price1']} </td>
<td align="left" width="0%"></td>
HTML;[/COLOR]
} //end if
echo "</tr>";
} //end while
echo <<<HTML
</tbody>
<tfoot>
<tr>
<p><th colspan="4">
$pageNavBar
</th>
</tr>
</tfoot>
</table>
HTML;
function getPages($limit, $count, $page){
//put the url into a variable
$s = "http://" . $_SERVER['HTTP_HOST'] .'/'. ltrim($_SERVER["SCRIPT_NAME"] ,'/');
//calculate the number of pages needed
$nPages = ceil($count/$limit);
//do the first/last prev/next buttons
$first = <<<HTML
<span class="first navi">
<a href="$s?page=1"><<<</a>
</span>
HTML;
$last = <<<HTML
<span class="last navi">
<a href="$s?page=$nPages">>>></a>
</span>
HTML;
if ($page > 1) {
$p = $page - 1;
$prev = <<<HTML
<span class="next navi">
<a href="$s?page=$p"><</a>
</span>
HTML;
} else {
$prev = ' ';
$first = ' ';
}
if ($page < $nPages) {
$p = $page + 1;
$next = <<<HTML
<span class="next navi">
<a href="$s?page=$p">></a>
</span>
HTML;
} else {
$next = ' ';
$last = ' ';
}
//now construct the pages
//if more than 10 then use a select
if ($nPages > 10){
$output = <<<HTMLJS
<span class="navi select">
<select name="page" onchange="window.location='{$s}?page=' + this.options[this.selectedIndex].value;">
HTMLJS;
for ($p=1; $p <=$nPages; $p++){
$output .= "<option value=\"$p\">$p</option>";
}
$output .= '</select></span>';
} else {
$output = '';
for ($p=1; $p<=$nPages; $p++){
$active = ($p == $page) ? 'active' : '';
$output .= "<span class=\"navi page {$active}\"><a href=\"$s?page=$p\">$p</a></span>";
}
}
return '<div class="pageNav">' . $first . $prev. $output . $next . $last . '</div>';
}
?>
Thank you very much!