jjmusicpro Posted February 4, 2008 Share Posted February 4, 2008 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/89291-get-results-and-make-table/ Share on other sites More sharing options...
mikefrederick Posted February 4, 2008 Share Posted February 4, 2008 why not just if $row=='4' print a line break? didn't read the code through but seems like that's that. Quote Link to comment https://forums.phpfreaks.com/topic/89291-get-results-and-make-table/#findComment-457214 Share on other sites More sharing options...
haku Posted February 4, 2008 Share Posted February 4, 2008 Thats pretty much the right idea. I use this technique: echo "<tr> for($i = 0; $i < someLength; $i++) { if($i % 4 == 0) { echo "</tr><tr>"; } echo [enter your <td> tags here]; } echo "</tr>"; Quote Link to comment https://forums.phpfreaks.com/topic/89291-get-results-and-make-table/#findComment-457250 Share on other sites More sharing options...
jjmusicpro Posted February 4, 2008 Author Share Posted February 4, 2008 i tried adding that and cant get it to work right. Quote Link to comment https://forums.phpfreaks.com/topic/89291-get-results-and-make-table/#findComment-457271 Share on other sites More sharing options...
haku Posted February 4, 2008 Share Posted February 4, 2008 So post some code. If we can't see what you've done, we can't see what you are doing wrong. Quote Link to comment https://forums.phpfreaks.com/topic/89291-get-results-and-make-table/#findComment-457274 Share on other sites More sharing options...
jjmusicpro Posted February 4, 2008 Author Share Posted February 4, 2008 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>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/89291-get-results-and-make-table/#findComment-457284 Share on other sites More sharing options...
mikefrederick Posted February 4, 2008 Share Posted February 4, 2008 or just do what i said originally, if($whatever=='4') { echo "<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/89291-get-results-and-make-table/#findComment-457285 Share on other sites More sharing options...
jjmusicpro Posted February 4, 2008 Author Share Posted February 4, 2008 where do i put that? Quote Link to comment https://forums.phpfreaks.com/topic/89291-get-results-and-make-table/#findComment-457287 Share on other sites More sharing options...
haku Posted February 4, 2008 Share Posted February 4, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/89291-get-results-and-make-table/#findComment-457293 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.