Jump to content


Photo

One more time..


  • Please log in to reply
16 replies to this topic

#1 SephirGaine

SephirGaine
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 02 August 2006 - 09:53 PM

Alright. Lemme start by posting the code that I've got thus far.

<?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'].'';
  }
?>

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.

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 02 August 2006 - 10:24 PM

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
Tell me the problem, I will try tell you the solution

#3 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 02 August 2006 - 10:33 PM

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)
RTFM is an almost extinct art form, it should be subsidized.

#4 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 02 August 2006 - 10:38 PM

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

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
SELECT Techs.Name FROM Techs JOIN WOR ON Techs.Name=WOR.Tech WHERE WOR.work_order_num='$ordernum'

Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#5 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 02 August 2006 - 10:41 PM

whats the difference between ' and ' ???
and sorry, I posted this before i read your other post

Tell me the problem, I will try tell you the solution

#6 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 02 August 2006 - 10:59 PM

the key on the left side of 1 and above Tab. it's a slightly tilted quote.
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#7 SephirGaine

SephirGaine
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 03 August 2006 - 12:16 AM

Well, I revised my code a bit, however I'm still having trouble. Hopefully the code it a bit more clear now.

And ryanlwh - 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.

<?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'].'';
		
?>


#8 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 03 August 2006 - 12:21 AM

php is case sencative
mysql_fetch_assoc
not
mysql_Fetch_assoc
Although that should not really matter
try
echo $techinfo below the query
then copy that, and run the query in your query analyzer (standard is php myadmin)
Tell me the problem, I will try tell you the solution

#9 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 03 August 2006 - 12:42 AM

ok I see it now

$techname = mysql_Fetch_assoc($result);
should be

while($row = mysql_fetch_assoc($result)){
$techname = $row["fieldname"];
}

where fieldname is the name of the field from the database


Tell me the problem, I will try tell you the solution

#10 SephirGaine

SephirGaine
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 03 August 2006 - 12:55 AM

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.

<?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'].'';		
		}
?>

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 should be possible to do, correct? Thanks a ton for the help thus far, onlyican, it's much appreciated.

#11 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 03 August 2006 - 12:57 AM

while ($text = mysql_fetch_assoc('$result2')) {
Now, they are single quotes, not ticks yea
while ($text = mysql_fetch_assoc($result2)) {
Tell me the problem, I will try tell you the solution

#12 SephirGaine

SephirGaine
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 03 August 2006 - 01:00 AM

Aye, true, still didn't make a difference though.  :'(

#13 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 03 August 2006 - 01:22 AM

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
Tell me the problem, I will try tell you the solution

#14 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 03 August 2006 - 02:59 AM

yeah try to echo the queries to screen. you never know what you'd see :)
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#15 SephirGaine

SephirGaine
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 04 August 2006 - 07:01 PM

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.

<?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."";
		?>

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.  ???

#16 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 04 August 2006 - 08:20 PM

thats because the varible query is $query not $techname

echo "The query is ".$query."<br />";
Tell me the problem, I will try tell you the solution

#17 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 04 August 2006 - 08:27 PM

Also
while ($row = mysql_fetch_assoc("$result"));
Don't EVER surround the result with quotes....
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users