Jump to content

Recommended Posts

i am using the coopermine php module.

however, when it gets the results, it just will put x, where x is the number of items i say to get, in one long row.

 

I wanted it to stop at 4, and start a new line, but cant get this code to work like that....

 

if ($pic_count > 1000) {
    $result = $db->sql_query("SELECT COUNT(*) from " . $cpg_prefix . "pictures WHERE approved = 'YES'");
    $nbEnr = $db->sql_fetchrow($result);
    $total_count = $nbEnr[0];

    $granularity = floor($total_count / 1000);
    $cor_gran = ceil($total_count / $pic_count);
    srand(time());
    for ($i = 1; $i <= $cor_gran; $i++) $random_num_set = rand(0, $granularity) . ', ';
    $random_num_set = substr($random_num_set, 0, -2);

    $result = $db->sql_query("SELECT pid, filepath, filename, p.aid, p.title FROM ".$cpg_prefix."pictures AS p INNER JOIN ".$cpg_prefix."albums AS a ON (p.aid = a.aid AND ".VIS_GROUPS.") WHERE randpos IN ($random_num_set) AND approved='YES' GROUP BY pid ORDER BY RAND() DESC LIMIT $limit");
} else {
    $result = $db->sql_query("SELECT pid, filepath, filename, p.aid, p.title FROM ".$cpg_prefix."pictures AS p INNER JOIN ".$cpg_prefix."albums AS a ON (p.aid = a.aid AND ".VIS_GROUPS.") WHERE approved='YES' GROUP BY pid ORDER BY RAND() DESC LIMIT $limit");
}

while ($row = $db->sql_fetchrow($result)) {
    if ($CONFIG['seo_alts'] == 0) {
        $thumb_title = $row['filename'];
    } else {
        if ($row['title'] != '') {
            $thumb_title = $row['title'];
        } else {
            $thumb_title = substr($row['filename'], 0, -4);
        } 
    } 
    stripslashes($thumb_title);
    $content .= '<td align="center" valign="baseline"><a href="' . $CPG_M_URL . '&file=displayimage&album='.$row['aid'].'&pos=' . $row["pid"] . '"><img src="' . get_pic_url($row, 'thumb') . '" border="0" alt="' . $thumb_title . '" title="' . $thumb_title . '"><br /> </a></td>';
} 
$content .= '</tr><tr align="center"><td colspan="' . $limit2 . '" valign="baseline"></center></td></tr></table>';

Link to comment
https://forums.phpfreaks.com/topic/89291-get-results-and-make-table/
Share on other sites

if ($pic_count > 1000) {
    $result = $db->sql_query("SELECT COUNT(*) from " . $cpg_prefix . "pictures WHERE approved = 'YES'");
    $nbEnr = $db->sql_fetchrow($result);
    $total_count = $nbEnr[0];

    $granularity = floor($total_count / 1000);
    $cor_gran = ceil($total_count / $pic_count);
    srand(time());
    for ($i = 1; $i <= $cor_gran; $i++) $random_num_set = rand(0, $granularity) . ', ';
    $random_num_set = substr($random_num_set, 0, -2);

    $result = $db->sql_query("SELECT pid, filepath, filename, p.aid, p.title FROM ".$cpg_prefix."pictures AS p INNER JOIN ".$cpg_prefix."albums AS a ON (p.aid = a.aid AND ".VIS_GROUPS.") WHERE randpos IN ($random_num_set) AND approved='YES' GROUP BY pid ORDER BY RAND() DESC LIMIT $limit");
} else {
    $result = $db->sql_query("SELECT pid, filepath, filename, p.aid, p.title FROM ".$cpg_prefix."pictures AS p INNER JOIN ".$cpg_prefix."albums AS a ON (p.aid = a.aid AND ".VIS_GROUPS.") WHERE approved='YES' GROUP BY pid ORDER BY RAND() DESC LIMIT $limit");
}

while ($row = $db->sql_fetchrow($result)) {
    if ($CONFIG['seo_alts'] == 0) {
        $thumb_title = $row['filename'];
    } else {
        if ($row['title'] != '') {
            $thumb_title = $row['title'];
        } else {
            $thumb_title = substr($row['filename'], 0, -4);
        } 
    } 
    stripslashes($thumb_title);

for($i = 0; i < 5; $i++)
{
	if($i <4 == 0)
	{
		echo '</tr><tr>';
	}
	echo '<a href="' . $CPG_M_URL . '&file=displayimage&album='.$row['aid'].'&pos=' . $row["pid"] . '"><img src="' . get_pic_url($row, 'thumb') . '" border="0" alt="' . $thumb_title . '" title="' . $thumb_title . '">';
}

echo '</tr>';

//   $content .= '<td align="center" valign="baseline"><a href="' . $CPG_M_URL . '&file=displayimage&album='.$row['aid'].'&pos=' . $row["pid"] . '"><img src="' . get_pic_url($row, 'thumb') . '" border="0" alt="' . $thumb_title . '" title="' . $thumb_title . '"><br /> </a></td>';
//} 
//$content .= '</tr><tr align="center"><td colspan="' . $limit2 . '" valign="baseline"></center></td></tr></table>';

?>

I'm not fully sure at what you are trying to get at with your code, so I will give an example of how I would build a table with a mysql query and an un-known number of rows returned:

 

$query = "SELECT var1, var2, var3 FROM someTable";
$tableValues = mysql_query($query);
// you should check for errors at this point, but I'm not including that

echo "<table><tbody>";
while ($tableRow = mysql_fetch_array($tableValues)
{
    echo "<tr>";
    echo "<td>" . $tableRow['var1'] . "</td><td>" . $tableRow['var2'] . "</td><td>" . $tableRow['var3'] . "</td>";
    echo "</tr>";
}
echo "</tbody></table>";

 

This sets the <table> and <tbody> opening and closing tags outside the rows. Then for each row in the mysql query, a <tr> is outputted, followed by three <td></td> tags that have the details of the 3 variables pulled from the database, followed by a closing </tr> tag.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.