zchrykng
06-27-2011, 02:58 PM
Hi everyone I have been working on a php script for populating an image gallery. I have been having strange problems as have not been able to figure out what I am doing wrong. Any help would be great.
This is what I get from running the script.
query($query); $num_results = $result->num_rows; if ($num_results < 8) { $grid_fill = $num_results; } else { $grid_fill = 8; } $num_pages = $num_results / 8; echo '
'; for ($counts = 0; $counts < $grid_fill; ++$counts) { $row = $result->fetch_assoc(); $restitle = stripslashes($row['imagenm']); $resdsc = stripslashes($row['imagedsc']); $resindex = ; echo '
$restitle $resdsc
'; } echo '
'; ?>
While here is the code that I wrote for the script... passwords and such removed
<?php
$pagenum = $_GET['page'];
$category = $_GET['category'];
if ($pagenum == NULL) {
$pagenum = 1;
}
@ $db = new mysqli('server', 'user', 'password', 'database');
if (mrsqli_connect_errno()) {
echo 'Error: Could not connect to database. Please try again later.';
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
$query = 'select imageid, imagenm, imagedsc from portfolio';
if ($category != NULL ) {
$query = $query . 'where imagetp = ' . $category;
}
$query = $query . ' order by imagedtad';
$result = $db->query($query);
$num_results = $result->num_rows;
if ($num_results < 8) {
$grid_fill = $num_results;
}
else {
$grid_fill = 8;
}
$num_pages = $num_results / 8;
echo '<div class=\"content\">
<ul class=\"grid group\">
';
for ($counts = 0; $counts < $grid_fill; ++$counts) {
$row = $result->fetch_assoc();
$restitle = stripslashes($row['imagenm']);
$resdsc = stripslashes($row['imagedsc']);
$resindex = ;
echo '<li>
<div class=\"infooverlay\">
<div class=\"valign\">
<div class=\"info\">
<span class=\"title\">$restitle</span>
<span class=\"dsc\">$resdsc</span>
</div>
</div>
</div>
<a href=\"$resindex\" >
<img alt=\"$restitle\" src=\"portfolio/thumbnails/$resindex.png\">
</a>
</li>';
}
echo '
</ul>
</div>';
?>
This is what I get from running the script.
query($query); $num_results = $result->num_rows; if ($num_results < 8) { $grid_fill = $num_results; } else { $grid_fill = 8; } $num_pages = $num_results / 8; echo '
'; for ($counts = 0; $counts < $grid_fill; ++$counts) { $row = $result->fetch_assoc(); $restitle = stripslashes($row['imagenm']); $resdsc = stripslashes($row['imagedsc']); $resindex = ; echo '
$restitle $resdsc
'; } echo '
'; ?>
While here is the code that I wrote for the script... passwords and such removed
<?php
$pagenum = $_GET['page'];
$category = $_GET['category'];
if ($pagenum == NULL) {
$pagenum = 1;
}
@ $db = new mysqli('server', 'user', 'password', 'database');
if (mrsqli_connect_errno()) {
echo 'Error: Could not connect to database. Please try again later.';
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
$query = 'select imageid, imagenm, imagedsc from portfolio';
if ($category != NULL ) {
$query = $query . 'where imagetp = ' . $category;
}
$query = $query . ' order by imagedtad';
$result = $db->query($query);
$num_results = $result->num_rows;
if ($num_results < 8) {
$grid_fill = $num_results;
}
else {
$grid_fill = 8;
}
$num_pages = $num_results / 8;
echo '<div class=\"content\">
<ul class=\"grid group\">
';
for ($counts = 0; $counts < $grid_fill; ++$counts) {
$row = $result->fetch_assoc();
$restitle = stripslashes($row['imagenm']);
$resdsc = stripslashes($row['imagedsc']);
$resindex = ;
echo '<li>
<div class=\"infooverlay\">
<div class=\"valign\">
<div class=\"info\">
<span class=\"title\">$restitle</span>
<span class=\"dsc\">$resdsc</span>
</div>
</div>
</div>
<a href=\"$resindex\" >
<img alt=\"$restitle\" src=\"portfolio/thumbnails/$resindex.png\">
</a>
</li>';
}
echo '
</ul>
</div>';
?>