Deanznet Posted November 7, 2007 Share Posted November 7, 2007 I was working on this in another topic.. but it got kinda big with all my other problems.. and i solved most in the old thread.. So anyways heres the problem.. When a user gose to this page.. it displays all the images in the database.. But the images are all across the page.. The image url is located in basename.. also some images dont have any urls in the basename so how can i make it show just the ones with stuff in the basename. I want about 4 columns with 4 in a row and if it goes past that it makes a new page. Any idea how this can be done? this is the code we tried fixing in the old thread, but still displays in a straight line <? ob_start();//output buffering include("include/common.php"); function washdata($input) { if(preg_match('/^[0-9a-zA-z]*$/', $input) == 1) { return true; } else { return false; } } if(washdata($_POST['keyword_query']) == true) { $keyword_query = mysql_real_escape_string($_POST['keyword_query']);//we need to sanitize ANY and ALL user input, to prevent sql injection and yada-yada $query = @mysql_query("SELECT id,basename,keywords FROM images WHERE keywords LIKE '%$keyword_query%' ") or die(mysql_error()); if(!mysql_num_rows($query)){//0 = false, 1 or more = true die("I'm sorry, no results were found for $keyword_query."); } //if it gets to here, that means there were some matches... echo "<table><tr>"; $rowcounter = 0; while($row = mysql_fetch_array($query)){ $basename = $row['basename']; list($filename,$extension) = explode(".",$basename);//something.ext to something & ext $keywords = $row['keywords'];//you can do fancy stuff with this one, explode into arrays, etc... if (!$rowcounter%3){echo "<tr>";}//if 1 or 2, nothing happens, if 0, it echos <tr> if ($basename) { echo "<td><P><img src='$basename' width='100' height'100' alt='$keywords' /><br>Keywords: $keywords<br><br>"; } echo "</td>"; $rowcounter++; if (!$rowcounter%3){echo "</tr>";}//if 1 or 2, nothing happens, if 0, it echos </tr> } echo "</table>"; mysql_free_result($query);//clear off memory of all data from this query, just in case it returns a lot of results and takes up memory on the sever, helps w/ server load } else { echo "Only letters and numbers please."; } ?> Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 8, 2007 Author Share Posted November 8, 2007 Anyone? ??? Quote Link to comment Share on other sites More sharing options...
optikalefx Posted November 8, 2007 Share Posted November 8, 2007 you need to get the number of rows of the database, there is php mysql function for that. Then use that number to determine how many pages your going to have, as in multiples of 16. so from the number of pages, use that to determine how many sets of 4 for loops you will have. so you will have 4 for loops per page to display a table of images, and then based on the number of pages when you click a link to go the 'next' page you will need to send in the url the number of starting images to start with and start for looping form there, and keep going. so that number will keep track of our last picture, it will obviously be 17 for the 2nd page and 25 for the 3rd and so on. thats just an idea. the easier idea is to just list them in a 4 by x table and just scroll the page forever Quote Link to comment 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.