Jump to content

Recommended Posts

Can anyone give me a hand turning this into a join statement?

$query1 = sprintf("SELECT * FROM companies WHERE status = 1");
$result1 = mysql_query($query1);
while ($row1 = mysql_fetch_assoc($result1)) {
	$C1=$row1["companyName"];
	$C3=$row1["id"];
	$C4=$row1["businessType"];
		
$query="SELECT * FROM companyAdmins WHERE companyID = '$C3'";
$result=mysql_query($query);
$num=mysql_numrows($result);
$email=mysql_result($result,0,"email");

echo '<p>' . $C1 . ' @ ' . $email . '</p>';
 
}

Im trying to select companyName,id, and business type from the companies table where the status is one

and I'm also trying to select the email from the companyAdmins table where the companyID is equal to the id from the companies table.

 

I want to basically get

 

companyName.companies, id.companies, businessType.companies, and email.companyAdmins

 

I have this file written and now I'm trying to go back and refactor the code and make everything cleaner.

Link to comment
https://forums.phpfreaks.com/topic/280071-mysql-join/
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.