Jump to content

One more time..


SephirGaine

Recommended Posts

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.
Link to comment
Share on other sites

again
Table names and field names dont need single quotes (')
Who ever first mentioned this needs a slap

Some MySQL Versions make all field names, table names ect Lowercase

So try making Tech and WOR lower case (tech, wor)
Same as Techs
Name
Phone
Email

also add
echo mysql_error();
after a query, if there was an error, this will tell you
Link to comment
Share on other sites

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)
Link to comment
Share on other sites

[quote author=onlyican link=topic=102782.msg408463#msg408463 date=1154557452]
again
Table names and field names dont need single quotes (')
Who ever first mentioned this needs a slap

Some MySQL Versions make all field names, table names ect Lowercase

So try making Tech and WOR lower case (tech, wor)
Same as Techs
Name
Phone
Email

also 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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

Aint gone to sleep honest
One thing to note, dont make a difference tho
echo ' ' .$text
just use
echo $text

Try this
under
$techinfo = "SELECT * FROM Techs...
add this code

echo "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
Link to comment
Share on other sites

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.  ???
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.