SephirGaine Posted August 2, 2006 Share Posted August 2, 2006 Alright. Lemme start by posting the code that I've got thus far.[code]<?php $query = "SELECT Tech FROM `WOR` where work_order_num='$ordernum'"; $techname = mysql_query($query) or die(mysql_error()); ?><?php $techinfo = "SELECT * FROM `Techs` where Name='$techname'"; $tech2 = mysql_query($techinfo) or die(mysql_error()); while ($tech3 = mysql_Fetch_assoc($tech2)) { echo ''.$tech3['Name'].'<br> '.$tech3['Phone'].'<br> '.$tech3['Email'].''; }?>[/code]Basically, this is what I've got. I have two DB tables, one with the information about work orders (WOR), including a technician's name. I have a second table (Techs) that has the rest of their information. I have a form where you select a work order number, and from there it recalls all the information on that particular work order. I'm trying to assign the assigned tech to a variable ($techname), and then recall their information from the second table, and finally echo it onto the page.This is how I thought it would work, however nothing is showing up when I try to run the script, so any help would be much appreciated. Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 2, 2006 Share Posted August 2, 2006 againTable names and field names dont need single quotes (')Who ever first mentioned this needs a slapSome MySQL Versions make all field names, table names ect LowercaseSo try making Tech and WOR lower case (tech, wor)Same as TechsNamePhoneEmailalso add echo mysql_error();after a query, if there was an error, this will tell you Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted August 2, 2006 Share Posted August 2, 2006 You assign the result of the first query to $techname. Then you use that variable in your second query.After the first query $techname contains an MySql structure on which you have to perform a mysql_fetch(_assoc) in order to get the content of the Tech column.Ronald 8) Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted August 2, 2006 Share Posted August 2, 2006 [quote author=onlyican link=topic=102782.msg408463#msg408463 date=1154557452]againTable names and field names dont need single quotes (')Who ever first mentioned this needs a slapSome MySQL Versions make all field names, table names ect LowercaseSo try making Tech and WOR lower case (tech, wor)Same as TechsNamePhoneEmailalso add echo mysql_error();after a query, if there was an error, this will tell you[/quote]again, onlyican, those are not single quotes. they're backticks (`)... please read up on this before slapping people.Sephir, you can also try to join the two tables together[code]SELECT Techs.Name FROM Techs JOIN WOR ON Techs.Name=WOR.Tech WHERE WOR.work_order_num='$ordernum'[/code] Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 2, 2006 Share Posted August 2, 2006 whats the difference between ' and ' ???and sorry, I posted this before i read your other post Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted August 2, 2006 Share Posted August 2, 2006 the key on the left side of 1 and above Tab. it's a slightly tilted quote. Quote Link to comment Share on other sites More sharing options...
SephirGaine Posted August 3, 2006 Author Share Posted August 3, 2006 Well, I revised my code a bit, however I'm still having trouble. Hopefully the code it a bit more clear now.And [b]ryanlwh[/b] - unfortunately I've never attempted to combine tables before, so I'm not sure exactly what I'm looking at or what it really does. Not only that but I've no idea how to 'properly' apply that code, so I'd have to do some kind of research before trying it out. Thanks for the input, though, I'll definitely look into it.[code]<?php $query = "SELECT Tech FROM `WOR` where work_order_num=`$ordernum`"; $result = mysql_query($query) or die(mysql_error(1)); $techname = mysql_Fetch_assoc($result); ?><?php $techinfo = "SELECT * FROM `Techs` where Name=`$techname`"; $result2 = mysql_query($techinfo) or die(mysql_error(1)); $text = mysql_Fetch_assoc($result2); echo ''.$result.'<br> '.$text['Phone'].'<br> '.$text['Email'].''; ?>[/code] Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 3, 2006 Share Posted August 3, 2006 php is case sencativemysql_fetch_assocnotmysql_Fetch_assocAlthough that should not really mattertry echo $techinfo below the querythen copy that, and run the query in your query analyzer (standard is php myadmin) Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 3, 2006 Share Posted August 3, 2006 ok I see it now$techname = mysql_Fetch_assoc($result);should bewhile($row = mysql_fetch_assoc($result)){$techname = $row["fieldname"];}where fieldname is the name of the field from the database Quote Link to comment Share on other sites More sharing options...
SephirGaine Posted August 3, 2006 Author Share Posted August 3, 2006 Sorry, deleted my post from before because it was a stupid mistake on my part.. however I tried that last bit out and unfortunately still no beans.[code]<?php $query = "SELECT Tech FROM WOR where work_order_num='$ordernum'"; $result = mysql_query($query) or die(mysql_error(1)); while ($row = mysql_fetch_assoc($result)){ $techname = $row["Name"];} ?><?php $techinfo = "SELECT * FROM Techs where Name='$techname'"; $result2 = mysql_query($techinfo) or die(mysql_error(1)); while ($text = mysql_fetch_assoc('$result2')) { echo ''.$text['Name'].'<br> '.$text['Phone'].'<br> '.$text['Email'].''; }?>[/code]I'm just getting kind of disgruntled however, since I've been working on this single piece of code for the past 2 days to no avail. Really, it [b]should[/b] be possible to do, correct? Thanks a ton for the help thus far, onlyican, it's much appreciated. Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 3, 2006 Share Posted August 3, 2006 while ($text = mysql_fetch_assoc('$result2')) {Now, they are single quotes, not ticks yeawhile ($text = mysql_fetch_assoc($result2)) { Quote Link to comment Share on other sites More sharing options...
SephirGaine Posted August 3, 2006 Author Share Posted August 3, 2006 Aye, true, still didn't make a difference though. :'( Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 3, 2006 Share Posted August 3, 2006 Aint gone to sleep honestOne thing to note, dont make a difference thoecho ' ' .$textjust use echo $textTry thisunder $techinfo = "SELECT * FROM Techs...add this codeecho "The Query is ".$techinfo."<br />";This will show if all the variables are parsing ok, to find out if the first query is working proper Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted August 3, 2006 Share Posted August 3, 2006 yeah try to echo the queries to screen. you never know what you'd see :) Quote Link to comment Share on other sites More sharing options...
SephirGaine Posted August 4, 2006 Author Share Posted August 4, 2006 Hey.. back, and once again, thanks for the help you two. I tried to echo my very first query, and something's wrong up there.. and unfortunately I can't figure out what.[code]<?php $query = "SELECT Tech FROM `WOR` WHERE work_order_num='$ordernum'"; $result = mysql_query($query) or die(mysql_error(1)); while ($row = mysql_fetch_assoc("$result")); $techname = $row['Tech']; echo "The Query is ".$techname.""; ?>[/code]The echo simply says "The Query is " and that's it. I'm not sure if there's something wrong in the code or for some reason with accessing the database. However, I've got another piece of code on this same page that returns other sections of this same DB row without any problems. So.. I'm basically completely stumped. I've got the table entry's name correct, I see no glaring errors within my code.. it's just not cooperating it seems like. I've tried any given number of things, trying different variable names, changing the echo statement to some other variable ($row for example), and still nothing. ??? Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 4, 2006 Share Posted August 4, 2006 thats because the varible query is $query not $technameecho "The query is ".$query."<br />"; Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted August 4, 2006 Share Posted August 4, 2006 Also[code]while ($row = mysql_fetch_assoc("$result"));[/code]Don't EVER surround the result with quotes.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.