eZe616 Posted May 28, 2007 Share Posted May 28, 2007 I was wondering if there was an easier way to write this piece of script, that took me since this morning to get working. I feel like there's an better, solution for it. <?php include 'dbcon.php'; $id = "34"; $sql = "SELECT * FROM hpics WHERE id='".$id."' order by p1 ASC"; $result = mysql_query($sql) or die(mysql_error()); $num_result = mysql_num_rows($result); echo "<b>".$num_result."</b><br /><br />"; // Starting Here; Is there a smoother way to write it?? $pic = array(); $v = 1; for ($i=0; $i < $num_result; $i++) { $row = mysql_fetch_array($result); $expl = explode("_img", $row['p1']); $expl2 = explode(".", $expl[1]); $pic[] = $expl2[0]; } foreach ( $pic as $value ) { if ( $v == $value ) { echo $v; $v++; echo " - ".$v."<br />"; } } if ( $v != $value ) { echo "<br /><b>Finally At Number: </b>".$v; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53307-easier-way-to-write-this-script/ Share on other sites More sharing options...
Barand Posted May 28, 2007 Share Posted May 28, 2007 Do we have to spend time guessing what it does or would you like to tell us. Quote Link to comment https://forums.phpfreaks.com/topic/53307-easier-way-to-write-this-script/#findComment-263494 Share on other sites More sharing options...
eZe616 Posted May 28, 2007 Author Share Posted May 28, 2007 My bad... It first looks into a image db gor images with the set id. I get the number of rows it sends back. create a pic array to the images last number, from a picture called HID_img2.jpg f.e. for every picture is finds, ite retrieves only the number, and puts it in the pic array. Then I put it into a foreach loop so it can see if any array value is the equal to the starting number. if it is add +1 to the starting number. the If the starting number is not equal to the any array value, it echo's it. This is suppose to be a simple version, of what i want to accomplish with images upload/delete system. Quote Link to comment https://forums.phpfreaks.com/topic/53307-easier-way-to-write-this-script/#findComment-263512 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.