Re: mySQL query in PHP - Parse error
- From: noone <noone@xxxxxxxxxxx>
- Date: Sat, 04 Feb 2006 01:37:41 GMT
JT wrote:
I am working on a basic webpage in PHP connecting to a mySQL database,
here is my query...
//query 1
$query_rs_staff = "SELECT * FROM jtStaff WHERE
locationID=".$_GET['myDesk'];
$rs_staff = mysql_query($query_rs_staff);
$row_rs_staff = mysql_fetch_assoc($rs_staff);
//query 2
$query_rs_section = "SELECT * FROM jtSection WHERE
sectionID=$row_rs_staff['sectionID']";
$rs_section = mysql_query($query_rs_section);
$row_rs_ssection = mysql_fetch_assoc($rs_section);
?>
I had it working with query 1. then I added query 2 to get from another
table, some additional data. So i have no problems with query 1. When
ran thru my server, it throws back a parse error on line 20, which is
the first line of query 2. can someone tell me the correct syntax for
what i am trying to do here?
thanks
why not do this in one query.. It saves coding and reduces network/system traffic by only returning columns and rows that are necessary instead of "give me everything and let the program sort it out". That method is considered VERY bad coding practices, but taught in way too many institutions of "higher lerarning".
(you will need to fix the php exact syntax for this...)
select a.field1,a.field2,,,,b.field1,b.field2,,,,
from jtstaff a, jtsection b
where a.locationID= $_GET['myDesk']
and b.sectionid=a.sectionid
this will return all rows where locationid = mydesk and the jsstaff.sectionid is in jtsection.stationid
depending upon what you are actually trying to retreive, you may also need a locationid column (field) in the jtsection table to make them more unique - then just add:
and a.locationid=b.locationid
to the end of the sql statement above.
Michael Austin
DBA.
.
- Follow-Ups:
- Re: mySQL query in PHP - Parse error
- From: JT
- Re: mySQL query in PHP - Parse error
- References:
- mySQL query in PHP - Parse error
- From: JT
- mySQL query in PHP - Parse error
- Prev by Date: Data transfer problem - ideas/solutions wanted (please)
- Next by Date: Re: need to do a string replace of "asc" to "desc" or "desc" to "asc" first occurrence only
- Previous by thread: Re: mySQL query in PHP - Parse error
- Next by thread: Re: mySQL query in PHP - Parse error
- Index(es):