First things first ive tried to fix this myself for hours and spent a good time trying to find an answer too but to no avail.. anyways any help wud be greatly appreciated, its for college! :)
i have a session variable of "custID" stored when someone enters their id on a login page. in my mysql database the customer table has the rows "custID" and "clientID". what i want to do is use the client id linked to that customer id to display the details of that client in a table (clientCompany is another table with "clientID" in it. all primary keys/foreign keys are working fine). the $refclient seems to be working. i echoed the result and it gave me "2001" which is what i wanted.
$refclient = mysql_query("SELECT clientID FROM Customer WHERE custID='$_SESSION[custID]'");
echo mysql_result($refclient, 0); // outputs "2001" which is the client ID. this works
however i now want that number to be used in my $client statement in the where clause.
$client = mysql_query("SELECT * FROM clientCompany WHERE clientID = '$refclient'");
this isnt working tho.. i understand that the $refclient gives "resource id #" but how do i convert that into a number so the where clause effectively says " WHERE clientID = 2001 " ? i dont know how to use join statements (im a noob!) i did a quick count function which shows thats its not gettng the data from the table (it's connected to the server ok)
$count2=mysql_num_rows($client);
if($count2==1)
{
echo "working"; // 1 row is all that it should create
}
else
{
echo "not working"; //this is what always shows
}
i have some table headers here which i left out to shorten my question. all if statements, tables work fine, all brackets closed, stuff like that :)
here is what should be outputted:
while($row = mysql_fetch_array($client))
{
echo "<tr>";
echo "<td>" .$row['clientID']. "</td>";
echo "<td>" .$row['compName']. "</td>";
echo "<td>" .$row['compAddress']. "</td>";
echo "<td>" .$row['contactPersonForCompany']. "</td>";
echo "<td>" .$row['compEmail']. "</td>";
echo "<td>" .$row['compPhoneNum']. "</td>";
echo "</tr>";
}
basically what should i use instead of '$refclient' in my "$client" select statement? when i type '2001' instead of '$refclient' it works perfectly but obviously i need to have it linked to the custID typed in so cant do that. also the customer cant know the clientID so i cant get them to input it/store is in a session variable..
$client = mysql_query("SELECT * FROM clientCompany WHERE clientID = '$refclient'");
PS sorry bout the essay of a question that is! just wanted to give as much detail as i could =) thanks in advance!