PHP - Sum Columns From 2 Mysql Tables
I have looked all over the net on how to fix this... I am creating a baseball statistical website and I have 2 tables with identical columns (2012hitting and 2013hitting). I am trying to create a page where I can 1) group each year's statistics (which I have been able to do) and 2) have a row named "Career Totals". Each table has about 15 columns, various stats. How can I add the data from my 2012hitting table to my 2013hitting table into a Career Totals row for each player?
This is what I'm trying now: Code: [Select] /* CONNECTION VARIABLES */ $id = $_GET['id']; // get var from URL /* Get data. */ $sql = "SELECT * (sum(2012hitting.hr) +sum(2013hitting.hr)) as totalhr FROM 2012hitting, 2013hitting WHERE id='$id'"; $result = mysql_query($sql); ?> <?php $alternate = "2"; while ($row = mysql_fetch_array($result)) { $field1 = $row["season"]; $field2 = $row["team"]; $field3 = $row["games"]; $field4 = $row["ave"]; $field5 = $row["slg"]; $field6 = $row["r"]; $field7 = $row["h"]; $field8 = $row["rbi"]; $field9 = $row["bb"]; $field10 = $row["k"]; $field11 = $row["hr"]; $field12 = $row["dbl"]; $field13 = $row["tpl"]; $field14 = $row["sb"]; $field15 = $row["obp"]; $field16 = $row["ops"]; if ($alternate == "1") { $color = "#ffffff"; $alternate = "2"; } else { $color = "#E4E4E4"; $alternate = "1"; } echo "<tr bgcolor=$color><td align='center'>$field1</td><td align='center'>$field2</td><td align='center'>$field3</td><td align='center'>$field4</td><td align='center'>$field5</td><td align='center'>$field6</td><td align='center'>$field7</td><td align='center'>$field8</td><td align='center'>$field9</td><td align='center'>$field10</td><td align='center'>$field11</td><td align='center'>$field12</td><td align='center'>$field13</td><td align='center'>$field14</td><td align='center'>$field15</td><td align='center'>$field16</td></tr>"; } echo "</table>"; ?> Thank you in advance! Similar TutorialsHi,
How can I select multiple columns from two tables and run a search through multiple fields?
My tables a
t_persons (holds information about persons)
t_incidents (holds foreign keys from other tables including t_persons table)
What I want is to pull some columns from the two tables above and run a search with a LIKE criteria, something like below. The code originally worked well with only one table, but for two tables it generate errors:
$query = "SELECT p.PersonID ,p.ImagePath ,p.FamilyName ,p.FirstName ,p.OtherNames ,p.Gender ,p.CountryID ,i.IncidentDate ,i.KeywordID ,i.IncidentCountryID ,i.StatusID FROM t_incidents AS i LEFT JOIN t_persons AS p ON i.PersonID = p.PersonID WHERE FamilyName LIKE '%" . $likes . "%' AND FirstName LIKE '%" . $likes . "%' AND OtherNames LIKE '%" . $likes . "%' AND Gender LIKE '%" . $likes . "%' AND IncidentDate LIKE '%" . $likes . "%' AND KeywordID LIKE '%" . $likes . "%' AND IncidentCountryID LIKE '%" . $likes . "%' AND StatusID LIKE '%" . $likes . "%' ORDER BY PersonID DESC $pages->limit";Errors a Column 'IncidentDate' in where clause is ambiguous Column 'KeywordID' in where clause is ambiguous Column 'IncidentCountryID' in where clause is ambiguous Column 'StatusID' in where clause is ambiguousThese columns are foreign keys on t_incidents table. I have also attached the table relationship diagram if it helps. I will appreciate any better way to do this. Thanx. Joseph Attached Files Model - 3.png 76.6KB 0 downloads This portion is kind of stumping me. Basically, I have a two tables in this DB: users and users_access_level (Separated for DB normalization) users: id / username / password / realname / access_level users_access_level: access_level / access_name What I'm trying to do, is echo the data onto an HTML table that displays users.username in one table data and then uses the users.access_level to find users_access_level.access_name and echo into the following table data, I would prefer not to use multiple queries if possible or nested queries. Example row for users: 1234 / tmac / password / tmac / 99 Example row for users_access_level: 99 / Admin Using the examples above, I would want the output to appear as such: Username: Access Name: Tmac Admin I am not 100% sure where to start with this, but I pick up quickly, I just need a nudge in the right direction. The code I attempted to create just shows my lack of knowledge of joining tables, but I'll post it if you want to see that I did at least make an effort to code this myself. Thanks for reading! Hi. Im trying to get my table so I can click on username and it will display ascending or click again and it descends. I want to be able to do this will all of them..Username Password IP Country Type Status E-mail Date start Date end .. If anyone can help me it would be great. I dont know PHP . I paid someone to make this for my and they binned it half way through the job taking my money... Thank you This is my code <?php if(session_is_registered('username')){ include("header.php"); ?> <div id="content_main" class="clearfix"> <div id="main_panel_container" class="left"> <div id="tabledata" class="section"> <h2 class="ico_mug">Users table</h2> <? if($_GET['type']=='delete'){ mysql_query("delete from users where id='".$_GET['id']."'"); ?><div id="success" class="info_div"><span class="ico_success">User deleted successful!</span></div><? } if($_GET['type']=='edit'){ if(isset($_POST['username'])){ mysql_query("UPDATE users SET username='".$_POST['username']."', password='".$_POST['password']."', ip='".$_POST['ip']."', country='".$_POST['country']."' WHERE id='".$_GET['id']."'"); } $row=mysql_fetch_array(mysql_query("SELECT * FROM users WHERE id='".$_GET['id']."'")); ?> <form action="" method="post" accept-charset="utf-8"> <fieldset> <label>Username:<input type="text" name="username" value="<?echo $row['username'];?>" size=60/></label> <label>Password:<input type="text" name="password" value="<?echo $row['password'];;?>" size=60/></label> <label>IP:<input type="text" name="ip" value="<?echo $row['ip'];;?>" size=60/></label> <label>Country:<input type="text" name="country" value="<?echo $row['country'];;?>" size=60/></label> <br /> <button>Submit</button> </fieldset> </form> <button onclick="location.href='index.php?action=users';">Back</button> <? } if($_GET['type']=='add'){ if(isset($_POST)){ $j=0; for($i=1; $i<=5; $i++){ if($_POST['username'.$i]!=''){ if(($_POST['username'.$i]!='') && ($_POST['password'.$i]!='') && ($_POST['ip'.$i]!='') && ($_POST['country'.$i]!='')) { if(($_POST['date_start'.$i]=='')||($_POST['date_end'.$i]=='')){ $date_start=0; $date_end=0; } else { $date_start=strtotime($_POST['date_start'.$i]); $date_end=strtotime($_POST['date_end'.$i]); } mysql_query("INSERT INTO users (username,password,ip,email,country,date_start,date_end) VALUES ('".$_POST['username'.$i]."','".$_POST['password'.$i]."','".$_POST['ip'.$i]."','".$_POST['email'.$i]."','".$_POST['country'.$i]."','".$date_start."','".$date_end."') "); $j++; } else { ?><div id="fail" class="info_div"><span class="ico_cancel">Fields on the same row can't be blank</span></div><? } } } if($j>0){ ?><div id="success" class="info_div"><span class="ico_success"><? echo $j;?> users have been added!</span></div><? } } ?> <fieldset> <i> Date format should be like 2000-05-25<br> Type: B for instant buy; S for subscription<br> Status: Y for active; N for inactive </i> </fieldset> <form action="" method="post" accept-charset="utf-8"> <table id="table"> <thead> <tr> <th>Username</th> <th>Password</th> <th>IP</th> <th>Email</th> <th>Country</th> <th>Type</th> <th>Status</th> <th>Date start</th> <th>Date end</th> </tr> </thead> <tbody> <? for ($i=1; $i<=5; $i++) { ?> <tr> <td> <input type="text" name="username<?echo $i;?>" size="10"> </td> <td> <input type="text" name="password<?echo $i;?>" size="10"> </td> <td> <input type="text" name="ip<?echo $i;?>" size="10"> </td> <td> <input type="text" name="email<?echo $i;?>" size="10"> </td> <td> <select name="country<?echo $i;?>"> <option value="UK">UK</option> <option value="US">US</option> </select> </td> <td> <select name="type<?echo $i;?>"> <option value="B" selected>B</option> <option value="S">S</option> </select> </td> <td> <select name="status<?echo $i;?>"> <option value="Y" selected>Y</option> <option value="N">N</option> </select> </td> <td> <input type="text" name="date_start<?echo $i;?>" size="10"> </td> <td> <input type="text" name="date_end<?echo $i;?>" size="10"> </td> </tr> <? } ?> <tr> <td><button>Submit</button> </td> </tr> </tbody> </table> </form> <br> <? } ?> <?php if($_GET['type']=='import') { if($_POST['import'] && $_FILES['flimport']['name']!='') { //print_r($_FILES); $fieldseparator = ","; $lineseparator = "\n"; $csvfile=$_FILES['flimport']['tmp_name']; $size = $_FILES['flimport']['size']; if(!$size) { exit; } $file = fopen($csvfile,"r"); $csvcontent = fread($file,$size); fclose($file); ////////////////////////////////////////////////////////////// $lines = 0; $queries = 0; $linearray = array(); foreach(split($lineseparator,$csvcontent) as $line) { $lines++; $line = trim($line," \t"); $line = str_replace("\r","",$line); $line = str_replace("'","\'",$line); $linearray = explode($fieldseparator,$line); $linemysql = implode("','",$linearray); $exist=0; if(is_numeric($linearray[0])) { $exist=mysql_num_rows(mysql_query("select id from users where username='".$linearray[2]."' or email='".$linearray[1]."'")); $query = "insert into users values('$linemysql');"; } else { $exist=mysql_num_rows(mysql_query("select id from users where username='".$linearray[1]."' or email='".$linearray[0]."'")); $query = "insert into users values('','$linemysql');"; } //echo $query."<br />"; if($exist==0) { @mysql_query($query); if(mysql_insert_id()) $queries++; } } echo '<div id="success" class="info_div"><span class="ico_success">'.$queries.' users added successfully</span></div>'; } ?> <form name="frmImport" action="" method="post" enctype="multipart/form-data"> <input type="hidden" value="1" name="import" /> <table id="table"> <tbody> <tr> <td><span style="font-size:10px; color:#333">Note: Please entry ms excel <strong>.CSV (Comma delimited)</strong> file only</span></td> </tr> <tr> <td><input type="file" accept="application/msexcel" name="flimport" /> </td> </tr> <tr> <td><button>Import Now</button></td> </tr> </tbody> </table> </form> <br /> <?php } ?> <button onclick="location.href='index.php?action=users&type=add';">Add users</button> <button onclick="location.href='index.php?action=users&type=import';" name="btnimport">Import users</button> <button onclick="location.href='export.php?datafrom=users';" name="btnexport">Export users</button> <table id="table"> <thead> <tr> <th>Actions</th> <th>Username</th> <th>Password</th> <th>IP</th> <th>Country</th> <th>Type</th> <th>Status</th> <th>E-mail</th> <th>Date start</th> <th>Date end</th> </tr> </thead> <tbody> <? if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; } $start_from = ($page-1) * 20; $query=mysql_query("SELECT * FROM users WHERE 1 LIMIT $start_from, 20"); while($row=mysql_fetch_array($query)){ ?> <tr> <td><a href="index.php?action=users&type=delete&id=<?echo $row['id'];?>"><img src="img/cancel.jpg" alt="cancel"/></a><a href="index.php?action=users&type=edit&id=<?echo $row['id'];?>"><img src="img/edit.jpg" alt="edit"/></a></td> <td><?echo $row['username'];?></td> <td><?echo $row['password'];?></td> <td><?echo $row['ip'];?></td> <td><?echo $row['country'];?></td> <td><?echo $row['type'];?></td> <td><?echo $row['status'];?></td> <td><?echo $row['email'];?></td> <td class="table_date"><?echo date("Y-m-d",$row['date_start']);?></td> <td class="table_date"><?echo date("Y-m-d",$row['date_end']);?></td> </tr> <? } ?> </tbody> </table> <? $rs_result = mysql_query("SELECT COUNT(id) FROM users"); $row = mysql_fetch_row($rs_result); $total_records = $row[0]; $total_pages = ceil($total_records / 20); ?> <div class="pagination"> <span class="pages">Page 1 of <?echo $total_pages;?></span> <?php for ($i=1; $i<=$total_pages; $i++) { if($page==$i){ ?><span class="current"><b><?echo $page;?></span></b><? } else { echo "<a href='index.php?action=users&type=view&page=".$i."'>".$i."</a> "; } } if($total_pages>1){ $next=$page+1; ?> <a href="index.php?action=users&type=view&page=<? echo $next;?>" >»</a> <? } ?> </div> </div> <!-- end #tabledata --> <? include("shortcuts.php"); ?> </div> <? ?> </div><!-- end #content_main --> </div><!-- end #content --> <? include("footer.php"); ?> <? } else { header( "Location: index.php?action=login" ); } ?> Hey guys seem to have tricky question here, I am just wondering how I could do the following:
I have an SQL table that contains these columns:
As you can see there is a 'Make' column and a 'Model' column and each row displays what make it is.
I now want to associate the 'Makes' with the 'Models' in another table just like this example:
BMW AUDI VOLVO FORD TOYOTA
X5 All Road XC90 Focus Supra
3 Series A1 C30 Mustang Yaris
5 Series Galaxy
So for example if the first table has a row that contains the make 'AUDI' within the 'Make' column I then want it to take the value of the 'Model' and list it into my other table under the 'AUDI' column, any ideas how I can do this with PHP?
Thanks!
I have a table called "friends" and 4 columns called: id......friend_1......friend_2.......date I want to retrieve all of the friends of the user that is logged in, so if the table looks like: friend_1.........friend_2 3.........................6 6.........................8 12.......................3 the result if the users id is 3 would be: 6 12 and if the users id was 6 it would be: 3 8 the query I have right now partially works, just note sure how to modify it to get the full result I want. Code: [Select] $get_friends = mysql_query("SELECT * FROM friends WHERE (friend_1='".$session."' OR friend_2='".$session."')"); while($friends = mysql_fetch_array($get_friends)) { print $friends['friend_1']; }with the code above if you use the table I showed above and assumed that $session = 3, the result is: 3 12 but should be: 6 12 hopefully that's pretty straight forward, thanks in advanced. This: Code: [Select] echo "<pre>"; print_r($torrent->content()); echo "</pre>"; Returns: Code: [Select] Array ( [Eureka.S05E01.HDTV.XviD-ASAP\Eureka.S05E01.HDTV.XviD-ASAP.avi] => 367011826 [Eureka.S05E01.HDTV.XviD-ASAP\eureka.s05e01.hdtv.xvid-asap.nfo] => 4798 [Eureka.S05E01.HDTV.XviD-ASAP\Sample\eureka.s05e01.hdtv.xvid-asap.sample.avi] => 7883092 ) Needs to be inserted to MySQL like: In other words, the array $torrent->content() needs to be inserted to MySQL as new lines at columns "filename" and "size". Please help me..
So I have a database that is structured like this: https://imgur.com/a/DdyTqiE
I would like to loop through this table, and get a count of how many were 'is_no_show' and 'is_cancelled' per (unique) category with respect to 'scheduled_student_services.' How would I approach this? I know I probably need to do two loops but I'm not sure the PHP syntax for this. Any suggestions or tips would be helpful. Thank you for your time! I am loading notifications from a database table called "notifications" and I am having a little trouble getting them to order in the correct way. my query I'm using right now: Code: [Select] $query = mysql_query("SELECT B.* FROM (SELECT A.* FROM notifications A WHERE A.user_id='$session' AND A.from_id!='$session' ORDER BY A.id ASC ) AS B ORDER BY B.state ASC LIMIT 7"); this works well as far as showing the unread notifications on top, then the read notifications below, however it's not ordering the two sets by ID (which the id auto increments so the higher id number is the newest) from newest on top to the oldest on bottom, still keeping them separated by the unread on top, read on bottom (column name is state for showing whether they're read or not). The order the notifications are displaying by their ID is: 3 5 2 4 1 when it should be: 5 3 2 4 1 I have a search set up to search a table for the text entered in a textbox, I have two columns in the table, one with the first name of people, and the second with their last names, I am wondering how I can search both, so for instance: I type in the search field: Roger Smith in the database it would look like: First_name-----|-----Last_name -------------------|------------------- Roger------------|-------Smith my current query is: Code: [Select] $query = mysql_query("SELECT * FROM users WHERE fname LIKE '%$find%' OR lname LIKE '%$find%'"); But if I type both parts of the name it doesn't return anything. works fine if I just search for "Roger" OR "Smith". Hello, I have a script that processes data from a form, and then outputs data from a MySQL table based on which selections are made on the form. What I'm trying to do is create columns showing data for each month depending on which months the user selects, and then a "Total" column at the end of that. The output first determines the "family" the results are in, then the ID the product is for the parent family, and then it outputs the data based on what ID is listed. Unfortunately, I have no idea how to do this without nesting while loops inside other while loops which I know is bad for server performance - and yes this does take a long time to complete. Here is some of my code for this to show what I'm doing wrong: Code: [Select] $searchdatabase5 = "SELECT field3 FROM slssum2 WHERE company = '$companyname' AND CONCAT(year,month) BETWEEN '$startyear$startmonth' AND '$endyear$endmonth' AND field3 != 0 AND field4 != '995' GROUP BY field3"; $run5 = mysql_query($searchdatabase5) or die(mysql_error()); while($row5 = mysql_fetch_assoc($run5)) { $field5_3 = $row5['field3']; echo '<tr><td colspan="0"><hr style="width: 100%; height: 1px; color: #a0a0a0;"></td></tr><tr><td colspan="0" bgcolor="#ccffcc"><strong>FAMILY '. $field5_3 .'</strong><br /></td></tr>'; $searchdatabase12 = "SELECT field4 FROM slssum2 WHERE company = '$companyname' AND CONCAT(year,month) BETWEEN '$startyear$startmonth' AND '$endyear$endmonth' AND field3 = '$field5_3' AND field4 != 0 GROUP BY field4"; $run12 = mysql_query($searchdatabase12) or die(mysql_error()); while($row12 = mysql_fetch_assoc($run12)) { $field12_4 = $row12['field4']; $searchdatabase6 = "SELECT field3,field4,field5,field6 FROM slssum2 WHERE company = '$companyname' AND CONCAT(year,month) BETWEEN '$startyear$startmonth' AND '$endyear$endmonth' AND field4 = '$field12_4' GROUP BY field3,field4,field5"; $run6 = mysql_query($searchdatabase6) or die(mysql_error()); while($row6 = mysql_fetch_assoc($run6)) { $field6_3 = $row6['field3']; $field6_4 = $row6['field4']; $field6_5 = $row6['field5']; $field6_6 = $row6['field6']; echo '<tr><td colspan="0">'. $field6_5 .' - '. $field6_6 .'</td></tr><tr><td valign="middle" align="left" bgcolor="#ccc" width="183px">Units</td>'; $searchdatabase7 = "SELECT * FROM slssum2 WHERE company = '$companyname' AND CONCAT(year,month) BETWEEN '$startyear$startmonth' AND '$endyear$endmonth' AND field5 = '$field6_5' ORDER BY year,month ASC"; $run7 = mysql_query($searchdatabase7) or die(mysql_error()); while($row7 = mysql_fetch_assoc($run7)) { $field7_3 = $row7['field3']; $field7_4 = $row7['field4']; $field7_5 = $row7['field5']; $field7_9 = $row7['field9']; $field7_10 = $row7['field10']; $field7_month = $row7['month']; $field7_year = $row7['year']; $startmonth2 = ltrim($startmonth, '0'); echo '<td bgcolor="#e6e6e6" width="95px" nowrap="nowrap" align="right">'; echo $field7_10; echo '</td>'; } Here is the output: I know the code is very bad, but what would be the best way to recreate what I have in the image? Thank you. I create a post just now but cannot seem to find it to add to it. Anyhow, I have 2 tables, I need to multiply qty from the one table to the mass from the other to get a total, which I have achieved with this code: $sql_total_mass = " SELECT jobs_assembly.assemble_qty, jobs.mass, (jobs_assembly.assemble_qty * jobs.mass) AS 'sum' FROM jobs_assembly LEFT JOIN jobs on jobs_assembly.jobs_id = jobs.id LEFT JOIN job_names ON jobs.job_names_id = job_names.job_id WHERE jobs_assembly.assemble_date = '$link_date' ORDER BY job_names.job_name, jobs.assembly "; $result_total_mass = mysqli_query($conn, $sql_total_mass); if (mysqli_num_rows($result_total_mass) > 0) { while($row_total_mass = mysqli_fetch_assoc($result_total_mass)) { echo $row_total_mass['sum'].'<br />'; } //while } //if Now I need to take all these totals and make a grand total. So basically add all the results from $row_total_mass[‘sum’] together and show it.
Hi, This has been baffling me for a couple hours now and i cant seem to figure it out. I have some code which creates an array and gets info from a mysql database and then displays in a list. This works great but after adding more and more rows to my database the list is now becoming quite large and doesnt look great on my site. Is it possible to split the list into multiple columns of about 25 and if possible once 3 or 4 columns have been created start another column underneath. To help explain i would be looking at a layout as follows: Code: [Select] line 1 line 1 line 1 line 2 line 2 line 2 ... ... ... line 25 line 25 line 25 line 1 line 1 line 1 line 2 line 2 line 2 ... ... ... line 25 line 25 line 25Im guessing there should be some sort of if statement to check how many items are being displayed and to create a new column if necessary. Is this correct? Thanks, Alex I made a small editing system for my news page, and I need to update three columns within my table "announcements" in the database. I tried a method of updating all of them with one MySQL query instead of using three as it just isn't neat. I've searched several methods via google and I've tried all of them, but just can't seem to get it to work. Is this MySQL query correct? mysql_query("UPDATE announcements SET title = {$title} WHERE id = '$id', content = {$content} WHERE id = '$id', lastmodified = ". date('M-d-Y') ." WHERE id = '$id'"); This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=313325.0 I created a simple search box which will query my table and match the input value to one of my columns. two of these columns store comma separated values. if i query a column other than a column which stores my csv i can see my search results. if i query a column which stores my csv i will not see results unless the search value matches the first value within the column. how would i be able to get say the second or third or forth value. here is the code i am using to query the table any help would be appreciated thanks. Code: [Select] $q = $this->db->query("SELECT * FROM table WHERE col1 LIKE 'searchvalue'". " OR col2 LIKE 'searchvalue'". " OR col3 LIKE 'searchvalue'". " OR col4 LIKE 'searchvalue'". " OR FIND_IN_SET('searchvalue', col5) > 0 ". " OR FIND_IN_SET('searchvalue', col6) > 0"); just trying to see if i have this right in my head here.. if i have a page that has a topic on it and many replies, the tables would look like this.. would this be the right code to pull out the topic AND all responses for say. www.mysite.com/view?id=1 $topic = 'SELECT * from topics where id = $id' $replies = 'SELECT * from replies where replies.topic_id = $id' I'm creating a staff directory that I'd like to use alternating background colors (odd/even) to make it easier to read. All of the information is stored in sql, which I can pull to the page with a repeat function, but I'm not sure how to get the zebra effect to alternate with the output. Is there any easy way to do this? I'm using CSS to change the background of the table itself. Code: [Select] <table width="100%" border="0" cellpadding="1" cellspacing="0" class="staff_b"> <tr> <td width="35%"><div class="staff_h">Name</div></td> <td width="35%"><div class="staff_h">Department</div></td> <td width="30%"><div class="staff_h">Extension</div></td> </tr> <tr class="staff_e"> <td>1</td> <td>2</td> <td>3</td> </tr> <tr class="staff_o"> <td>4</td> <td>5</td> <td>6</td> </tr> </table> Heyyzarrh, iv been having troubles trying to make it so my PHP script will echo out the username by corresponding the posters ID with the ID in the members table. Heres what iv got so far: Code: [Select] <?php if ($urlid == "") { } $sql = mysql_query("SELECT members.username, posts.mem_id, posts.post_date, posts.post FROM members JOIN posts ON members.id = posts.mem_id WHERE posts.mem_id='$urlid' ORDER BY post_date DESC LIMIT 20"); while ($row = mysql_fetch_array($sql)){ echo '<b>' .$row['$username']. ':</b> '.$row['post'].'<br />At: '.$row['post_date'].'<br /><br />'; } ?> Please help!! :S so far only the actual posts data comes out not the username from the table "members"... I need some help on how to search in two different mysql tables, and then show the results sorted/ordered by the tables. Quote RESULTS: Tabel 1 # ... # ... Tabel 2 # ... # ... Thanks in advance! $sql = "SELECT * FROM leads WHERE accesstoken = '".$_POST["userAc"]."'"; $result = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); if(mysql_num_rows($result)>0) { while($row = mysql_fetch_array($result)) { $id= $row['id']; $fullname= $row['fullname']; $email= $row['email']; $to = $email; $message .= $_POST["userMessage"]; $subject = $_POST["userSubject"]; $headers = "From: " . $_POST["userEmail"] . "\r\n"; $headers .= "Reply-To: ". $_POST["userEmail"] . "\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; if (mail($to, $subject, $message, $headers)) { $output = json_encode(array('type'=>'error', 'text' => '<p>Your Message was sent successfully!</p>')); die($output); } else { $output = json_encode(array('type'=>'error', 'text' => '<p>Your Message was not sent!</p>')); die($output); } } }I have another table called accounts that I want to join with this one, I need to select from ref to get the email from account table also! be something like this $sql = "SELECT * FROM accounts WHERE ref = '".$_POST["userAc"]."'"; $result = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); |