Jump to content

Recommended Posts

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;
		}
	?>

Link to comment
https://forums.phpfreaks.com/topic/53307-easier-way-to-write-this-script/
Share on other sites

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.

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.