can any one explain this query to me??

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
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

can any one explain this query to me??

Post by itsmani1 »

Code: Select all

<?php

$select = "SELECT sec.idnum AS 'ID Number', sec.lname AS 'Last Name', secy.fname AS 'First Name' FROM table WHERE (($search) LIKE '%$svalue%')) ORDER BY $order"; 

?>
can any one explain this query to me specially sec.idum etc, and
(($search)LIKE '%$values%')) ORDER BY $order";

i havn't used this type of query ever....
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

it returns all rows where field $search is like $values and orders that resultset by field $order. All of them are variable, thus can be adjusted based on user input or something. sec.idnum won't work because there's no such table mentioned in FROM clause.
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

Code: Select all

<?php

$select = "SELECT sec.idnum AS 'ID Number', sec.lname AS 'Last Name', secy.fname AS 'First Name' FROM (itable INNER JOIN linktable ON itable.policynumber = linktable.policynumber) INNER JOIN security ON linktable.agentid = sec.idnum WHERE (($search) LIKE '%$svalue%')) ORDER BY $order"; 
?>
Now this is the complete qyery. please tell me wot sec.idmun means and 2nd thing is

Code: Select all

FROM (itable INNER JOIN linktable ON itable.policynumber = linktable.policynumber) INNER JOIN security ON linktable.agentid = sec.idnum
wot is this???

Regards!!!!
Breckenridge
Forum Commoner
Posts: 62
Joined: Thu Sep 09, 2004 11:10 pm
Location: Breckenridge, Colorado

Post by Breckenridge »

sec.idnum is:

sec is a table name
idnum of a field in the table named sec

Code: Select all

select idnum from sec
is more or less the same as:

Code: Select all

select sec.idnum from idnum
when you use the AS var_name you are instructing the db engine to use var_name insted of the actual table field which is idnum that is all

to understand joins please visit:
http://dev.mysql.com/doc/mysql/en/JOIN.html
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

Breckenridge wrote:sec.idnum is:

sec is a table name
idnum of a field in the table named sec

Code: Select all

select idnum from sec
is more or less the same as:

Code: Select all

select sec.idnum from idnum
when you use the AS var_name you are instructing the db engine to use var_name insted of the actual table field which is idnum that is all

to understand joins please visit:
http://dev.mysql.com/doc/mysql/en/JOIN.html
well thankx for the help now one more thing left that i donot know

Code: Select all

<?php
FROM (itable INNER JOIN linktable ON itable.policynumber = linktable.policynumber) INNER JOIN security ON linktable.agentid = sec.idnum

?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

from mysql_manual
INNER JOIN and , (comma) are semantically equivalent in the absence of a join condition: both will produce a Cartesian product between the specified tables (that is, each and every row in the first table will be joined onto all rows in the second table).
Post Reply