View Single Post
  #14 (permalink)  
Old 08-24-2007, 05:31 PM
scotthai scotthai is offline
WebProWorld New Member
 

Join Date: Sep 2006
Location: San Jose
Posts: 24
scotthai RepRank 0
Default Re: MySQL Multiple Select Question

hewgriff,
MySQL, SQL, ORACLE - they all run similar syntax, but it is actually not so hard to find the information you need.

//PHP REFERENCE
// find all ids like some name in category
// table bigrows has n_id, and cat_id
$sql = @mysql_query("SELECT * FROM 'bigrows' WHERE n_id = '2' AND cat_id = '1'");
This returns a results set from 'bigrows' (table name) where the lookup item, person id is 2 while also returning a second event qualifier of cat_id = 1. This is great when looking up loads of data, you could look for all daves from california like so.

$name = $_POST,$_GET,$_REQUEST,(ETC) ['name'] where the input is Dave, david, dave // example of one type of variable getter method --> POST,GET,REQUEST
$name = strtolower($name);
$sql = @mysql_query("SELECT * FROM users WHERE n_name LIKE '%$name%' AND state_id ='1' AND state_name = ' CALIFORNIA'");

There are also many different ways of collecting data across multiple datasets with a real well built database. So the challenge is first creating the database to function well within the scope of the project.

So onto specific names from the table,

$sql = @mysql_query("SELECT name,date,id,timestamp FROM bigtable WHERE eid = '123');
This returns the rows from the select statment,
if using PHP you can go further and create an associative array of the data.

$row = mysql_fetch_assoc($sql);
echo $row['name']; // prints out the name as a match to eid 123

You can also use the MATCH method of SQL (MySQL 4.1)
SELECT * FROM 'bigtable' WHERE MATCH (name,date,id,timestamp) AGAINST ('%word%');
SELECT * FROM 'bigtable' WHERE MATCH(eid) AGAINT (eid);

The later would get you an absolute match against the eid, however the drawback to this method of searching is that MySQL has in the default config that the match must be longer than 3 characters, so this method works better when doing a FULL INDEX search.

For what you are looking for the best bet is going to be a select against the rows you wish to fetch information from and then doing a WHERE clause as an exact match to the EID.

SELECT name,id,timestamp,date FROM bigtable WHERE EID = '123';

I hope this helps. If you want to email me the actual problem in a better description I could try and help out better.

Scott Haines
web design and development
__________________
Scott Haines
Web Designer, San Jose

Last edited by mjtaylor : 07-07-2008 at 11:15 AM. Reason: please use your sig file to link to your site, thanks
Reply With Quote