troubleshooting Question

Displaying some selected search results through a modal

Avatar of Abraham Augustus Nortey
Abraham Augustus Nortey asked on
PHPBootstrapSQL
24 Comments1 Solution188 ViewsLast Modified:
I created a search engine and is displaying results from the  database and beneath the results is a bootstrap modal for which am displaying some selected results in there
Problem is that i want to for each results fetched eg row 1 of id 1 should displayed the contents for id 1 and not any other but here in this if  3 results is found, it displays the 3rd  results for all which shouldn't be the case.
Beneath is an images that shows the above...Any help to solve this is highly appreciated.




<?php
$button = $_GET [ 'submit' ];
$search = $_GET [ 'search' ];
if( !$button )
          echo "you didn't submit a keyword";
else {
    if( strlen( $search ) <= 1 )
            echo "Search term too short";
            else { echo "You searched for <b> $search </b> <hr size='1' > </ br > ";
            $conn = mysqli_connect( "localhost","root","",'register') ;
            $search_exploded = explode ( " ", $search );
            $x = 0;
            foreach( $search_exploded as $search_each ) {
                  $x++; $construct = "";
                  if( $x == 1 )
					  
                      	$construct .="keyword LIKE '%$search_each%' OR qualifications1 LIKE '%$search_each%' OR dept LIKE '%$search_each%' ";
                           else
					   	$construct .="AND keyword LIKE '%$search_each%' OR AND qualifications1 LIKE '%$search_each%' OR AND dept LIKE '%$search_each%' ";
				
          }
          $construct = " SELECT * FROM users WHERE $construct ";
          $run = $conn->query( $construct ); $foundnum = $run->num_rows ;
          if ($foundnum == 0) 
                  echo "Sorry, there are no matching result for <b> $search </b>. </br> </br> 1. Try more keywords. for example: If you want to search 'For a person in the Banking Department' then use general keyword like 'Banking','Business','Finance' or if the person needed resides in the Information  technology Department, then use general keyword like 'I.T' ,'Information, technology','Informatics' etc. <br> </br> 2. Try different words with similar  meaning </br><br> 3. Please check your spelling"; 
				  
                  else {
                  echo "$foundnum results found !<p>";
					 $per_page = 1;
					$start = isset($_GET['start']) ? $_GET['start']: '';
					$max_pages = ceil($foundnum / $per_page);
					if(!$start)
					$start=0; 
							$getquery = $conn->query("$construct LIMIT $start, $per_page"); 
						
							while( $runrows = $getquery->fetch_assoc() ) {
					  
                       $id=$runrows['id'];
						$firstname = $runrows ['firstname'];
						$job_type = $runrows ['job_type'];
						$about = $runrows ['about'];
						$dept = $runrows ['dept'];
						$gender = $runrows ['gender'];
						$nationality = $runrows ['nationality'];
						$marital_status = $runrows ['marital_status'];
						$computer_literate = $runrows ['computer_literate'];
						$computer_literate2 = $runrows ['computer_literate2'];
						$computer_literate3 = $runrows ['computer_literate3'];
						$computer_literate4 = $runrows ['computer_literate4'];
						$computer_literate5 = $runrows ['computer_literate5'];
						$computer_literate6 = $runrows ['computer_literate6'];
						$computer_literate7 = $runrows ['computer_literate7'];
						$computer_literate8 = $runrows ['computer_literate8'];
						$computer_literate9 = $runrows ['computer_literate9'];
						$lang_spoken = $runrows ['lang_spoken'];
						$lang_spoken2 = $runrows ['lang_spoken2'];
						$lang_spoken3 = $runrows ['lang_spoken3'];
						$lang_spoken4 = $runrows ['lang_spoken4'];
						$lang_spoken5 = $runrows ['lang_spoken5'];
						$lang_spoken6 = $runrows ['lang_spoken6'];
						$edu1 = $runrows ['edu1'];
						$edu2 = $runrows ['edu2'];
						$edu3 = $runrows ['edu3'];
						$edu4 = $runrows ['edu4'];
						$edu5 = $runrows ['edu5'];
						$edu6 = $runrows ['edu6'];
						$edu7 = $runrows ['edu7'];
						$edu8 = $runrows ['edu8'];
						$edu9 = $runrows ['edu9'];
						$edu10 = $runrows ['edu10'];
						$qualifications1 = $runrows ['qualifications1'];
						$qualifications2 = $runrows ['qualifications2'];
						$qualifications3 = $runrows ['qualifications3'];
						$qualifications4 = $runrows ['qualifications4'];
						$qualifications5 = $runrows ['qualifications5'];
						$qualifications6 = $runrows ['qualifications6'];
						$qualifications7 = $runrows ['qualifications7'];
						$qualifications8 = $runrows ['qualifications8'];
						$qualifications9 = $runrows ['qualifications9'];
						$qualifications10 = $runrows ['qualifications10'];
						$org_name1 = $runrows ['org_name1'];
						$org_name2 = $runrows ['org_name2'];
						$org_name3 = $runrows ['org_name3'];
						$org_name4 = $runrows ['org_name4'];
						$org_name5 = $runrows ['org_name5'];
						$pos_held1 = $runrows ['pos_held1'];
						$pos_held2 = $runrows ['pos_held2'];
						$pos_held3 = $runrows ['pos_held3'];
						$pos_held4 = $runrows ['pos_held4'];
						$pos_held5 = $runrows ['pos_held5'];
						$work_yoe1 = $runrows['work_yoe1'];
						$work_yoe2 = $runrows['work_yoe2'];
						$work_yoe3 = $runrows['work_yoe3'];
						$work_yoe4 = $runrows['work_yoe4'];
						$work_yoe5 = $runrows['work_yoe5'];
						$work_yoem1 = $runrows['work_yoem1'];
						$work_yoem2 = $runrows['work_yoem2'];
						$work_yoem3 = $runrows['work_yoem3'];
						$work_yoem4 = $runrows['work_yoem4'];
						$work_yoem5 = $runrows['work_yoem5'];
						$achievements = $runrows ['achievements'];
						$hobbies = $runrows ['hobbies'];

							   
						   echo "<h5>CV<b>$id</b></h5><br>";
							echo "<b>Gender</b>: $gender<br><br>";
							echo "<b>About</b> : $about<br><br>";
							echo "<b>Nationality</b>: $nationality<br><br>";
							echo "<b>Marital_status</b>: $marital_status<br><br>";
							echo "<b>Languages spoken</b>: $lang_spoken<br><br>";
							echo "<b>Job Wanted</b> :$job_type<br><br>";
							echo "<b>Qualifications </b>: $qualifications1<br><br>";
							echo "<button type='button' class='btn btn-info btn-lg' data-toggle='modal' data-target='#myModal'>View more</button><br><hr>";
                     }
					  
				//Pagination Starts
				echo "<center>";

				$prev = $start - $per_page;
				$next = $start + $per_page;

				$adjacents = 3;
				$last = $max_pages - 1;

				if($max_pages > 1)
				{   
				//previous button
				if (!($start<=0)) 
				echo " <a href='searchResult.php?search=$search&submit=Search&start=$prev'>Prev</a> ";    

				//pages 
				if ($max_pages < 7 + ($adjacents * 2))   //not enough pages to bother breaking it up
				{
				$i = 0;   
				for ($counter = 1; $counter <= $max_pages; $counter++)
				{
				if ($i == $start){
				echo " <a href='searchResult.php?search=$search&submit=Search&start=$i'><b>$counter</b></a> ";
				}
				else {
				echo " <a href='searchResult.php?search=$search&submit=Search&start=$i'>$counter</a> ";
				}  
				$i = $i + $per_page;                 
				}
				}
				elseif($max_pages > 5 + ($adjacents * 2))    //enough pages to hide some
				{
				//close to beginning; only hide later pages
				if(($start/$per_page) < 1 + ($adjacents * 2))        
				{
				$i = 0;
				for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
				{
				if ($i == $start){
				echo " <a href='searchResult.php?search=$search&submit=Search&start=$i'><b>$counter</b></a> ";
				}
				else {
				echo " <a href='searchResult.php?search=$search&submit=Search=$i'>$counter</a> ";
				} 
				$i = $i + $per_page;                                       
				}

				}
				//in middle; hide some front and some back
				elseif($max_pages - ($adjacents * 2) > ($start / $per_page) && ($start / $per_page) > ($adjacents * 2))
				{
				echo " <a href='searchResult.php?search=$search&submit=Search&start=0'>1</a> ";
				echo " <a href='searchResult.php?search=$search&submit=Search&start=$per_page'>2</a> .... ";

				$i = $start;                 
				for ($counter = ($start/$per_page)+1; $counter < ($start / $per_page) + $adjacents + 2; $counter++)
				{
				if ($i == $start){
				echo " <a href='searchResult.php?search=$search&submit=Search&start=$i'><b>$counter</b></a> ";
				}
				else {
				echo " <a href='searchResult.php?search=$search&submit=Search&start=$i'>$counter</a> ";
				}   
				$i = $i + $per_page;                
				}

				}
				//close to end; only hide early pages
				else
				{
				echo " <a href='searchResult.php?search=$search&submit=Search&start=0'>1</a> ";
				echo " <a href='searchResult.php?search=$search&submit=Search&start=$per_page'>2</a> .... ";

				$i = $start;                
				for ($counter = ($start / $per_page) + 1; $counter <= $max_pages; $counter++)
				{
				if ($i == $start){
				echo " <a href='searchResult.php?search=$search&submit=Search&start=$i'><b>$counter</b></a> ";
				}
				else {
				echo " <a href='searchResult.php?search=$search&submit=Search&start=$i'>$counter</a> ";   
				} 
				$i = $i + $per_page;              
				}
				}
				}

				//next button
				if (!($start >=$foundnum-$per_page))
				echo " <a href='searchResult.php?search=$search&submit=Search&start=$next'>Next</a> ";    
				}  
					  
				echo "</center>";
                  }
              }
            } 
				
		
		
                  ?>
	
	
	
		
