All,
I have a web form that's using php to self submit. I want to use sql statements to pull in data from three different tables to create something that I call a "profile" to be entered into a fourth table called "profile".
I am able to use three tables successfully but when I would try to incorporate the fourth table (contacts) its throwing me for a loop. No pun intended. Well maybe.
I will briefly describe my tables:
table 1: profile <- all data will be submitted here
table 2: company - used for majority of insert information, this table has fields for reps (repIDs) but not contacts
table 3: reps - only used for information for one input field
table 4: contacts - only used for information for one input field
Here is my code.
I have a web form that's using php to self submit. I want to use sql statements to pull in data from three different tables to create something that I call a "profile" to be entered into a fourth table called "profile".
I am able to use three tables successfully but when I would try to incorporate the fourth table (contacts) its throwing me for a loop. No pun intended. Well maybe.
I will briefly describe my tables:
table 1: profile <- all data will be submitted here
table 2: company - used for majority of insert information, this table has fields for reps (repIDs) but not contacts
table 3: reps - only used for information for one input field
table 4: contacts - only used for information for one input field
Here is my code.
Code:
<?php
$q=$_GET["q"];
include("includes/connection.php");
$company_query = "SELECT * FROM `company` WHERE id = '".$q."' ";
$contact_query = "SELECT contact.id FROM `contact` LEFT JOIN `company` on '".$q."' = contact.companyid WHERE company.id = '".$q."' ";
if(!$company_query){ exit('<p>Error in Sql statement!<br />'. 'Error: ' .mysql_error() . '</p>');}
if(!$contact_query){ exit('<p>Error in Sql statement!<br /> Error: .mysql_error()</p>'); }
$rs = mysql_query($company_query);
$rs2 = mysql_query($contact_query);
while($row = mysql_fetch_array($rs)) {
// added this section from id to createdBy for the purpose of separating names for ns reps and contact names
$id = $row['id'];
$company = htmlspecialchars($row['company_companyName']);
$city = htmlspecialchars($row['company_city']);
$state = htmlspecialchars($row['company_state']);
$nsRepid = htmlspecialchars($row['nsRepid']);
$nsReps = explode(", ",$nsRepid);
$nsReplist = "";
foreach($nsReps as $nsRep){
$sql2 = "SELECT * FROM nsreps WHERE id = $nsRep";
$results = @mysql_query($sql2);
($nr = mysql_fetch_array($results));
$nsReplist .=$nr['nsreps_firstName'] . " ";
$nsReplist .=$nr['nsreps_lastName'] . ", ";
}
$nsReplist = substr($nsReplist,0,strlen($nsReplist)-2);
[COLOR=red][b]while($row2 = mysql_fetch_array($rs2)) {
$contacts = $row2["id"];
/* //an attempt to load contact first and last names based on contact id in contact table
$contactIDs = implode(", ",$sql3); // put companyid field data here
$contacts = explode(", ",$contactIDs);
$contactlist = "";
foreach($contacts as $contact){
$sql4 = "SELECT id, contact_firstName, contact_lastName FROM contact WHERE id = $contact";
$resultsCT = @mysql_query($sql4);
($ct = mysql_fetch_array($resultsCT));
$contactlist .=$ct['contact_firstName'] . " ";
$contactlist .=$ct['contact_lastName'] . ", ";
}
$contactlist = substr($contactlist,0,strlen($contactlist)-2);
*/
}
// seek back to record #1 for the next loop
mysql_data_seek($rs2, 0);
$row2 = "";[/b][/color]
$overview = htmlspecialchars($row['company_overview']);
echo "<div class='row'>
<label>Company Information:</label>
<span><input class='disabled w200' type='text' name='company' id='company' value='$company' /><label>Company Name</label></span>
<span><input class='disabled w180' type='text' disabled='disabled' name='city' id='city' value='$city' /><label>City</label></span>
<span><input class='disabled w100' type='text' disabled='disabled' name='state' id='state' value='$state' /><label>State</label></span>
</div>";
echo "<div class='row'>
<label>NS Rep(s):</label>
<span><input class='disabled text' type='text' name='nsreps' id='nsreps' value='$nsReplist' /><label>NS Reps</label></span>
</div>";
echo "<div class='row'>
<label>Customer Contact(s):</label>
<span><input class='disabled text' type='text' name='contacts' id='contacts' value='$contacts' /><label>Customer Contacts</label></span>
</div>";
echo "<div class='row'>
<label>Overview:</label>
<textarea class='disabled textarea' type='text' disabled='disabled' name='overview' id='overview'>$overview</textarea>
</div>";
}
mysql_close($dbcnx);
?>