Jump to content

richardw

Members
  • Posts

    120
  • Joined

  • Last visited

Everything posted by richardw

  1. Hello, Make sure your table has a timestamp, and then sort on the date, most recent first fot the last 20 mysql_query("SELECT * FROM SOMEWHERE ORDER BY yourtime_stamp DESC LIMIT 0,20"); I hope this helps Richard
  2. You will need a third party mudule. Pear is on most installs, so first you will have to track down ot's location. Specifically the "Speadsheet/Excel/Writer.php" script. That foundation will enable you to create an Excel file, complete with formatting and headers here is my example for a mailing list download: <?php // Include PEAR::Spreadsheet_Excel_Writer set_include_path('../PEAR/'); require_once("Spreadsheet/Excel/Writer.php"); // Create an instance $xls =& new Spreadsheet_Excel_Writer(); $today = date("Ymd"); // Send HTTP headers to tell the browser what's coming $xls->send("filename_here".$today.".xls"); // Add a worksheet to the file, returning an object to add data to $sheet =& $xls->addWorksheet('Mailing List Download'); $titleText = ' Mailing List generated: ' . date('dS M Y'); // Create a format object $titleFormat =& $xls->addFormat(); // Set the font family - Helvetica works for OpenOffice calc too... $titleFormat->setFontFamily('Helvetica'); // Set the text to bold $titleFormat->setBold(); // Set the text size $titleFormat->setSize('15'); // Set the text color $titleFormat->setColor('navy'); // Set the bottom border width to "thick" $titleFormat->setBottom(2); // Set the color of the bottom border $titleFormat->setBottomColor('navy'); // Set the alignment to the special merge value $titleFormat->setAlign('left'); // Add the title to the top left cell of the worksheet, // passing it the title string and the format object $sheet->write(0,0,$titleText,$titleFormat); // Some text to use as a title for the worksheet // $titleText = 'List Created:' . date('dS M Y'); // $sheet->write(0,1,$titleText); // Set up some formatting $colHeadingFormat =& $xls->addFormat(); $colHeadingFormat->setBold(); $colHeadingFormat->setFontFamily('Helvetica'); $colHeadingFormat->setBold(); $colHeadingFormat->setSize('10'); $colHeadingFormat->setAlign('center'); // An array with the data for the column headings // **************** ******************************* // $colNames = array('Item','Price($)','Quantity','Total'); // $sheet->writeRow(2,0,$colNames,$colHeadingFormat); // **************** ******************************* $str = "HEADING HERE"; //"$row["fname"]; $arr = explode (",", $str); $colNames = array('ID','Salutation','First Name','Middle Name','Last Name','last_index','first_index', 'Address','Address2','City','Organization','Oranization Type','role','Department','E-Mail','email_id','Phone','Title','State ID','Zip','Referral Source ID','Reffered By','OtherSource','created', 'modified', 'mail_type', 'sent_on'); $sheet->writeRow(2,0,$arr,$colHeadingFormat); $sheet->writeRow(5,0,$colNames,$colHeadingFormat); // Get data records from table. // leaving a blank row to look nicer // The row height // The cell group to freeze // 1st Argument - vertical split position // 2st Argument - horizontal split position (0 = no horizontal split) // 3st Argument - topmost visible row below the vertical split // 4th Argument - leftmost visible column after the horizontal split $freeze = array(6,0,7,0); // Freeze those cells! $sheet->freezePanes($freeze); // Use this to keep track of the current row number $currentRow = 8; // $sheet->setRow(0,30); // Set the column width for the first 4 columns $sheet->setColumn(0,3,15); // Write some numbers /* for ( $i=0;$i<11;$i++ ) { // Use PHP's decbin() function to convert integer to binary $sheet->write($i,0,decbin($i)); } */ // Connect database. // mysql_connect(""); // mysql_select_db(""); $host="localhost"; // Host name $username_s =""; // Mysql username $password_s =""; // Mysql password $db_name=""; mysql_connect("$host", "$username_s", "$password_s")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get data records from table. $sql = "SELECT * FROM contacts"; $result =mysql_query($sql); // Create an array of arrays out of the recordset. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $sheet->writeRow($currentRow,0,$row); $currentRow++; } // Finish the spreadsheet, dumping it to the browser $xls->close(); ?> For more detail google this module /* * Module written/ported by Xavier Noguer <xnoguer@rezebra.com> * * PERL Spreadsheet::WriteExcel module. * require_once 'PEAR.php'; require_once 'Spreadsheet/Excel/Writer/Workbook.php'; /** * Class for writing Excel Spreadsheets. This class should change COMPLETELY. * * @author Xavier Noguer <xnoguer@rezebra.com> * @category FileFormats * @package Spreadsheet_Excel_Writer */
  3. First is a suggestionto change your query updates into a switch staement to make it easier to track bracket sets which is the cause of the missing bracket, hence the unexpexted end. Second is more out of curiosity since I don't know your table strucutre, why are you updating the same field within the database with different value types: "forum_name" i.e. place, age, tel? if(isset($_POST['placech'])) { $forum = $_POST['place']; $query = "UPDATE users SET forum_name = '$place' WHERE user_id = '$user_id'"; $result = mysql_query($query); } if(isset($_POST['agech'])) { $forum = $_POST['age']; $query = "UPDATE users SET forum_name = '$age' WHERE user_id = '$user_id'"; $result = mysql_query($query);
  4. Try this: $arraynum = sizeof($uploaded); //how many entities the array contains //then use for each to loop through the insert statement up for x number of files uploaded insert into gallery (Title, Cat, Photographer, Makeup, Hair, Wardrobe, uploaded, destination) values('$Title'[$i],'$Cat[$i]','$Photographer'[$i],'$Makeup'[$i],'$Hair'[$i],'$Wardrobe'[$i],'$uploaded'[$i],'$destination[$i]')";
  5. can you post some code? why can't you join the tables and edit the respective data? Also, look at using replacements for the php tags such as: <?php or ?> php = "Hypertext Preprocessor" and the PHP scripts will be compiled at runtime by the PHP engine
  6. hi, check out this program which was posted about two years ago. it will create a basic foundation for you, then you will have to modify The php My SQL To fit your needs. IT will allow you to display and edit right away. i have not tested or used it since then, but i remember it as being very functional. you will still have to design your sql tables to meet your needs. http://iobe.net/proj/index.php?pg=install i hope this works for you
  7. try this, it is somewhat of a guess,but intval may helpinthe sorting SELECT t.team_id, t.level, t.name, t.initials, t.owner, l.user_id, SUM(l.2playerpts) AS 2playerpts, SUM(l.4playerpts) AS 4playerpts,SUM(l.6playerpts) AS 6playerpts, SUM(l.8playerpts) AS 8playerpts, l.wins, l.losses, u.user_id, u.team_id FROM teams t INNER JOIN users u ON u.team_id = t.team_id INNER JOIN leaderboard l ON l.user_id = u.user_id GROUP BY t.team_id $sum_on_this = intval((2playerpts + 4playerpts + 6playerpts + 8playerpts)); ORDER BY $sum_on_this DESC
  8. % is a wildcardas it "Matches any number of characters, even zero characters"
  9. there is also a good solution posted a day or two ago http://www.phpfreaks.com/forums/index.php/topic,214197.0.html
  10. hi, try using [MAX(date) as last_record however, you indicated date of entry, and also reffered to last modification. if that is the case, make sure to build in a routine To upate your date field on record modification. Keep in mind, if it is date of entry and it you have an autoincrement Id field you can probably select on The last id. best
  11. check out this solution by Barand: http://www.php-editors.com/forums/php-programming-help/2389-need-help-sorting-directory-files.html
  12. <?php $text = "Lanacane Anti-Chafing Gel, relieves and prevents soreness from rubbing skin and skin on clothing.<br />\r\nUnique barrier against friction.<br />\r\nSilky finish - dries on contact.<br />\r\nNon-greasy, non-staining and fragrance free.<br />\r\nLanacane Anti-chafing Gel forms a breathable barrier on your skin, to prevent and aid healing of chafing caused by repeated rubbing of skin on skin or clothing. <br />\r\n<br />\r\nUnique anti-friction formula dries on contact, clear, non-greasy, providing your skin with long lasting relief. <br />\r\n<br />\r\nGentle enough to use anywhere, everyday. <br />\r\n<br />\r\nDirections: A small amount of Lanacane Anti-Chafing Gel goes a long way.<br />\r\nSmooth a small dab on irritated area.<br />\r\nRe-apply if needed.<br />\r\nTo avoid future chafing, apply prior to activity.<br />\r\nIf pain from soreness and rubbing extends 7 days, consult doctor. For external use only. <br />\r\n<br />\r\nIngredients: <br />\r\nCyclopentasiloxane • Dimethicone Crosspolymer • Vinyl Dimethicone Crosspolymer • Zea Mays (Corn starch)."; echo $text ; seems to work. is there any other code used in the output routine? echo "<br><br>" ; echo nl2br($text) ; // provides extra space ?> myouput for the above is respectively: Lanacane Anti-Chafing Gel, relieves and prevents soreness from rubbing skin and skin on clothing. Unique barrier against friction. Silky finish - dries on contact. Non-greasy, non-staining and fragrance free. Lanacane Anti-chafing Gel forms a breathable barrier on your skin, to prevent and aid healing of chafing caused by repeated rubbing of skin on skin or clothing. Unique anti-friction formula dries on contact, clear, non-greasy, providing your skin with long lasting relief. Gentle enough to use anywhere, everyday. Directions: A small amount of Lanacane Anti-Chafing Gel goes a long way. Smooth a small dab on irritated area. Re-apply if needed. To avoid future chafing, apply prior to activity. If pain from soreness and rubbing extends 7 days, consult doctor. For external use only. Ingredients: Cyclopentasiloxane • Dimethicone Crosspolymer • Vinyl Dimethicone Crosspolymer • Zea Mays (Corn starch). --------> with nl2br Lanacane Anti-Chafing Gel, relieves and prevents soreness from rubbing skin and skin on clothing. Unique barrier against friction. Silky finish - dries on contact. Non-greasy, non-staining and fragrance free. Lanacane Anti-chafing Gel forms a breathable barrier on your skin, to prevent and aid healing of chafing caused by repeated rubbing of skin on skin or clothing. Unique anti-friction formula dries on contact, clear, non-greasy, providing your skin with long lasting relief. Gentle enough to use anywhere, everyday. Directions: A small amount of Lanacane Anti-Chafing Gel goes a long way. Smooth a small dab on irritated area. Re-apply if needed. To avoid future chafing, apply prior to activity. If pain from soreness and rubbing extends 7 days, consult doctor. For external use only. Ingredients: Cyclopentasiloxane • Dimethicone Crosspolymer • Vinyl Dimethicone Crosspolymer • Zea Mays (Corn starch).
  13. Here is an ftp solution, useful if you want ownership to show instead of "nobody". This example will post your uploaded file into a database for later use. <?php if(isset($_POST['start_upload']) && $_FILES['txt_file']['name'] != ""){ $local_file = $_FILES['txt_file']['tmp_name']; // Defines Name of Local File to be Uploaded $destination_file = "/public_html/YourDomain/docs/".($_FILES['txt_file']['name']); // $destination_file = "/recreation/images/".basename($_FILES['txt_file']['name']); // Path for File Upload (relative to your login dir) // Global Connection Settings $ftp_server = "address_see_note_at right"; // FTP Server Address (exlucde ftp://) $ftp_user_name = "user_here"; // FTP Server Username $ftp_user_pass = "pass_here"; // Password // Connect to FTP Server $conn_id = ftp_connect($ftp_server); // Login to FTP Server $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); // Verify Log In Status if ((!$conn_id) || (!$login_result)) { // echo "FTP connection has failed! <br />"; // echo "Attempted to connect to $ftp_server for user $ftp_user_name"; // exit; } else { // echo "Connected to $ftp_server, for user $ftp_user_name <br />"; } $upload = ftp_put($conn_id, $destination_file, $local_file, FTP_BINARY); // Upload the File // Verify Upload Status ?> <?php if (!$upload) { $message = "<h2>FTP upload of ".$_FILES['txt_file']['name']." has failed!</h2><br /><br />"; } else { $link = "http://www.domainname_here.com/docs/".$_FILES['txt_file']['name']; $file_name = $_FILES['txt_file']['name']; // </font><br /><br /><br /><br />"; $message = "Success!<br /><br />" . $_FILES['txt_file']['name'] . " has been uploaded to " . $ftp_server . $destination_file . "!<br /><br />"; $title = $_POST["title"]; $description = $_POST["description"]; $category = $_POST["category"]; // Connect to Database include "db_conn.php"; $sql = "INSERT INTO docs ( title,link,filename,description,category) VALUES ('$title','$link','$file_name','$description','$category')"; $result = mysql_query($sql); } ftp_close($conn_id); // Close the FTP Connection } ?> and my form is: <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" enctype="multipart/form-data"> Please choose a file: <input name="txt_file" type="file" size="35" /><br /> <br /> File Title: <input name="title" type="Text" size="62"> <br /> <br /> Description: <input name="description" type="Text" size="62"><br> <br> Category: <select name="category"> <option value=""> - Select - </option> <?php include "db_conn.php"; $sql2 = "SELECT * FROM cat ORDER BY category ASC"; $result2 = mysql_query($sql2); while ( $row2 = mysql_fetch_assoc( $result2)) { echo "<option value=\"".$row2["cat_id"]."\">".$row2["category"]. "</option>\n"; } mysql_free_result($result2); ?> One important item that I forgot to mention: The PHP code for the ftp upload must appear at the top of the page before the 'DOCTYPE' line. best
  14. I just wanted to know if your making headway. If not, I will give it a try in the am. I have already recreated your table structures, but I won't be able to test my query till the am.
  15. Hi, YOu are missing a ' before the 5 in your enum field CREATE TABLE users ( id int(11) NOT NULL auto_increment, username varchar(22) NOT NULL, password varchar(32) NOT NULL, email_address varchar(155) NOT NULL, nickname varchar(255) NOT NULL, user_level enum('0','1','2','3','4','5') default '0' NOT NULL, forum_posts int(11) default '0' NOT NULL, profile text NOT NULL, siggy varchar(255) NOT NULL, last_post varchar(155) NOT NULL, last_login varchar(12) NOT NULL, style varchar(55) NOT NULL, PRIMARY KEY (id) ) TYPE=MyISAM try this
  16. Try the join with a WHERE clause for status and also keep the 1 in '' as mentioned earlier $sql = "SELECT m.id, m.label, m.link_url, m.parent_id, m.topmenu, m.leftmenu FROM cmsmenu m LEFT JOIN cmspages p ON p.menu_ID = m.id WHERE p.statusID = '1' ORDER BY m.parent_id, m.orderid ASC";
  17. here is one more solution, its an old one of mine and code heavy but it gives flexibility to trim where you want and set a trimming spread before the break <?php $posttext = "Soon you will know just how easy it is to build unncessaarily long routines. Take a look at counting words and seperating at a space or a period. This routine works well based on the trimto length"; $str_len = strlen($posttext); if ($str_len >= 75) { $str_len = trim(strlen($posttext)); $trimto = 65; $select = 8; // eight characters either way to a break $i = 0; for ($i = 0; $i < $trimto+$select; $i++) { $current_char = substr($posttext,$i,1); if ($current_char == " " ) { $cutlength = $i; } } $textout = (substr($posttext, $str_len= 0, $cutlength)); } echo $textout; ?>
  18. This may be a little more than you want, but try substituting the MySQL call with your form data. Youu can always send your form data to the database and use php for the RSS feed. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>RSS Feed Code Display</title> <?php // Insert here the the title of your feed $rss_title= "PHP RSS feed"; // Insert your site, in the format site.com $rss_site= "www.YourSite.com" ; // Insert the description of your website $rss_description= "Helpful RSS Tips"; // Applicable language of the feed. For spanish, change to "es" $rss_language="en"; // Address of the logo file. It can be called whatever you want it to be! $rss_logo="rss.jpg"; // the feed's author email $emailadmin="YourName"; // set the file's content type and character set // this must be called before any output @header("Content-Type: text/xml;charset=iso-8859-1"); // Open the database mysql_connect("localhost","username","password"); @mysql_select_db("database_NameHere") or die("Unable to select DB"); // Select all the records from the Articles/Blog table - whatever you're using it for $query = "SELECT *,DATE_FORMAT(DATE_ADD(date, INTERVAL 5 HOUR), '%a, %d %b %Y %H:%i:%s GMT') AS pubDate FROM YOUR_DATABASE ORDER BY date DESC LIMIT 0,10"; // DATE_FORMAT(date, '%a, %d %b %Y %H:%i:%s') AS pubDate $result = @mysql_query($query) or die("Query failed") ; // dont forget the RSS specification when matching your form to the RSS feed echo '<?xml version="1.0" encoding="ISO-8859-1" ?> <rss version="2.0"> <channel> <title>'.$rss_title.'</title> <link>http://www.'.$rss_site.'</link> <description>'.$rss_description.'</description> <language>en-en</language> <image> <url>'.$rss_logo.'</url> <title>'.$rss_site.'</title> <link>http://www.'.$rss_site.'</link> </image>'; ?> <?php for($i=0;$i<10; $i++) //will loop through 10 times to generate 6 RSS items { // $photo_name = 'where-ever a photo for this article could be found - needs to be http://www.yoursite.com/images/whatever.gif'; $subject = @mysql_result($result,$i,'title'); //subject line for the RSS item $subject = str_replace ("’","'",htmlspecialchars(strip_tags($subject))); // Pass the record URL_product to the variable $url_product. It also // has to include the relative path, like in: "path/product1.htm" $url_product = 'php4me.com/press/article.php'; //define the URL of where people could read this blog/article entry // Define a description of the item $description = @mysql_result($result,$i,'description'); //easiest way is by grabbing the content // Clean the description $description = str_replace ("&amp","",htmlspecialchars(strip_tags($description))); $description2 = str_replace ("’","'",htmlspecialchars(strip_tags($description))); // ’ “” $description3 = str_replace ("“","\"",htmlspecialchars(strip_tags($description2))); $description4 = str_replace ("”","\"",htmlspecialchars(strip_tags($description3))); // Pass tags to describe the product - this has been left ouf of this example //This is a teaser of your article, basically what RSS readers will show the user in their inbox. //This is how you entice users to come over and read the full article //the easiest way is to just take the first few hundred characters of the content (description) $short_description = substr($description4,0,500) . " ..."; //so you can define when it was published // $timestamp = mysql_result($result,$i,'date'); //cleans the timestamp into an RSS friendly format $pubdate = @mysql_result($result,$i,'pubDate'); // date("r", strtotime($timestamp)); //outputs the RSS item $quest = "?id="; $id = @mysql_result($result,$i,'id'); echo ' <item> <title>'.$subject.'</title> <link>http://www.'.$url_product.$quest.$id.'</link> <guid isPermaLink="true">http://www.'.$url_product.$quest.$id.'</guid> <description>'.$short_description.'</description> <pubDate>'.$pubdate.'</pubDate> </item> '; } //end of the for-loop mysql_close(); //close the DB echo //close the XML file ' </channel> </rss>'; ?> <?php highlight_file($_SERVER['DOCUMENT_ROOT'] . $_SERVER['PHP_SELF']); ?> </body> </html>
  19. Here is one more approach without the array: Insert this line after the "while" statement $colors= ($colors== "#F1F5F8" ? "#006600" : "#F1F5F8"); // change colors to suit your page design echo "<p style=\"color: ".$colors.";\">".$row['Name']."</p>";
  20. As far as storing numbers, yes. Make sure to set the field size to hold the largest of your expected number. When actually processing, use intval() <?php $n1= "100"; // assume it came from a vchar field $n2 = "25"; $n3 = intval($n1)+ intval($n2); echo $n3; ?>
  21. Just to have, a method to pull apart your date. The previos post is right as this will not sort correctly in the MySQL code <?php $takeapart = "12.02.2008"; $start_here = explode('.',$takeapart); $month = $start_here[0]; $day = $start_here[1]; $year = $start_here[2]; echo $year.".".$day.".".$month; $post_date = date('m.d.Y'); echo $post_date; // in the database format ?>
  22. try investing preg_replace to search the field and break and hyphenate long or mistyped words <?php $result = "OneTooManyHighlights and the start of a sentance break to prevent css distortion breakingstylestyle"; $result = preg_replace("/([^\s]{14})/","$1 ",$result); echo $result; ?> There is a forum here on Regular Expressions that might be worth exploring. The limitation on this routine is that it doesn't trap for emails or links. If that is part of your text, you will have to expand the regex. Also, don't forget the earlier nl2br() for those extra lines
  23. Are you looking for a tutorial or a ready to go sample application?
  24. Along the lines of the last post, using a system path can work well. <?php $path = "/usr/local/www/vhosts/somepath/"; require_once("$path/db_inc.php"); print "Test Line"; ?> best
  25. Also, you can add the code posted by rajivgonsalves into an ".htaccess" file and place it in your files directory and the html and htm files will process the php code.
×
×
  • 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.