</div>
	
	</div>
	</div>
	

	<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">
<div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title" align="center">Extra Details</h4><br>
		   <h5 class="modal-title" align="center" style="color: green;"><?php echo "<b>You are viewing  some details of </b>CV$id </b>";  ?></h5><hr>
	    <ul style="color: red;"><b>
		     
        </ul></b>
      </div>
      <div class="modal-body">
       <div>
		   <div id="printTable">
		 <?php
	 			
				
			echo "<h5>CV<b>$id</b></h5>";
			echo "<b>About Entry</b>: $about<br><br><br>";
		   echo "<b>Department</b>: $dept<br><br><br><br>";
		   echo "<b>Gender</b>: $gender<br><br><br><br>";
		   echo "<b>Nationality</b>: $nationality<br><br><br><br>";
		   echo "<b>Marital_status</b>: $marital_status<br><br><br><br>";
		   echo "<b>Computer Background</b>:<br><br>";
		   
		   echo "$computer_literate<br><br><br>"; 
		   echo "$computer_literate2 <br><br><br>";
		    echo "$computer_literate3<br><br><br>";
		    echo "$computer_literate4 <br><br><br>";
		   echo " $computer_literate5<br><br><br>"; 
		   echo " $computer_literate6 <br>";
		   echo "<b>Languages spoken</b><br>"; 
		   echo " $lang_spoken-";
		   echo " $lang_spoken2-";
		   echo " $lang_spoken3-";
		   echo " $lang_spoken4-";
		   echo " $lang_spoken5-";
		   echo " $lang_spoken6<br><br><br><br>";
		   echo "<b>Educational Background</b>:<br><br> $edu1 <br><b>Qualification</b>: $qualifications1<br><br><br>";
			    echo " $edu2 <br><b>Qualification</b>:$qualifications2<br><br><br>"; 
			   echo " $edu3 <br><b>Qualification</b>:$qualifications3<br><br><br>";
			   echo " $edu4 <br><b>Qualification</b>:$qualifications4<br><br><br>";
			   echo "<b>Working Experience</b>:<br><br> $org_name1 <br><b>Position held</b>: $pos_held1<br><b>Experience</b>: $work_yoe1 $work_yoem1<br><br><br>";
			   echo " $org_name2 <br><b>Qualification</b>:$pos_held2<br><b>Experience</b>: $work_yoe2 $work_yoem2<br><br><br>"; 
			   echo " $org_name3 <br><b>Qualification</b>:$pos_held3<br><b>Experience</b>: $work_yoe3 $work_yoem3<br><br><br>";
			   echo " $org_name4 <br><b>Qualification</b>:$pos_held4<br><b>Experience</b>: $work_yoe4 $work_yoem4<br><br><br><br>";
		   echo "<b>Job Type Wanted</b> :$job_type<br><br><br><br>";
		  echo "<b>Other Relevant Achievements</b> :$achievements<br><br><br><br>";
		 
		   echo "<b>Hobbies</b>: $hobbies<br><br><br><br>";
		
								
 ?>
		  </div>
      </div>
      <div class="modal-footer">
    <!--<button type='button' class='btn btn-info btn-md' data-toggle='modal' data-target='#Contact_Modal'>Pay</button>-->
		  <a href="#contactModal" role="button" data-toggle="modal" style="width:150px"; class="btn btn-primary">Pay</a>
		
		    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>  
		 
		  <span class="glyphicon glyphicon-print"></span> <a href="#null" onclick="printContent('printTable')">Print Cv</a>
		 
				<script>
		  
		  </script>	
<script type="text/javascript">
function printContent(id){
str=document.getElementById(id).innerHTML
newwin=window.open('','printwin','left=100,top=100,width=1000,height=1000')
newwin.document.write('<HTML>\n<HEAD>\n')
newwin.document.write('<TITLE>Print Page</TITLE>\n')
newwin.document.write('<script>\n')
newwin.document.write('function chkstate(){\n')
newwin.document.write('if(document.readyState=="complete"){\n')
newwin.document.write('window.close()\n')
newwin.document.write('}\n')
newwin.document.write('else{\n')
newwin.document.write('setTimeout("chkstate()",2000)\n')
newwin.document.write('}\n')
newwin.document.write('}\n')
newwin.document.write('function print_win(){\n')
newwin.document.write('window.print();\n')
newwin.document.write('chkstate();\n')
newwin.document.write('}\n')
newwin.document.write('<\/script>\n')
newwin.document.write('</HEAD>\n')
newwin.document.write('<BODY onload="print_win()">\n')
newwin.document.write(str)
newwin.document.write('</BODY>\n')
newwin.document.write('</HTML>\n')
newwin.document.close()
}

</script>
   
	

      </div>
    </div>

  </div>
</div>
Screenshot--100-.png
Screenshot--101-.png
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 24 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 24 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros