Newbie

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fanturex
Forum Newbie
Posts: 5
Joined: Mon Jan 17, 2005 10:38 am

Newbie

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
fanturex
Forum Newbie
Posts: 5
Joined: Mon Jan 17, 2005 10:38 am

Fantastic

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

search the forums for "pagination"
fanturex
Forum Newbie
Posts: 5
Joined: Mon Jan 17, 2005 10:38 am

Many Thanks

Post by fanturex »

Thankyou, but I wish I hadn't asked. Time to get the php guide for dummies backout.

Many Thanks

Chris
Post Reply