Page 1 of 1

Newbie

Posted: Mon Jan 17, 2005 10:42 am
by fanturex
Hello

I was wondering if any experts could point me in the right direction.

I have a mysql db setup and can pull records off using the following command:

Code: Select all

$result = mysql_query("SELECT * FROM TEL WHERE Last  LIKE '$search%' limit 10");
Which will search the field LAST, I need to search multiple fields and have tried:

Code: Select all

$result = mysql_query("SELECT * FROM TEL WHERE Last OR Department LIKE '%$search%' limit 10");
Which then only pulls info off the DEPARTMENT field.

This is all very new and without sounding sad I am really excited about developing scripts within php.

If anyone has any ideas or suggestions, they are most welcome.

Many Thanks

Chris

Posted: Mon Jan 17, 2005 10:49 am
by feyd
2 ways:

Code: Select all

SELECT * FROM `TEL` WHERE `Last` LIKE '%$search%' OR `Department` LIKE '%$search%' LIMIT 10
or with Full Text Searching on:

Code: Select all

SELECT * FROM `TEL` WHERE MATCH (`Last`, `Department`) AGAINST('$search') LIMIT 10

Fantastic

Posted: Mon Jan 17, 2005 11:06 am
by fanturex
Many thanks, works like a charm

All I need to do now is how to learn about spreading the results across many pages.

My db contains so much info but due to the website design I have to limit the echo's to 10 listings per page

Code: Select all

<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","",""); 
	
//select which database you want to edit
mysql_select_db("meetings"); 

$search=$_POST["search"];

//get the mysql and store them in $result
//change whatevertable to the mysql table you're using
//change whatevercolumn to the column in the table you want to search
$result = mysql_query("SELECT * FROM `TEL` WHERE `Last` LIKE '%$search%' OR `Department` LIKE '%$search%' limit 10");

//grab all the content
while($row = mysql_fetch_array($result))
{	
   //the format is $variable = $r["nameofmysqlcolumn"];
   //modify these to match your mysql table columns
  
    $First = $row["First"];
	$Last = $row["Last"]; 
	$Title = $row["Title"];
	$Company = $row["Company"];
	$Department = $row["Department"];
	$Phone = $row["Phone"];
	$Email = $row["Email"];
	$Office = $row["Office"];
	
   //display the row
   echo("<p>Name: $First $Last<div align=centre>
		 Department: $Department </br>
	Extension: $Phone </br>
	Email Address: $Email </br>
   <hr></div></p>");
   }
?>
I suppose what I mean is how would one add a next button with the additional echo info links to the site.

I really hope that makes sense.

Once again many thanks

Chris

Posted: Mon Jan 17, 2005 11:11 am
by feyd
search the forums for "pagination"

Many Thanks

Posted: Mon Jan 17, 2005 11:51 am
by fanturex
Thankyou, but I wish I hadn't asked. Time to get the php guide for dummies backout.

Many Thanks

Chris