I am writing a hash algorithm simulator, I am running the keys through the hash but I am not being able to display the whole hash table after all keys are entered. I also I can not figure a way to check if there is any collision because I am not being able to search through the keys that already enterd. Please if there is any help to show how to display table as keys are entered and check for collision I would greadtly appreciate.... here is code

<html><head><title>t</title></head>
<body>

<form method="POST" action="">
<?php

if (count($_POST) == 0) { // initial display of script
  echo <<< EOT

<br>Hash Tablee Size<br>7:<input type="radio" name="tableSize"  value="7" checked />
&nbsp; &nbsp;11:<input type="radio" name="tableSize" value="11" />
&nbsp; &nbsp;13:<input type="radio" name="tableSize" value="13" />
&nbsp; &nbsp;17:<input type="radio" name="tableSize" value="17" />
<br>

<br>Bucket Size<br>1:<input type="radio" name="bucketSize" value="1" checked />
&nbsp; &nbsp;2:<input type="radio" name="bucketSize" value="2" />
&nbsp; &nbsp;3:<input type="radio" name="bucketSize" value="3" />
<br>


<p>Specify set of values (separate each value with a space):<br />
   <input type="radio" name="Values" value="a123 a14 a15 a206 a13 a21 a34 a21 a45 a13" size="60" /> Predifined Values (a123 a14 a15 a206 a13 a21 a34 a21 a45 a13)</p>
  
<input type="hidden" name="CurrentPos" value="-1" />



<input type="submit" name="Next" value="Start" />

EOT;
  }
else { // process the form submission



  // split the values
  $values = explode('a',($_POST['Values']));
  $numValues = count($values); // simplification

  if (!isset($_POST['Next'])) $pos = 0;
  else $pos = max(0,min($numValues,$_POST['CurrentPos']+1));

  // form names in the output
  $posName = ($pos == 0) ? 'first' : (($pos == $numValues-1) ? 'last' : 'next');
  $nextButton = ($pos == $numValues-1) ?
     '<input type="submit" name="StartOver" value="Start Over" />' :
     '<input type="submit" name="Next" value="Next" />';

 $key=$values[$pos]%$_POST['tableSize']; //run the hash algorithm
         echo "<br>";
	  $tableFull=($pos / (($_POST['bucketSize']) * ($_POST['tableSize']))) * 100;
         $tableFull= round($tableFull, 2);
	echo "Percenteage Table Full " . $tableFull . "%";

	if($tableFull==100)
	{echo " Last Operation, Table is Full";
		$_POST['posName']='last';
	exit;}

  echo <<< EOT
<p> $posName {$values[$pos+1]} % {$_POST['tableSize']} => $key.</p>
<input type="hidden" name="User" value="{$_POST['User']}" />
<input type="hidden" name="Values" value="{$_POST['Values']}" />
<input type="hidden" name="CurrentPos" value="$pos" />
<input type="hidden" name="tableSize" value="{$_POST['tableSize']}" />
<input type="hidden" name="bucketSize" value="{$_POST['bucketSize']}" />

<input type="hidden" name="posName" value="$posName" />

$nextButton

EOT;
  }
  
?>
</form>
</body></html>

To me it looks like a big mess, you should just use a forloop and with an echo statement inside to produce your output alot more cleaner imo.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.