PHP - Display Mysql Query Results In Html Table
I have the following code that searches my database and displays results in a table:
$fields = array("field1", "field2", "field3") $cols = implode (', ', $fields); $result= mysql_query (" SELECT $cols FROM tablename WHERE ................... "); if (!$result) {die('Could not search database: ' . mysql_error());} if($result) { if(mysql_num_rows($result) == 0) { return "Sorry. No records found in the database"; } else { $table = "<table border='1' cellpadding='5' cellspacing='5'>"; while($arr = mysql_fetch_array($result, MYSQL_ASSOC)) { $table .= "\t\t<tr>\n"; foreach ($arr as $val_col) { $table .= "\t\t\t".'<td>'.$val_col.'</td>'."\n"; } $table .= "\t\t</tr>\n"; } $table .= "</table>"; echo $table; } mysql_free_result($result); } As you can see each of the MySQL table fields specified by $fields is displayed in a new column in the html table. I want to change this so that e.g. "field3" is displayed in a new row instead. So, instead of the html table looking like: | "field1-result1" | "field2-result1" | "field3-result1" | | "field1-result2" | "field2-result2" | "field3-result2" | | "field1-result3" | "field2-result3" | "field3-result3" | I want it to look like: | "field1-result1" | "field2-result1" | | "field3-result1" | | | "field1-result2" | "field2-result2" | | "field3-result2" | | | "field1-result3" | "field2-result3" | | "field3-result3" | | I guess this is quite straightforward, but I can't work it out! Pls help! Thanks. Similar TutorialsHello, I know this should be pretty simple to figure out, but everything I try is giving me absolutely no results. I have a mysql query selecting columns from my database and returning results. I have the results printing out right now, so I can see that this part is working. All I want to do is take the results and put them into a table to display on my page. Basically, take what's in the database table and copy it to a table I can put on the web. FYI I am using sourcerer so the "connect" code is taken care of for me in the "JFactory" bit of code. Here is the first part of my code, selecting the information from the database. {source} <?php $db = JFactory::getDbo(); $query = $db -> getQuery(true); $query -> SELECT($db -> quoteName(array('first_dept_name', 'last_name', 'dept', 'position', 'phone_num'))); $query -> FROM ($db -> quoteName('#__custom_contacts')); $query -> ORDER ('first_dept_name DESC'); $query -> WHERE ($db -> quoteName('contact_category')."=".$db -> quote('YTown Employees')); $db -> setQuery($query); $results = $db -> loadObjectList(); print_r($results); Here is where I am trying to print the results into a table. I got this code directly from a PHP book, but I am getting nothing at all returned back to me. I get table headers, but no data. <?php echo "<table><tr><th>Name</th><th>Department</th></tr>"; while ($row = mysqli_fetch_array ($result)){ echo "<tr>"; echo "<td>".$row['last_name']."</td>"; echo "<td>".$row['dept']."</td>"; echo "</tr>"; } echo "</table>"; ?> {/source} Say a user puts in a support request, and for every request it generates a unqiue string, and enters it into the database. Ok, now say there is a text field, when the user enters their unique string and it finds a match, it displays the data along with it. How can I accomplish this? Im kind of new to mysql, but I know basic SQL. Would be great if somebody could point me in the right direction! Thanks First off, let me say that this will not be a public use site. We want to create a site that allows us to run queries in our database; this way we don't need to log into the MySQL server when ever we want to run a query. Basically, I am trying to create something as simple as a form with a text-input and a submit button. In this text-input, we will write a query (such as SELECT * FROM xxxx). When we hit submit, we would like to have the MySQL table printed out in a large textbox below. Our database has multiple tables, so something that works across the entire database seamlessly is key. Has anyone ever made anything like this? Is there another way to go about this? We really just want an easy way to run queries on the go. Thanks in advance to anyone who replies! Hey Everyone, I'm creating a site that will show images uploaded for certain days working on a job site. Kind of a day-to-day photo journal for the customer. On the site, the user gets here, sees 3 large images, and a series of thumbnails if more than 3 images exist for that day (works fine). However, underneath that I want to display a 3-4 column setup of "Archived Dates" that provide a link to the images of the other dates. I have this working correctly, but the results are displayed as follows: Date 1: Date 2: Date 3: etc.... I want them to display like this; Day 1 Day 4 Day 2 Day 5 Day 3 Day 6 and so on..... in a 3 column format. Here is the code I have right now just looping through to display these link results, not the rest of the page. I am trying to do it tableless right now, but if that isn't the right way to go, please let me know. Thanks to anyone in advance, Nick $SQLRowe = "SELECT DISTINCT RoweImgDate from tblRowe WHERE RoweImgDate !='" . $_GET['date'] . "' Order by RoweImgDate DESC Limit 0, 30"; //echo $SQLRowe; $rsSQLRowe = mysql_query($SQLRowe); <span class="rowe">Archived Photos:</span><br/> <div id="archive"> <?php while($row = mysql_fetch_array($rsSQLRowe)){ //echo "<a href='index.php?id="' . $row[RoweImgID] . '"' class='link'>$row[RoweImgDate]</a></br>"; echo "<div id='archivedates'>"; echo "<a href='index.php?date=" . $row[RoweImgDate] . "' class='link'>$row[RoweImgDate]</a>"; echo "</div>"; //echo "<img src='images/$row[RoweImage]'/><br/>"; //echo "<span class='FeatDesc'><p>$row[RoweImgDesc]</p></span><br/>"; } ?> </div> I was wondering how does one go about showing results from SELECT query in columns in a html table. I have a list of products in a table, and would like to show them on the page in 4 columns. I have done many searches on google to try and find the sulution, but the majority of what im finding instead is about displaying a table from phpmyadmin as a table in html. If its a large operation to do this, I would be very happy if someone could poiint me in the direction of a tutorial maybe. Here is the code I have so far to display the products, but for some reason, it only show 1 row instead of all the rows from my table. Code: [Select] <?php $dbhost = "localhost"; $dbuser = "user"; $dbpass = "pass"; $dbname = "dbname"; mysql_connect ($dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $result = mysql_query("SELECT * FROM mcproducts"); while($row = mysql_fetch_array($result)) { $products_local_id = $row['products_local_id']; $productname = $row['product_name']; $thumburl = $row['image_from_url']; $productlink = $row['product_local_url']; $thumbnail = $row['product_image_small']; $currencysymbol = $row['product_currency']; $price = $row['product_price']; $flagicon = $row['product_country_from']; } ?> <html> <head> <link href="style/stylesheet.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="displaybox"> <div class="productimage"> <a href="<?php echo $productlink; ?><?php echo $products_local_id; ?>"><img src="<?php echo $thumburl; ?><?php echo $thumbnail ?>" width="150" height="150"></a> </div> <div class="productdescription"> <div class="pro_name"> <a href="<?php echo $productlink ?><?php echo $products_local_id; ?>"><?php echo $productname; ?></a> </div> <div class="pro_description"> </div> <?php if ($flagicon=="Ireland") { $flagicon = "<img src=\"flags/ireland.jpg\">"; } elseif ($flagicon=="UK") { $flagicon = "<img src=\"flags/uk.jpg\">"; } else echo ""; ?> <div class="pro_description"><?php echo $flagicon; ?><?php echo $currencysymbol ?> <?php echo $price ?></div> </div> </div> </body> </html> Many thanks, DB Hello all, I have made the multi level marketing downline tree, but the problem with it now, it gives only the downline of one result, as the query gives 2 results what I want now is to make it give the downline of both results not just one, and it's always 2 results, not more here is my code Code: [Select] <?php $id = $_GET['id']; $result = mysql_query("SELECT id FROM users WHERE id = '".$id."' ORDER BY id"); $row = mysql_fetch_assoc($result); if ($row['id'] == 0) { echo" <table> <div id=\".piccenter\""; echo "<tr>"; echo "<img src=\"icon.gif\" border=0 align=\"center\">"; echo ""; } else { echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$row['id']."'"; echo ""; echo "</div>"; } } $result2 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$row['id']."'"); $rows2 = mysql_fetch_assoc($result2); foreach ($rows2 as $row2) { if ($row2['id'] == 0) { echo" <div id=\".picleft\"> <img src=\"icon.gif\" border=0 align=\"center\">"; } else { echo "<img src=\"images.png\" border=0 >"; echo "<br />"; echo "'".$row2['id']."'"; echo "</div>"; echo " <td>"; echo "</td> "; } } $result3 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$rows2['id']."'"); $row3 = mysql_fetch_assoc($result3); if ($row3['id'] == 0) { echo"<div id=\".picright\"> <img src=\"icon.gif\" border=0 align=\"center\">"; } else { echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$row3['id']."'"; echo ""; echo " <tr> <td>"; echo "</td> </tr> "; } $result4 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$row3['id']."'"); $rows4 = mysql_fetch_assoc($result4); if ($rows4['id'] == 0) { echo"<img src=\"icon.gif\" border=0 align=\"center\">"; } else { echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$rows4['id']."'"; echo ""; echo " <tr> <td>"; echo "</td> </tr> "; } $result5 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$rows4['id']."'"); $rows5 = mysql_fetch_assoc($result5); if ($rows5['id'] == 0) { echo"<img src=\"icon.gif\" border=0 align=\"center\">"; } else { echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$rows5['id']."'"; echo ""; echo " <tr> <td>"; echo "</td> </tr> "; } $result6 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$rows5['id']."'"); $rows6 = mysql_fetch_assoc($result6); if ($rows6['id'] == 0) { echo"<img src=\"icon.gif\" border=0 align=\"center\">"; } else { echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$rows6['id']."'"; echo ""; echo " <tr> <td>"; echo "</td> </tr> "; } $result7 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$rows6['id']."'"); $rows7 = mysql_fetch_assoc($result7); if ($rows7['id'] == 0) { echo"<img src=\"icon.gif\" border=0 align=\"center\">"; } else { echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$rows7['id']."'"; echo ""; echo " <tr> <td>"; echo "</td> </tr> "; } $result8 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$rows7['id']."'"); $rows8 = mysql_fetch_assoc($result8); if ($rows8['id'] == 0) { echo"<img src=\"icon.gif\" border=0 align=\"center\">"; } else { echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$rows8['id']."'"; echo ""; echo " <tr> <td>"; echo "</td> </tr> "; } $result9 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$rows8['id']."'"); $rows9 = mysql_fetch_assoc($result9); if ($rows9['id'] == 0) { echo"<img src=\"icon.gif\" border=0 align=\"center\">"; } else { echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$rows9['id']."'"; echo ""; echo " <tr> <td>"; echo "</td> </tr> </tbody> </table> "; } ?> Hey all. I have a query that selects data from a datbase based on a criteria. Easy enough. But now I am growing and the amount displaying is too much. How can you, via php, have a queries result be displayed only so many at a time and auto create links that show the rest? Like if query returns 82 results, I want it to display 25 immediately and create 3 links at the bottom. The next link would show 26-50. The next 51-75. And the final 76-82. etc Example: Code: [Select] $result = mysql_query("SELECT * FROM pay"); $num_rows = mysql_num_rows($result); while($row = mysql_fetch_array($result)) { echo $row['first_name']; echo $row['last_name']; echo $row['item_name']; echo $row['option_selection1']; echo $row['payment_date']; echo $row['stat']; } This is simple. But what happens when the results are 125? I want to limit it to displaying 25 at a time. Is the only way to manually create seperate pages and have each one show 1-25, then 26-50, etc? Or is there a way to have the script do it, itself? Any tutorials out there on this specifically? Hopefully I am making sense. Thanks! Hello all. I'm using this code to go through the database and output certain user-defined numbers Code: [Select] <?php mysql_connect ("pdb1.awardspace.com", "anastasov_db","moscow1945") or die (mysql_error()); mysql_select_db ("anastasov_db"); $term = $_POST['term']; $sql = mysql_query("select * FROM countries WHERE cocode = '$term'"); while ($row = mysql_fetch_array($sql)){ echo '<br/> Code: '.$row['cocode']; echo '<br/> Country: '.$row['coname']; echo '<br/><br/>'; } ?> Now how would I go about making a page that appears if the script can't find any results in the database? Thank you in advance I have no clue about to go abt this one: I have form which has some: Code: [Select] <table> <tr> <td> <form> Title display info </form> </td> </tr> </table> I need to add an additional link next to title such that when someone clicks on the link the table expands and displays rsult of a query. Code: [Select] <table> <tr> <td> <form> Title LINK if( link is clicked ) { $query=select display query results } else { dont display query results display info } </form> </td> </tr> </table> In an .html, before : <!-- BEGIN myquery --> I need to stop output and check the content of "myquery" Is there a command for that ? Thank You. Hello, This is query in MySQL Quote mysql> LOAD DATA LOCAL INFILE '/var/www/html/numbers.csv' INTO TABLE details FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (number); Query OK, 0 rows affected (0.00 sec) Records: 2200 Deleted: 0 Skipped: 1200 Warnings: 0 Now, I am trying to run the same query in PHP and display the same results.... (i.e. Records, Deleted, Skipped) Quote <?php $db=mysql_connect("localhost", "user", "1234") or die(mysql_error()); $dname="database"; mysql_select_db($dname)or die(mysql_error()); $sqlstatement="LOAD DATA LOCAL INFILE '/var/www/html/numbers.csv' INTO TABLE details FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (number)" ; mysql_query($sqlstatement) or die(mysql_error());; echo "it is done!"; ?> Tried mysql_fetch_array, row but could not get it to work... please help guys Hi All, Below is my code to add the two different query results into one. This is working fine when both the queries have same no.of rows. eg: row1 = 1 2 3 (Query1) row2 = 3 5 5 (Query2) o/p: 4 7 8 Let's say, I have few rows which are not exactly matched with first query. eg: row1 = 1 2 3 2 (Query1) row2 = 3 empty empty 5 (Query2) o/p : 4 2 3 7 (I want the o/p to be like this) empty means there is no data from the second query. In my while, && working fine when the 2 queries have same no.of rows. while (($row1 = mysql_fetch_assoc($rs1)) && ($row2 = mysql_fetch_assoc($rs2))) { $strHtml .= "<tr>"; $strHtml .= "<td align=center colspan=3>".($row1['Calls']+$row2['Calls'])."</td>"; $strHtml .= "<td align=center colspan=3>".($row1['actual_duration(min)A']+$row2['actual_duration(min)A'])."</td>"; $strHtml .= "<td align=center colspan=3>".($row1['call_usage']+$row2['call_usage'])."</td>"; $strHtml .= "<td align=center colspan=3>".($row1['disconnection_charge']+$row2['disconnection_charge'])."</td>"; $strHtml .= "<td align=center colspan=3>".($row1['total_revenue']+$row2['total_revenue'])."</td>"; $strHtml .= "</tr>"; } Is the while loop i am using correct or there is any other better solution for this? please help me, Thanks in advance. I'm having a weird issue in which i'm trying to pull rows from a table based on the contents of specific fields. My query strings a $ms = ("SELECT * FROM games WHERE game = 'test' AND playername = '$test' OR opponentname = '$test' ORDER BY playdate DESC LIMIT 25") or die ('Error: '.mysql_error ()); Which works fine until later I try to use: $ms2 = ("SELECT * FROM games WHERE game = 'test2' AND playername = '$test' OR opponentname = '$test' ORDER BY playdate DESC LIMIT 25") or die ('Error: '.mysql_error ()); What is weird is on $ms2 I found if I change it to: $ms2 = ("SELECT * FROM games WHERE playername = '$test' OR opponentname = '$test' AND game = 'test2' ORDER BY playdate DESC LIMIT 25") or die ('Error: '.mysql_error ()); It works... on one page, on the rest neither line works it just pulls every row in the table that fit one of the two name fields. Has anyone experienced anything like this or know why or a fix for this? Thanks! Hi guys, i'm trying to search from a form and use php to display the results of the FullText Search from a MySQL database, but I don't get any results from the query. This is the query: $query="SELECT * FROM tutorials WHERE MATCH(title, tags) AGAINST ('$searchform')"; I think the query is right but it doesn't give me any results.... Does anyone know what could be wrong? I think it might be something wrong with my table (database). my table should have 5 columns: id, title, category, content, tags The form should search throught the title and tags columns to see if it finds anything matching the $searchform , but I don't think it is doing it. Can anyone help please? Hello - I am connecting to MySql and running a query. If I use a foreach loop, I can iterate over the results and have them print to screen. However, when I try the below everything is null!
How can I add the results of my MySql query to a php array?
<?php $con=mysqli_connect("site", "user", "psasswr=ord", "db"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="SELECT * FROM test LIMIT 10"; $result = mysqli_query($con,$sql); echo json_encode($result); mysqli_free_result($result); mysqli_close($con); ?>
but what this prints is: {"current_field":null,"field_count":null,"lengths":null,"num_rows":null,"type":null} I am trying to display certain MySQL data based off of what link is clicked. For example.. I want to display all the entries from 2009 when a link for 2009 is clicked; maybe like.. <a href="http://website.com/page?yr=09">2009</a> But I am having trouble doing so.. any help would be great! P.S. The years are in my database with only the last two numbers.. 10, 09, 08, etc. $result = mysql_query("select setlist_id, month, day, year, name, venue, location, label1, set1, set2, set3, encore, notes, photos, recording, poster from $database_table order by setlist_id DESC, year, month, day",$db) or die_now("Could not select setlists"); while($row = mysql_fetch_array($result)) { $the_id = $row["setlist_id"]; $the_month = $row["month"]; $the_day = $row["day"]; $the_year = $row["year"]; $the_name = $row["name"]; $the_venue = $row["venue"]; $the_location = $row["location"]; $the_label1 = $row["label1"]; $the_set1 = $row["set1"]; $the_set2 = $row["set2"]; $the_set3 = $row["set3"]; $the_encore = $row["encore"]; $the_notes = $row["notes"]; $the_photos = $row["photos"]; $the_recording = $row["recording"]; $the_poster = $row["poster"]; echo("<div class='date' id='date' tabindex='0'>" . "$the_month" . "." . "$the_day" . "." . "$the_year" . " - "); echo ($the_name != '') ? "" . "$the_name" . " - " : ''; echo("" . "$the_venue" . " - " . "$the_location" . "</div>"); echo("<div class='set'>" . "$the_label1" . ":<br /></div><div class='list'>" . "$the_set1" . "<br /></div>"); echo ($the_set2 != '') ? "<div class='set'>Set Two:<br /></div><div class='list'>" . "$the_set2" . "<br /></div>" : ''; echo ($the_set3 != '') ? "<div class='set'>Set Three:<br /></div><div class='list'>" . "$the_set3" . "<br /></div>" : ''; echo ($the_encore != '') ? "<div class='set'>Enco <br /></div><div class='list'>" . "$the_encore" . "<br /></sdiv>" : ''; echo("<div class='line'></div>"); echo nl2br("<div class='notes'>" . "$the_notes" . "</div>"); } When I replace the $result line with... $result = mysql_query("SELECT * FROM `$database_table` WHERE `year` = '09' order by setlist_id DESC, year, month, day",$db) or die_now("Could not select shows");... I get all the results from just 2009, which is what I want, but I want the results to depend on what link has been clicked. I hope I am making sense. Hi I have the following code: Code: [Select] $result = mysql_query("SELECT * FROM xbox_games order by gameid"); $row = mysql_fetch_assoc($result); $id = $row["gameid"]; $title = $row["gametitle"]; $cover = $row["cover"]; <?php echo $title;?> Which displays only the first result from my database. How can i change this to display all the results either as a list, or in a table? Thanks Hi, I have a regular MySQL query that displays it's results to the screen in a browser as an HTML table, all nice and fruity. The managers who use this function like to send out the results to staff, currently they simply take a screen shot and paste it into an email to send out to everyone - quite an overhead on the email system, company network, not to mention the time taken to do the screen shot and paste it into an email in the first place. It would be good if I could include a standard HTML form button (preferably) or link on the results page to shove the displayed results to Outlook as an email, that contains the table all ready for the manager to add in what ever they want to the email and then send (usually to 'all@mysite.com' but it would be useful if they could change or add to this as they see fit). This is kind of what happens with a normal mailto HTML tag, except I want it to contain the MySQL query result too. This is the existing table output routine (something I inherited): Code: [Select] /* Output data into a HTMl table */ echo "<p>"; echo "<table align=center width=800 border=\"1\">"; echo "<tr>"; echo "<td BGCOLOR=\"#ffcc00\"><strong>Agent name</strong></td> <td BGCOLOR=\"#ffcc00\"><strong>Number of calls made / handled</strong></td> <td BGCOLOR=\"#ffcc00\"><strong>Average call minutes</strong></td> <td BGCOLOR=\"#ffcc00\"><strong>Total mins (inc hours + secs rounded)</strong></td> </tr>"; while($row = mysql_fetch_row($numresults)) { echo "<tr>"; for($i=0; $i < mysql_num_fields($numresults); $i++) { echo "<td align=center width=443>$row[$i]</td>"; } echo "</tr>\n"; } echo "</table></p>"; Hey all, first post to this site. I'm somewhat new to PHP, so bear with me - this might be an easy question, it might not be. Just looking for a little help. Basically, I have a query which takes commands from a form through AJAX (day, time, time1). The query executes a wildcard on a table named sip_data, searches for linked $id (so if $id=3, for example in multiple tables, it spits out the $name, $zip in a div). Here's the code: Code: [Select] <?php $dbhost = "localhost"; $dbuser = ""; $dbpass = ""; $dbname = ""; //Connect to MySQL Server $link = mysql_connect($dbhost, $dbuser, $dbpass); //Select Database mysql_select_db($dbname) or die(mysql_error()); // Retrieve data from Query String $id = $_GET['id']; $name = $_GET['name']; $zip = $_GET['zip']; $server_url = $_GET['server_url']; $day = $_GET['day']; $time = $_GET['time']; $time1 = $_GET['time1']; // Escape User Input to help prevent SQL Injection $id = mysql_real_escape_string($id); $name = mysql_real_escape_string($name); $zip = mysql_real_escape_string($zip); $server_url = mysql_real_escape_string($server_url); $day = mysql_real_escape_string($day); $time = mysql_real_escape_string($time); $time1 = mysql_real_escape_string($time1); //build query $query = "SELECT * FROM $day,sip_data WHERE $day.id=sip_data.id AND $day$time<=>$day$time1 ORDER BY zip ASC"; //Execute query $qry_result = mysql_query($query) or die(('No Results')); //Build Result String while($row = mysql_fetch_array($qry_result)) { echo "<table id=query_result align=left>"; echo "<tr>"; if($zip = $row[zip]); echo "<th><b>$row[zip]</b></th>"; echo "</tr>"; echo "<tr>"; echo "<td><a href=$row[server_url] rel=ajaxDiv>$row[name]</a></td>"; echo "</tr>"; echo "</table>"; } echo $display_string; ?> Basically, my issue with this is that some of the results within the sip_data DB will have zip codes that repeat. The current code prints out each results with the zip code and name - here's an image of a sample result: What I would like to do is avoid repeating the zip code and just group the results under each zip code, kinda like this: 55408 55412 55423 --------- ------------ ---------- example example example example example example Any help would be greatly appreciated. I feel like I'm so close to the answer, but just need a little guidance. Who knows, I might be way off. Thanks in advance! Hi I am sure this is very simple but it's got me beat! I have a page that sends emails to people with their account details. I can get it to work fine with straight plain text but would like it in HTML and I can't get the username and password details into the body of the email. I'm sure it's just a formatting issue but I've tried many things and it fails!! Any suggestions very welcome. The code is below. Many thanks in advance. <?php // MAIL TO AP require_once '../phpmailer/class.phpmailer.php'; $mail = new PHPMailer(); if(isset($_GET['idcode'])){ $idcodepassed = $_GET['idcode']; }else{ $idcodepassed = 111111; // set this to your default value if no URL value is present } mysql_select_db($database_process, $process); $result = mysql_query("SELECT applicantid, idcode, type, company, email, CONCAT('pdf_document_',idcode) AS linkname, length, username, password, DATE_FORMAT(applicationdate,'%D %M %Y') AS formattedDate, parties FROM applicant WHERE idcode = '$idcodepassed' LIMIT 1 "); while($row = mysql_fetch_array($result)) { $appid = $row['applicantid']; $idcode = $row['idcode']; $type = $row['type']; $company = $row['company']; $email = $row['email']; $term = $row['length']; $username = $row['username']; $password = $row['password']; $appdate = $row['formattedDate']; $parties = $row['parties']; } // $body = file_get_contents('EmailTextAP.php'); // $body = eregi_replace("[\]",'',$body); $body = '<html><p>This email TO AP is confirmation of your appointment of Clear Appointments as your agent for service of process under the agreement between $parties. Our appointment starts on $appdate and you have appointed us for $term years from this date. We have attached our letter of confirmation to this email for your records.</p> <p>You can log into your account on our website (<a href=\"http://www.clearappointments.co.uk\">www.clearappointments.co.uk</a>) at any time to review your documents and change your contact details. Your user name is:??? and your password is ???.</p> <p>We appreciate your custom and hope that you will use us again.</p> <p>Kind regards</p> <p>Clear Appointments Team<br /> '; $mail->SetFrom('confirmation@clearappointments.co.uk', 'Clear Appointments'); $mail->AddReplyTo('confirmation@clearappointments.co.uk', 'Clear Appointments'); // set the subject of the email $mail->Subject = "Process Agent Letter of Confirmation Attached"; @MYSQL_CONNECT("localhost","lawwork1_graham","733576"); @mysql_select_db("lawwork1_process"); $query = "SELECT company, email FROM applicant WHERE idcode='$idcodepassed'"; $result = @MYSQL_QUERY($query); // sets name and location of attachment $directory = '../docs/'; $docname = 'Confirmation_Letter_'. $idcodepassed . '.pdf'; $invname = 'Invoice_' . $idcodepassed . '.pdf'; $send=$directory.$docname; $sendinvoice=$directory.$invname; while ($row = mysql_fetch_array ($result)) { $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->MsgHTML($body); $mail->AddAddress($row["email"]); // $mail->AddAddress($row["instemail"]); // attachment // $mail->AddAttachment($send); // $mail->AddAttachment($sendinvoice); $mail->AddAttachment($send); // attachment // $mail->AddAttachment($sendinvoice); // attachment if(!$mail->Send()) { echo "Mailer Error (" . str_replace("@", "@", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>'; } else { echo ""; // echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "@", $row["email"]) . ')<br>'; } // Clear all addresses and attachments for next loop $mail->ClearAddresses(); $mail->ClearAttachments(); } ?> |