Jump to content

[SOLVED] not getting the right info, stuck on one row


HAVOCWIZARD

Recommended Posts

hi people...the search works perfect, but when it is sepose to display in displays the same record it found in the search, let say i search for toilet paper i get 3 results, correct, but it only show the first supplier of the toilet paper not the second or the 3rd one, pls help sitting the whole day and night with this problem, very gratefull, will check later, going to bed now is 1 am, long day lol..here is the code thanks

 

<h2>Search</h2> 
<form name="search" method="post" action="<?=$PHP_SELF?>">
Seach for: <input type="text" name="find" /> 

</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>


<?php
//This is only displayed if they have submitted the form 
if ($searching =="yes") 
{ 
echo "<h2>Results</h2><p>"; 

//If they did not enter a search term we give them an error 
if ($find == "") 
{ 
echo "<p>You forgot to enter a search term"; 
exit; 
} 

// We preform a bit of filtering 
$find = strtoupper($find); 
$find = strip_tags($find); 
$find = trim ($find);

//Now we search for our search term, in the field the user specified 
//$data = mysql_query("SELECT * FROM registrations WHERE upper(register_companyName) LIKE'$find', ");  
$data = mysql_query("SELECT * FROM registrations WHERE register_companyName = '$find' or register_contactPerson = '$find' or register_telephoneNumber = '$find' or register_telephoneNumber2 = '$find' or register_faxNumber = '$find' or register_cellphoneNumber = '$find' or register_emailAddress = '$find' or register_website = '$find' or register_address1 = '$find' or register_address2 = '$find' or register_area = '$find' or register_suburb = '$find' or register_province = '$find' or register_country = '$find' or register_postalCode = '$find' or register_business = '$find' or register_description = '$find' or register_trading = '$find' or register_Mcat = '$find' or register_keyword1 = '$find' or register_keyword2 = '$find' or register_keyword3 = '$find' or register_keyword4 = '$find' or register_keyword5 = '$find' or register_keyword6 = '$find' or register_keyword7 = '$find' or register_keyword8 = '$find' or register_keyword9 = '$find' or register_keyword10 = '$find' or register_keyword11 = '$find' or register_keyword12 = '$find' or register_keyword13 = '$find' or register_keyword14 = '$find' or register_keyword15 = '$find' or register_keyword16 = '$find' or register_keyword17 = '$find' or register_keyword18 = '$find' or register_keyword19 = '$find' or register_keyword20 = '$find' or register_latitude = '$find' or register_longitude = '$find'");   


//And we display the results 

//while ($result = mysql_fetch_array($data)) 
//echo $result['register_companyName']; 
//echo " "; 
//echo $result['register_telephoneNumber']; 
//echo "<br>"; 
//echo $result['register_faxNumber']; 
//echo "<br>"; 
//echo "<br>"; 


$result = mysql_fetch_array($data); 

$result_fnd = mysql_num_rows($data);

for ($loop_result = 0; $loop_result <> $result_fnd; $loop_result++)
	{	
			if($result != "")
				{				


						echo '<div id="resultDIV' . $loop_result . '" style="" class="textField">';

						echo '	<table style="width:100%;">';
						echo '		<tr>';

						echo '		<td style="width:75%">';
						// company name
						echo '	<a href="javascript:showHideDIV(\'resultDropDownDIV' .$loop_result . '\')" class="linkResults">';

						//ob_start("highlight");
						echo htmlspecialchars( stripslashes( $result['register_companyName']) );
						//ob_end_flush();

						echo '</a>';
						echo '		</td>';
						echo '		</tr>';

						echo '		<tr>';
						echo '		<td>';
						echo '			Relevancy: <img src="images/relevancy.gif" style="width:' . ($result[$loop_result]["relevancy"]  / 2) . 'px; height:8px" alt="relevancy_rating" /> ' . $result[$loop_result]["relevancy"] . '%';
						echo '		<td>';


						echo '		</tr>';
						echo '	</table>';

						echo '	<div id="resultDropDownDIV' . $loop_result . '" style="width:95%; display:none;"> ';
						echo '		<table style="width:100%;table-layout:fixed"> ';


						if($result['$register_business'])
						{
							// business
							echo '			<tr> ';
							echo '				<td style="width:20%; vertical-align:top"> ';
							echo '					Business: ' ;	
							echo '				</td> ';
							echo '				<td style="width:40%"> ';

							echo '					';

							// start our highlight procedure
							ob_start("highlight");

							echo htmlspecialchars( stripslashes($result['register_business']) );

							// end our highlight procedure
							ob_end_flush();

							echo '				</td> ';
							echo '				</td> ';
							echo '			</tr> ';
						}

						if($result['register_description'])
						{
							// description
							echo '			<tr> ';
							echo '				<td style="vertical-align:top"> ';
							echo '					Description: ';
							echo '				</td> ';
							echo '				<td> ';

							echo '					<pre class="textField">';

							ob_start("highlight");

							echo htmlspecialchars( stripslashes( $result['register_description']));
							// end our highlight procedure
							ob_end_flush();

							echo "</pre>";

							echo '				</td> ';
							echo '			</tr> ';
						}

						if($result['register_address1'] || $result['register_address2'] || $result['register_area'] || $result['register_suburb'] || $result['register_province'] || $result['register_country'] || $result['register_postalCode'])
						{
							// Address
							echo '			<tr> ';
							echo '				<td style="vertical-align:top"> ';
							echo '					Address: ';
							echo '				</td> ';
							echo '				<td style="vertical-align:top"> ';

							if($result['register_address1'])
							{
								echo '				';

								ob_start("highlight");
								echo $result['register_address1'];
								// end our highlight procedure
								ob_end_flush();

								echo "<br />";
							}
							if($result['register_address2'])
							{
								echo '				';

								ob_start("highlight");
								echo $result['register_address2'];
								// end our highlight procedure
								ob_end_flush();

								echo "<br />";
							}
							if($result['register_area'])
							{
								echo '				';

								ob_start("highlight");
								echo $result['register_area'];
								// end our highlight procedure
								ob_end_flush();

								echo "<br />";
							}
							if($result['register_suburb'])
							{
								echo '				';

								ob_start("highlight");
								echo $result['register_suburb'];
								// end our highlight procedure
								ob_end_flush();

								echo "<br />";
							}
							if($result['register_province'])
							{
								echo '				';

								ob_start("highlight");
								echo $result['register_province'];
								// end our highlight procedure
								ob_end_flush();

								echo "<br />";
							}
								if($result['register_country'])
							{
								echo '				';

								ob_start("highlight");
								echo $result['register_country'];
								// end our highlight procedure
								ob_end_flush();

								echo "<br />";
							}
							if($result['register_postalCode'])
							{
								echo '				';

								ob_start("highlight");
								echo $result['register_postalCode'];
								// end our highlight procedure
								ob_end_flush();

								echo "<br />";
							}
							echo '				</td> ';
							echo '			</tr> ';

							echo '			<tr><td> </td></tr> ';
						}
							if($result['register_contactPerson'])
						{
							// Contact Person
							echo '			<tr> ';
							echo '				<td style="width:30%; vertical-align:top"> ';
							echo '					Contact Person: ';
							echo '				</td> ';
							echo '				<td style="width:70%"> ';
							echo '					';

							echo  $result['register_contactPerson'];
							echo '				</td> ';
							echo '			</tr> ';

							echo '			<tr><td> </td></tr> ';
							}

						if($result['register_telephoneNumber'])
						{
							// telephone
							echo '			<tr> ';
							echo '				<td style="width:30%; vertical-align:top"> ';
							echo '					Tel: ';
							echo '				</td> ';
							echo '				<td style="width:70%"> ';
							echo '					';

							ob_start("highlight");
							echo $result['register_telephoneNumber'];
							// end our highlight procedure
							ob_end_flush();

							echo '				</td> ';
							echo '			</tr> ';
						}

						if($result['register_telephoneNumber2'])
						{
							// Alternative telephone
							echo '			<tr> ';
							echo '				<td style="width:30%; vertical-align:top"> ';
							echo '					Tel: ';
							echo '				</td> ';
							echo '				<td style="width:70%"> ';
							echo '					';

							ob_start("highlight");
							echo $result['register_telephoneNumber2'];
							// end our highlight procedure
							ob_end_flush();

							echo '				</td> ';
							echo '			</tr> ';
						}

						if($result['register_faxNumber'])
						{
							// fax
							echo '			<tr> ';
							echo '				<td style="width:30%; vertical-align:top"> ';
							echo '					Fax: ';
							echo '				</td> ';
							echo '				<td style="width:70%"> ';
							echo '					';

							ob_start("highlight");
							echo $result['register_faxNumber'];
							// end our highlight procedure
							ob_end_flush();


							echo '				</td> ';
							echo '			</tr> ';
						}

						if($result['register_cellphoneNumber'])
						{
							// cellphone
							echo '			<tr> ';
							echo '				<td style="width:30%; vertical-align:top"> ';
							echo '					Cell: ';
							echo '				</td> ';
							echo '				<td style="width:70%"> ';
							echo '					';

							ob_start("highlight");
							echo $result['register_cellphoneNumber'];
							// end our highlight procedure
							ob_end_flush();

							echo '				</td> ';
							echo '			</tr> ';
						}
						if($result['register_trading'])
						{
							// trading hours
							echo '			<tr> ';
							echo '				<td style="vertical-align:top"> ';
							echo '					Trading Hours: ';
							echo '				</td> ';
							echo '				<td> ';

							echo '					<pre class="textField">';

							ob_start("highlight");

							echo htmlspecialchars( stripslashes( $result['register_trading'] ) );
							// end our highlight procedure
							ob_end_flush();

							echo "</pre>";

							echo '				</td> ';
							echo '			</tr> ';
						}

						if($result['register_emailAddress'])
						{
							// email
							echo '			<tr> ';
							echo '				<td style="width:30%; vertical-align:top"> ';
							echo '					Email: ';
							echo '				</td> ';
							echo '				<td style="width:70%"> ';
							echo '					<a href="mailto:' . htmlspecialchars( stripslashes( $result['register_emailAddress'] ) ) . '"  class="linkResults">';

							ob_start("highlight");
							echo htmlspecialchars( stripslashes( $result['register_emailAddress'] ) );
							ob_end_flush();

							echo '</a>';
							echo '				</td> ';
							echo '			</tr> ';
						}

						if($result['register_website'])
						{
							// website
							echo '			<tr> ';
							echo '				<td style="width:30%; vertical-align:top"> ';
							echo '					Website: ';
							echo '				</td> ';
							echo '				<td style="width:70%"> ';

							if(stristr(htmlspecialchars( stripslashes( $result['register_website'] ) ), "http://"))
							{
								echo	'				<a href="' . htmlspecialchars( stripslashes( $result['register_website'] ) ) . '"  class="linkResults">';

								ob_start("highlight");
								echo htmlspecialchars( stripslashes( $result['register_website'] ) );
								// end our highlight procedure
								ob_end_flush();

								echo '</a>';

							}
							else
							{
								echo	'				<a href="http://' . htmlspecialchars( stripslashes( $result['register_website'] ) ) . '" target="_blank"  class="linkResults">http://';

								ob_start("highlight");
								echo htmlspecialchars( stripslashes( $result['register_website'] ) );
								ob_end_flush();

								echo '</a>';
							}

							echo '				</td> ';
							echo '			</tr> ';
							}

						echo '			<tr><td> </td></tr>';
						echo '		</table> ';
						echo '	</div> ';
						echo '</div> ';
						echo "<br />";


				}

	}

//This counts the number or results - and if there wasn't any it gives them a little message explaining that 
$anymatches=mysql_num_rows($data); 
if ($anymatches == 0) 
{ 
echo "Sorry, but we can not find an entry to match your query<br><br>"; 
} 

//And we remind them what they searched for 
echo "<b>Searched For:</b> " .$find; 
} 
?>

Link to comment
Share on other sites

The simplest way is like this:

 

while ($row = mysql_fetch_array($data)) {
  print "<pre>";
  var_dump($row);
  print "</pre>";
}

 

Try placing that before your "$result = mysql_fetch_Array($data)" line.  The key is that you must "fetch_array" for EACH row of data.  A single call will not fetch all your results.

 

Once you understand how that works, you can replace the inside of that loop with your html display code.  The values you will be referencing will look like:

 

echo $row['register_companyName'];

Link to comment
Share on other sites

got it to work had to remove the loop statement and the if statement and when back to basics, lol, when i had the loop and the brackets it stays on the same value, so i added my loop_result as 0 and at the end of the echo's just put n mins and it worked, peferctly, thanks aloot for all the help guys keep it up, :) see later

Link to comment
Share on other sites

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.