Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Location
    Velsen Noord, Netherlands
    Posts
    218
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Question Display search results mysql in same page

    I have created a search form, to display results (specified) in text fields. The function worked before, but I changed the navigation part.

    Now the code that I have isn't working.

    When I hit the zoek button (search in dutch), I get redirected to the index page with some url:

    index.php?search2=Henk&submit2=Zoek

    The original search page is the following:

    index.php?id=zoeken (the code just above is this page)

    So this also where the results should be displayed, but their not.

    Here the code I use:
    Code:
    <?php
    
      // Get the search variable from URL
    
      $var = @$_GET['search'];
      $trimmed = trim($var); //trim whitespace from the stored variable
    
    // rows to return
    $limit=10; 
    
    //connect to your database ** EDIT REQUIRED HERE **
    mysql_connect("localhost","user","password"); //(host, username, password)
    
    //specify database ** EDIT REQUIRED HERE **
    mysql_select_db("database") or die("Unable to select database"); //select which database we're using
    
    // Build SQL Query  
    $query = "select * from nbs_vmb_contacts where nbs_vmb_group_id = '2' and nbs_vmb_contact_name like \"%$trimmed%\" or nbs_vmb_zip like \"%$trimmed%\""; // EDIT HERE and specify your table and field names for the SQL query
    
     $numresults=mysql_query($query);
     $numrows=mysql_num_rows($numresults);
    
      $result = mysql_query($query) or die("Couldn't execute query");
    
    // now you can display the results returned
      while ($row= mysql_fetch_array($result)) {
      	$name = $row["nbs_vmb_contact_name"];
      	$zip = $row["nbs_vmb_zip"];
    	$shared = $row["nbs_vmb_shared"];
    	$aanhef = $row["nbs_vmb_contact_aanhef"];
    	$prechar = $row["nbs_vmb_contact_prechar"];
    	$tussenv = $row["nbs_vmb_contact_tussenv"];
    	$sur = $row["nbs_vmb_contact_sur"];
    	$address = $row["nbs_vmb_address"];
    	$number = $row["nbs_vmb_number"];
    	$numberadd = $row["nbs_vmb_numberadd"];
    	$postbusnr = $row["nbs_vmb_postbusnr"];
    	$city = $row["nbs_vmb_city"];
    	$country = $row["nbs_vmb_country"];
    	$phone = $row["nbs_vmb_phone"];
    	$mobphone = $row["nbs_vmb_mobphone"];
    	$email = $row["nbs_vmb_emailadres"];
    	$day = $row["nbs_vmb_contact_day"];
    	$month = $row["nbs_vmb_contact_month"];
    	$year = $row["nbs_vmb_contact_year"];
    	$burnyear = $row["nbs_vmb_year"];
    	$selfburns = $row["nbs_vmb_selfburns"];
    	$relativeto = $row["nbs_vmb_relativeto"];
    	$profrelatie = $row["nbs_vmb_profrelatie"];
    	$psychonet = $row["nbs_vmb_psychonet"];
    	$revalinet = $row["nbs_vmb_revalinet"];
    	$reintegranet = $row["nbs_vmb_reintegranet"];
    	$juridisch = $row["nbs_vmb_juridischehulp"];
    	$nomail = $row["nbs_vmb_nomail"];
    	$comments = $row["nbs_vmb_comments"];
      }
    ?>
    <div id="left">
    <div id="left_01">
    <div id="toppage">
    	<h3><?php echo $tcm_label[8]; ?></h3>
    </div>
    <div id="toptable">
        <form action="" method="get" name="form_search">
          	<input type="text" class="search2" name="search2"/>
            <input type="submit" name="submit2" class="buttons" value="Zoek"/>
        </form>
    </div>
    <div style="margin:0px 1px 0px 1px">
      <form id="form_ins_contact" name="form_ins_contact" method="post" action="">
        <table width="780" height="600" border="0" align="center" cellpadding="0" cellspacing="2">
          <tr>
            <td width="122" align="right"><strong><?php echo $tcm_label[54]; ?></strong></td>
            <td class="td_no_border">
            	<select name="nbs_vmb_group_id" id="nbs_vmb_group_id">
              		<option value="1">NBS</option>
            	</select>        
            </td>
            <td align="right"></td>
            <td class="td_no_border2"></td>
            <td width="192" align="right" class="td_no_border2"></td>
            <td class="td_no_border2"></td>
          </tr>
          <tr>
            <td align="right"><strong><?php echo $tcm_label[19]; ?></strong></td>
            <td width="75" class="td_no_border">
            	<select name="nbs_vmb_contact_aanhef">
            		<option value="m" <?php if ($nbs_vmb_contact_aanhef == "m") echo "selected" ?> <?php if ($aanhef == "m") echo "selected"; ?>>Dhr</option>
                    <option value="v" <?php if ($nbs_vmb_contact_aanhef == "v") echo "selected" ?> <?php if ($aanhef == "v") echo "selected"; ?>>Mevr</option>
            	</select>        
            </td>
            <td class="td_no_border2"></td>
            <td class="td_no_border2"></td>
            <td class="td_no_border2"></td>
            <td class="td_no_border2"></td>
          </tr>
          <tr>
            <td align="right"><strong><?php echo $tcm_label[21]; ?></strong></td>
            <td colspan="3" class="td_no_border"><input name="nbs_vmb_contact_prechar" type="text" id="nbs_vmb_contact_prechar" size="20" value="<?php echo $prechar ?>" /></td>
            <td align="right"><strong><?php echo $tcm_label[22]; ?></strong></td>
            <td class="td_no_border"><input name="nbs_vmb_contact_name" type="text" id="nbs_vmb_contact_name" size="45" value="<?php echo $name ?>" /></td>
          </tr>
          <tr>
            <td align="right"><strong><?php echo $tcm_label[23]; ?></strong></td>
            <td colspan="3" class="td_no_border"><input name="nbs_vmb_contact_tussenv" type="text" id="nbs_vmb_contacttussenv" size="15" value="<?php echo $tussenv ?>" /></td>
            <td align="right"><strong><?php echo $tcm_label[24]; ?></strong></td>
            <td class="td_no_border"><input name="nbs_vmb_contact_sur" type="text" id="nbs_vmb_contact_sur" size="45" value="<?php echo $sur ?>" /></td>
          </tr>
          <tr>
            <td align="right"><strong><?php echo $tcm_label[25]; ?></strong></td>
            <td colspan="3" class="td_no_border"><input name="nbs_vmb_address" type="text" id="nbs_vmb_address" size="55" value="<?php echo $address ?>" /></td>
          </tr>
          <tr>
          	<td align="right"><strong><?php echo $tcm_label[26]; ?></strong></td>
            <td colspan="3" class="td_no_border"><input name="nbs_vmb_number" type="text" id="nbs_vmb_number" size="15" value="<?php echo $number ?>" /></td>
            <td align="right"><strong><?php echo $tcm_label[27]; ?></strong></td>
            <td class="td_no_border" width="194"><input name="nbs_vmb_numberadd" type="text" id="nbs_vmb_numberadd" size="15" value="<?php echo $numberadd ?>" /></td>
          </tr>
          <tr>
          	<td align="right"><strong><?php echo $tcm_label[28]; ?></strong></td>
            <td colspan="3" class="td_no_border"><input name="nbs_vmb_postbusnr" type="text" id="nbs_vmb_postbusnr" size="20" value="<?php echo $postbusnr ?>" /></td>
            <td align="right"><strong><?php echo $tcm_label[29]; ?></strong></td>
            <td class="td_no_border"><input name="nbs_vmb_zip" type="text" id="nbs_vmb_zip" size="15" value="<?php echo $zip ?>" /></td>
          </tr>
          <tr>
            <td align="right"><strong><?php echo $tcm_label[30]; ?></strong></td>
            <td colspan="3" class="td_no_border"><input name="nbs_vmb_city" type="text" id="nbs_vmb_city" size="55" value="<?php echo $city ?>" /></td>
            <td align="right"><strong><?php echo $tcm_label[31]; ?></strong></td>
            <td class="td_no_border"><input name="nbs_vmb_country" type="text" id="nbs_vmb_country" size="35" value="<?php echo $country ?>" /></td>
          </tr>
          <tr>
            <td align="right"><strong><?php echo $tcm_label[32]; ?></strong></td>
            <td colspan="3" class="td_no_border"><input name="nbs_vmb_phone" type="text" id="nbs_vmb_phone" size="30" value="<?php echo $phone ?>" /></td>
            <td align="right"><strong><?php echo $tcm_label[33]; ?></strong></td>
            <td class="td_no_border"><input name="nbs_vmb_mobphone" type="text" id="nbs_vmb_mobphone" size="30" value="<?php echo $mobphone ?>" /></td>
          </tr>
          <tr>
            <td align="right"><strong><?php echo $tcm_label[34]; ?></strong></td>
            <td colspan="3" class="td_no_border"><input name="nbs_vmb_emailadres" type="text" id="nbs_vmb_emailadres" size="55" value="<?php echo $email ?>" /></td>
            <td align="right"><strong><?php echo $tcm_label[35]; ?></strong></td>
            <td class="td_no_border"><input name="nbs_vmb_contact_day" type="text" id="nbs_vmb_contact_day" maxlength="2" size="1" value="<?php echo $day ?>" />
            <input name="nbs_vmb_contact_month" type="text" id="nbs_vmb_contact_month" maxlength="2" size="1" value="<?php echo $month ?>" />
            <input name="nbs_vmb_contact_year" type="text" id="nbs_vmb_contact_year" maxlength="4" size="3" value="<?php echo $year ?>" /></td>
          </tr>
          <tr>
            <td align="right"><strong><?php echo $tcm_label[36]; ?></strong></td>
            <td colspan="3" class="td_no_border"><input value="1" name="nbs_vmb_lid_vmb" type="checkbox" <?php if ($nbs_vmb_lid_vmb == "1") echo 'checked="checked"'; ?> /></td>
          </tr>
          <tr>
            <td align="right"><strong><?php echo $tcm_label[37]; ?></strong></td>
            <td colspan="3" class="td_no_border"><input value="1" name="nbs_vmb_selfburns" type="checkbox" <?php if ($nbs_vmb_selfburns == "1") echo 'checked="checked"'; ?> <?php if ($selfburns ==1) echo 'checked="checked"'; ?> /></td>
            <td align="right"><strong><?php echo $tcm_label[38]; ?></strong></td>
            <td class="td_no_border"><input name="nbs_vmb_year" type="text" id="nbs_vmb_year" size="15" value="<?php echo $burnyear ?>" /></td>
          </tr>
          <tr>
            <td align="right"><strong><?php echo $tcm_label[39]; ?></strong></td>
            <td colspan="3" class="td_no_border"><select name="nbs_vmb_relativeto" id="nbs_vmb_relativeto">
            	<option selected="selected">Selecteer relatie</option>
                <option id="Relatie" <?php if ($nbs_vmb_relativeto == "Relatie") echo "selected" ?> <?php if ($relativeto == "Relatie") echo "selected"; ?>>Relatie</option>
                <option id="Ouder" <?php if ($nbs_vmb_relativeto == "Ouder") echo "selected" ?> <?php if ($relativeto == "Ouder") echo "selected"; ?>>Ouder</option>
                <option id="Broer/zus" <?php if ($nbs_vmb_relativeto == "Broer/zus") echo "selected" ?> <?php if ($relativeto == "Broer/zus") echo "selected"; ?>>Broer/zus</option>
                <option id="Familie" <?php if ($nbs_vmb_relativeto == "Familie") echo "selected" ?> <?php if ($relativeto == "Familie") echo "selected"; ?>>Familie</option>
                <option id="Vriend" <?php if ($nbs_vmb_relativeto == "Vriend") echo "selected" ?> <?php if ($relativeto == "Vriend") echo "selected"; ?>>Vriend</option>
              </select></td>
          </tr>
           <tr>
            <td align="right"><strong><?php echo $tcm_label[40]; ?></strong></td>
            <td colspan="3" class="td_no_border"><input value="1" name="nbs_vmb_profrelatie" type="checkbox" <?php if ($nbs_vmb_profrelatie == "1") echo 'checked="checked"'; ?> <?php if ($profrelatie ==1) echo 'checked="checked"'; ?> /></td>
            <td align="right"><strong><?php echo $tcm_label[41]; ?></strong></td>
            <td class="td_no_border"><input value="1" name="nbs_vmb_psychonet" type="checkbox" <?php if ($nbs_vmb_psychonet == "1") echo 'checked="checked"'; ?> <?php if ($psychonet ==1) echo 'checked="checked"'; ?>/></td>
          </tr>
          <tr>
          	<td align="right"><strong><?php echo $tcm_label[42]; ?></strong></td>
            <td colspan="3" class="td_no_border"><input value="1" name="nbs_vmb_revalinet" type="checkbox" <?php if ($nbs_vmb_revalinet == "1") echo 'checked="checked"'; ?> <?php if ($revalinet ==1) echo 'checked="checked"'; ?> /></td>
            <td align="right"><strong><?php echo $tcm_label[43]; ?></strong></td>
            <td class="td_no_border"><input value="1" name="nbs_vmb_reintegranet" type="checkbox" <?php if ($nbs_vmb_reintegranet == "1") echo 'checked="checked"'; ?> <?php if ($reintegranet ==1) echo 'checked="checked"'; ?>/></td>
          </tr>
          <tr>
            <td align="right"><strong><?php echo $tcm_label[44]; ?></strong></td>
            <td colspan="3" class="td_no_border"><input value="1" name="nbs_vmb_juridischehulp" type="checkbox" <?php if ($nbs_vmb_juridischehulp == "1") echo 'checked="checked"'; ?> <?php if ($juridisch ==1) echo 'checked="checked"'; ?>/></td>
          </tr>
          <tr>
            <td align="right"><strong><?php echo $tcm_label[45]; ?></strong></td>
            <td colspan="3" class="td_no_border"><input value="1" name="nbs_vmb_nomail" type="checkbox" <?php if ($nbs_vmb_nomail == "1") echo 'checked="checked"'; ?> <?php if ($nomail ==1) echo 'checked="checked"'; ?>/></td>
          </tr>
          <tr>
            <td align="right"><strong><?php echo $tcm_label[46]; ?></strong></td>
            <td colspan="3" class="td_no_border"><textarea name="nbs_vmb_comments" cols="30" rows="6" id="nbs_vmb_comments"><?php echo $comments ?></textarea></td>
            <td></td>
            <td class="td_no_border2"><img src="../images/intra icon.png" width="96" height="96" /></td>
          </tr>
        </table>
        <table width="281" border="0" align="center" cellpadding="0" cellspacing="2">
          <tr>
            <td align="center" class="td_no_border2" nowrap="nowrap">
            	<input type="submit" class="buttons" value="Wijzig Contact" />
            </td>
            <td align="center" class="td_no_border2" nowrap="nowrap">
            	<input type="submit" class="buttons" value="Verwijder Contact" />
            </td>
          </tr>
        </table>
      </form>
      </div>
    </div>
    </div>
    Please any help.

  • #2
    New Coder
    Join Date
    Aug 2009
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Do you want to display results in the same page with the Zoek?

    I am not an expert but did this by writing the url of the result page to the action part of search form. And also they're together in a page.

    For example my page results are shown on a page like "search_result.php" and also my search form in this page just above the php codes ...

    Code:
    <p><font face="verdana" size="2" color="#ffffff"> <b>Italian - Turkish // Turkish  Italian </b> </p>
    <form method="post" action="search_result.php">
    <input type="text" name="search" size=45 maxlength=45>
    <input type="Submit" name="Ara" value="Ara">
    </form>
    and then starts my php codes

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Location
    Velsen Noord, Netherlands
    Posts
    218
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Well I tried that before but because I use a different kind of navigation, it won't work.

    Here is the code I use for the navigation:
    Code:
    <?php
    // -----------------------------------------------------------------|
    //						   PHP Contact Manager						|	
    //																	|
    //						http://it-net-design.com					|
    //																	|
    //	    	Licensed under GNU GENERAL PUBLIC LICENSE Version 2		|
    //																	|
    // -----------------------------------------------------------------|
    require_once('includes/connTCM.php'); 
    $tcm_lang_file = 'includes/lang_nl.php'; 
    require_once($tcm_lang_file); 
    
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>NBS contact database</title>
    <script type="text/javascript" src="includes/the_scripts.js"></script>
    <script type="text/javascript" src="includes/prototype.js"></script>
    <script type="text/javascript" src="includes/partialupdater.js"></script>
    <link href="tcm.css" rel="stylesheet" type="text/css" />
    <link href="../css/default.css" type="text/css" rel="stylesheet" />
    <style type="text/css">
    	scrollbar-arrow-color:#FFF; 
    	scrollbar-track-color:#FFF; 
    	scrollbar-face-color:#E0F5CC; 
    	scrollbar-highlight-color:#FFF; 
    	scrollbar-3dlight-color:#FFF; 
    	scrollbar-darkshadow-color:#FFF; 
    	scrollbar-shadow-color:#FFF; 
    </style>
    </head>
    <body>
    <div id="container">
    	<div id="wrapper">
    		<div id="logo">
            <H1><font face="Verdana" size="4" color="#2852A8">Contact database NBS</font></H1>
                <div id="navigation">
           	  	<ul>
                	<li><a href="index.php?id=home" class="buttons">Home</a></li>
                    <li><a href="index.php?id=selecties" class="buttons">Selecties</a></li>
                    <li><a href="index.php?id=zoeken" class="buttons">Zoeken</a></li>
                </ul>
           	  	</div>
            </div>
    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td height="900" align="center" valign="middle" class="td_no_border"><table width="790" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td class="td_no_border">
            <?php
    			switch($_GET['id']) {
    
    			default:
    			include('home.php');
    			break;
    
    			case "selecties":
    			include('selecties.php');
    			break;
    
    			case "zoeken":
    			include('search.php');
    			break;
    
    			}
    		?>
    <div style="padding:3px;"></div></td>
          </tr>
        </table>
    <img src="blank.gif" name="loader" id="loader" alt="" style="position:relative; top: -27px; left:160px" /><img src="loading.gif" id="loader_1" alt="Date in curs de procesare..." style="position:relative; top: -26px; left:160px; display:none" />
        </td>
      </tr>
    </table>
    </div>
    </div>
    </body>
    </html>
    The switch part is the navigation.

  • #4
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The best options on it is to use Ajax + php it could solve your problem

    Thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •