Sheets Posted January 13, 2012 Share Posted January 13, 2012 id: 20 Reason: this is a test id: 21 Reason: Tests id: 22 Reason: Lolcatz id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: 36 Reason: Test As you can see on the 2nd code box there are id's 20,21,22 and 36 in the database the rest are not active in the database. i am using using for to pull out the id that starts with the lowest value in the database, and only have it run until it gets to the maximum value. for ($id=$set_min; $set_max<=7; $id++) { // $id=$set_min is pulling the smallest value and $set_max is pulling the maximum value so it stops after it gets to 36 $query=mysql_query("SELECT * FROM posted WHERE id = $id"); $query_row=mysql_fetch_array($query); $reason = $query_row[reason]; $pulled_id = $query_row[id]; $pulled_pic22 = $query_row[picture]; $href_pull = "<a href=" . "search.php?id=" . "$id" .">"; echo "<td>" . $href_pull . "<img src=$pulled_pic22 height=200 width=150 />" . "</td>"; } how would i make it so i do not pull the values 23-35 which are not in the active database. Example: http://dev.hackmuch.com/of-the-day/search.php?id=36 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 13, 2012 Share Posted January 13, 2012 For starters, don't run queries in loops when it isn't necessary, and in this case, it isn't. What are you trying to accomplish, exactly? How are you determining the minimum and maximum ids of the records you want to retrieve? Quote Link to comment Share on other sites More sharing options...
Sheets Posted January 13, 2012 Author Share Posted January 13, 2012 That is the only way i know how to. 0.o but obviously it is not working. I am trying to pull the pictures out of the database, set it up so it forwards to search.php with the id that it has. however if you went to the link i posted you see there are 3 images then at the far right there is another one. It is pulling all the in between ids that are not in the database. I know there are better ways etc.. but this is all i know how at the moment. function get_min() { $min = mysql_query("SELECT MIN(id) FROM posted"); $query_min = mysql_fetch_array($min); $min_min = $query_min[0]; return $min_min; } function get_max() { $max = mysql_query("SELECT MAX(id) FROM posted"); $query_max = mysql_fetch_array($max); $max_max = $query_max[0]; return $max_max; } Quote Link to comment Share on other sites More sharing options...
litebearer Posted January 13, 2012 Share Posted January 13, 2012 how are you determining NOT ACTIVE?. As you can see on the 2nd code box there are id's 20,21,22 and 36 in the database the rest are not active in the database. Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted January 13, 2012 Share Posted January 13, 2012 I think this is what you are looking for: $sql = "SELECT id, reason, picture FROM posted WHERE id BETWEEN $set_min, AND $set_max"; //query string $result = mysql_query($sql) or die (mysql_error()); // run a single query only once, show error on failure while ($row=mysql_fetch_assoc($result)){ //run through the results using $row array to address returned fields by field name //your code start $reason = $row[reason]; $pulled_id = $row[id]; $pulled_pic22 = $row[picture]; $href_pull = "<a href=" . "search.php?id=" . "$id" .">"; echo "<td>" . $href_pull . "<img src=$pulled_pic22 height=200 width=150 />" . "</td>"; //your code end }//job done Quote Link to comment Share on other sites More sharing options...
Sheets Posted January 14, 2012 Author Share Posted January 14, 2012 how are you determining NOT ACTIVE?. As you can see on the 2nd code box there are id's 20,21,22 and 36 in the database the rest are not active in the database. basically there are no ids with the ones in between Quote Link to comment Share on other sites More sharing options...
Sheets Posted January 14, 2012 Author Share Posted January 14, 2012 I think this is what you are looking for: $sql = "SELECT id, reason, picture FROM posted WHERE id BETWEEN $set_min, AND $set_max"; //query string $result = mysql_query($sql) or die (mysql_error()); // run a single query only once, show error on failure while ($row=mysql_fetch_assoc($result)){ //run through the results using $row array to address returned fields by field name //your code start $reason = $row[reason]; $pulled_id = $row[id]; $pulled_pic22 = $row[picture]; $href_pull = "<a href=" . "search.php?id=" . "$id" .">"; echo "<td>" . $href_pull . "<img src=$pulled_pic22 height=200 width=150 />" . "</td>"; //your code end }//job done You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' AND 36' at line 1 Trying to fix myself ill let you know, but if you know how to fix feel free to reply Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 14, 2012 Share Posted January 14, 2012 The comma doesn't belong there . . . Quote Link to comment Share on other sites More sharing options...
Sheets Posted January 14, 2012 Author Share Posted January 14, 2012 $sql = "SELECT id, reason, picture FROM posted WHERE id BETWEEN $set_min AND $set_max"; //query string $result = mysql_query($sql) or die (mysql_error()); // run a single query only once, show error on failure while ($row=mysql_fetch_assoc($result)){ //run through the results using $row array to address returned fields by field name //your code start $reason = $row[reason]; $pulled_id = $row[id]; $pulled_pic22 = $row[picture]; $href_pull = "<a href=" . "search.php?id=" . "$pulled_id" .">"; echo "<td>" . $href_pull . "<img src=$pulled_pic22 height=200 width=150 />" . "</td>"; //your code end }//job done it works exactly like i want! thank you for your help! 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.