PHP - Newbie, Spacing Out An Article....sorry!
Similar TutorialsHi All, I have a 'Newspaper' in a game I'm coding. My plan was to have an edition every week and on average 15 articles a week. I would set this out like so. . Code: [Select] <? $select_paper=mysql_query("SELECT * FROM paper WHERE id=1"); while($the=mysql_fetch_object($select_paper)){ ?> <table width=100% class=table> <tr> <td> <td width=50% style=border: none; background-color: transparent; valign=top> <table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000 class='main' align=center> <tr> <td width=500 class='tableheading'><?php echo "$the->title"; ?><center> </center></td> </tr> <tr > <td class="profilerow" align=left><center><?php echo "$the->news"; ?> </td> </tr> <tr > <td class="subtableheader" align=left><center><?php echo "Article By $the->by - $the->date"; ?> </td> </tr> </table> <br> </td> <? } ?> With that repeated for 15 articles per edition. BUT! To save time, space and complication, I would rather do it using something like this. . Code: [Select] $select = mysql_query("SELECT * FROM paper WHERE edition=1 ORDER by id ASC"); $num = mysql_num_rows($select); Could someone tell me how to intergrate this with the layout tables as show in code #1? Thanks! Hello, can you help me on my news article? I would like to be able to add photo on the article. Below is my codes Quote ======= html ======= <?php include_once ('post_news.php'); ?> <form Action="add_news.php" Method="post"> <input name="postdate" type="text" id="postdate"> <input name="title" type="text" id="title"> <textarea name="newstext" cols="60" rows="15" id="newstext"></textarea> <input type="submit" name="submit" value="Submit"> <input type="reset" name="reset" value="Reset"> </form> ============== php - post_news.php ============== <?php ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); if (isset ($_POST['submit'])) { require_once ('inc/dbConfig.php'); // Define the query. $query = "INSERT INTO news (id, postdate, title, newstext) VALUES (0,'{$_POST['postdate']}', '{$_POST['title']}','{$_POST['newstext']}')"; // Execute the query. if (@mysql_query ($query)) { print "<p>Data has been added.</p>"; } else { print "<p>Could add the entry because: <b>" . mysql_error() . "</b>. The query was $query.</p>"; } mysql_close(); } ?> ===== db structure ====== id int(10) unsigned NOT NULL auto_increment, postdate timestamp(14), title varchar(50) NOT NULL, newstext text NOT NULL, PRIMARY KEY (id), KEY postdate (postdate) Hope you guys can help me. Thanks! I have manage to create my own script that add news article, however, I would like to add a comment form below the news article. How can I relate the news and the comments? also, when I delete the articles, it should also delete the comments in mysql. Your help is highly appreciated! I have a database in which i store articles that contain all type of special characters including slashes, single quotes, double quote etc. Previously it was working fine, but now after the updating the xampp, things are not going as usual. I insert are articles using following code $query = "INSERT INTO `articles` (`source`, `heading`, `description`, `catagory`, `detail`, `date`, `timestamp`) values ('$source', '$heading', '$desc', '$catagory', '$detail', '$date', '$timestamp')"; Error I am getting is Error Running query 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's economy and emphasized that international community should provide its complet' at line 2 Can anybody tell me whats wrong with my script? I'm feeling a little overwhelmed/burned-out/confused... I have a page "article_index.php" that contains a summary of each article plus a link to it, e.g. Code: [Select] <a href="<?php echo WEB_ROOT; ?>articles/postage-meters-save-you-money"> When you click on a link, it goes to "article.php" and uses a mod_rewrite to transform the "pretty URL" to regular URL that "article.php" can use to query the correct article from my database. ----- Here is what I need help with... When a user is on a given article page, I want to sto - ReturnToPath - ArticleID in the SESSION. I am drawing a blank on how to get the "ArticleID" when a user is on a give page?! Hope you guys follow me?! Debbie I am developing a CMS with articles and categories. I am making a feature for the admin panel that shows all the categories. In the table, I would like to include each category's latest article. My traditional method is to select just the categories in one query, loop through the results, and then inside the category loop have a query that gets the information on the latest article... So something like...
$query = " SELECT category_id, title, description FROM categories ORDER BY title ASC"; if($query = mysql_query($query)){ while($cat=mysql_fetch_assoc($query)){ $query_article = " SELECT article_id, category_id, title FROM articles WHERE category_id = ".$cat['category_id']." ORDER BY article_id DESC LIMIT 1"; $last = mysql_fetch_assoc($query_article); } }How could I use joins and/or subqueries to achieve my goal of combining these two queries into one? I have come up with a query which is below: SELECT c.category_id, c.title, c.description, a.article_id, a.category_id, a.title, COUNT(a.article_id) AS total_articles FROM article_categories AS c LEFT JOIN articles AS l ON ( SELECT article_id AS article_id, category_id, title AS article_title FROM articles AS l WHERE l.category_id = c.category_id ORDER BY l.article_id DESC LIMIT 1) LEFT JOIN articles AS a ON (c.category_id = a.category_id) GROUP BY c.category_id ORDER BY c.title ASCWhen I use the above query, I get an error saying "Operand should contain 1 column(s)" I would also like to add something that counts the total number of articles in the category. Thanks for your time! I'm building an article system, what im trying to do is when a user choose the article to be published tomorrow to able to. Write today the article but the system will show it from tomorrow Code: [Select] $gettoday = date("Y:m:d"); $query = "SELECT * FROM tblnews WHERE MainArticle = 1 AND NewsDate = '".$gettoday."' ORDER BY `Id` DESC LIMIT 1"; $result = mysql_query($query); This is my code, but when i use this and the article is not posted for today is not showing anything.. any suggestions please? Thank you Hello, I am trying to create article directory for learning PHP MySql and i want to write a script for recording number of views for an article and store it in Database. Can anyone please direct me to a nice simple tutorial or help me with the steps or algorithm? Suppose the link for an article is http://www.domain.com/article.php?id=123 Do i need to put extra variables and create a tracking PHP file for it? hi there, basically in my database i have DATETIME for when an article was posted, using this, I'd like to make it possible for viewers of the article to see when it was posted in a "Posted Today", "Posted Yesterday" or Posted 23 hours ago" format. If it was posted longer ago than yesterday, then I would like it to just be the normal date. I know how to work out if it was posted today, just through: $date = date('j F', strtotime($rows['date'])); $today=date('j F'); but not sure how to do the hours. thanks! This topic has been moved to Apache HTTP Server. http://www.phpfreaks.com/forums/index.php?topic=322454.0 Hi all - I'm setting up a custom PHP blog. It pulls the data from a MySQL database which includes HTML tags (<p><div><span> etc...). I would like to display only up to 50 words per post on the blog page, which users can then read and click a link to then see the entire post. I've developed some code which does this, however, it seems to be stripping my HTML tags... Very sad! Would be very very grateful if one (or more) of you kind lot would have a look at my code and let me know if there is a easier (I'm all for easy) and proper way of implementing this so that it works without stripping my HTML tags. Cheers!!! Code: [Select] // Counts number of blog words in the content $blog_content_words = str_word_count($blog["content"], 1); // Sets the blog_words variable to 0 $blog_words = 0; // Prints title on page as a permalink to a post echo '<h1><a href="blog.php?id='.$blog["id"].'">'.$blog["title"].'</a></h1><p>'; // Loops while blog_word is under 50 while($blog_words < 50) { // Prints a word from blog_content_words array of blog post and adds a space afterwards echo $blog_content_words["$blog_words"]." "; // Adds 1 to the blog_words counter ++$blog_words; } // Adds a read more link to the post which links to full blog post echo '... <a href="blog.php?id='.$blog["id"].'">[read more]</a></p>'; i need to submit 1 article (3 input fields: title, category, description), to multiple sites. it must be done with 1 click. one more thing... each site to which i have to submit has different input names, but are the same 3, also 1 is for title 1 for category and 1 for description. So i have this CMS that is used by lots of users and generally they do have rights to edit each others article. So now i'm thinking how can i at least warn them that somebody else is already editing it. Just that. maybe with sessions? but what happens when a user just closes the windows, will it destroy it. i taught about storing the value to mySQL but again what if the user closes the windows and so on. i never did this and i could use a boost. thanks guys Why is double spacing the results I know it's stupid simple but I can't see it. I removed $host ip so if you test put one in there. <!doctype html> <html lang="en"> <html> <body> <?php ini_set('max_execution_time', 0); ini_set('memory_limit', -1); $host = "insert IP"; $ports = array(21 ,22 ,23 ,25, 80, 81, 110, 143, 443, 587, 2525, 3306); foreach ($ports as $port) { $connection = @fsockopen($host, $port, $errno, $errstr, 2); if (is_resource($connection)) { echo '<p>' . $host . ':' . $port . ' ' . '(' . getservbyport($port, 'tcp') . ') is open.</p>'; fclose($connection); } else { echo '<p>' . $host . ':' . $port . ' is not Open.</p>'; } } ?> </body> </html>
Need to change the letter spacing.. help? $tag = 'www.xxxxxx.com'; $text_draw->setFontSize(8); $text_draw->setFillColor("black"); $output_image->annotateImage($text_draw, 123, 34, 0, $tag); $text_draw->setFillColor("white"); $output_image->annotateImage($text_draw, 122, 33, 0, $tag); This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=343705.0 I need the following XML code http://primarymortgages.co.uk/dev/property-xml-donotdelete.xml to be entered into the database, while I have done the first bit... <code> # address - basic info if(is_object($xml->address)) { foreach($xml->address as $address) { $name = $address->name; $street = $address->street; $locality = $address->locality; $town = $address->town; $county = $address->county; $postcode = $address->postcode; $custom_location = $address->custom_location; $display = $address->display; $insertS = "INSERT INTO $tablec (pal, afield, bfield, cfield, dfield, efield, ffield, hfield, ifield, jfield) VALUES (110, '$bD->afield', '$name', '$street', '$locality', '$town', '$county', '$postcode', '$custom_location', '$display')"; $insertQ = mysql_query($insertS); $iid = mysql_insert_id(); } } # property - basic info if(is_object($xml)) { $long = $xml->longitude; $lat = $xml->latitude; $type = $xml->type; $furnished = $xml->furnished; $bedrooms = $xml->bedrooms; $bathrooms = $xml->bathrooms; $description = $xml->description; $updateS = "UPDATE $tablec SET kfield = '$long', lfield = '$lat', mfield = '$type', nfield = '$furnished', ofield = '$bedrooms', pfield = '$bathrooms', atext = '$description' WHERE pal = 110 AND id = $iid"; $updateQ = mysql_query($updateS); } </code> I need to be able to get the paragraphs... <paragraph id="1" type="0"> <name>DESCRIPTION</name> <file /><dimensions> <metric /> <imperial /> <mixed /> </dimensions> <text>Primary are pleased to offer this two bedroom first floor maisonette in Wootton Bassett. The accommodation comprises of private entrance hall, lounge, kitchen, two bedrooms and bathroom. The property also benefits from uPVC double glazing, central heating and two allocated parking spaces. No onward chain.</text> </paragraph> <paragraph id="2" type="0"> <name>PRIVATE ENTRANCE PORCH</name> <file /> <dimensions> <metric /> <imperial /> <mixed /> </dimensions> <text>Storage cupboard.</text> </paragraph> <paragraph id="3" type="0"> <name>PRIVATE ENTRANCE HALL</name> <file /> <dimensions> <metric /> <imperial /> <mixed /> </dimensions> <text>Stairs leading to first floor. Radiator.</text> </paragraph> etc, etc... However the following code isn't working for me... <code> # paragraphs print_r ($xml->paragraph); foreach($xml->paragraph as $paragraph) { $thetitle = $paragraph->title; $thetext = $paragraph->text; $insertS = "INSERT INTO $tablec (pal, afield, bfield, atext) VALUES (111, '$iid', '$thetitle', '$thetext')"; $insertQ = mysql_query($insertS); print "<p>$insertS</p>"; } </code> Can someone adjust the # paragraphs code for me so it can work Many Thanks. HI guyz, want help in a code that can help find the GCD of two input numbers Use the example of GCD (12,15). I am brand new to php and the following code gives me an error of undefined variable although it seems to be defined. Please tell what I'm doing wrong cause this code comes from a book: <?php // Definition of the class Donation class Donation { private $name; private $amount; static $totalDonated = 0; static $numberOfDonors = 0; // Function to display what each person has donated function info() { $share = 100 * $this->amount / Donation::$totalDonated; return "{$this->name} donated {$this->amount} ({$share}%)"; } function __construct($nameOfDonor, $donation) { $this->name = $nameOfDonor; $this->amount = $donation; Donation::$totalDonated = Donation::$totalDonated + $donation; Donation::$numberOfDonors++; } function __destruct() { 109) Donation::$totalDonated = Donation::$totalDonated - $donation; Donation::$numberOfDonors--; } } It gives me the following error: Notice: Undefined variable: donation in C:\wamp\www\learnPHP\unitCounter.inc on line 109 |