Jump to content

xiledweb

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

xiledweb's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I am, but I'm not sure I understand how its going to help me with my problem.
  2. [quote author=fert link=topic=118252.msg483072#msg483072 date=1165890413] substr will do what you want. [/quote] I'm not familiar with substr... I did however try adding [code]echo "<td><a href=\"article.php?id=$id\">$articletext</a></td>\n";[/code] but it returned the error [i]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource[/i].
  3. Ok guys, hope I can get some help with this. I'm running a site which has different categories for users to post articles about. On my main page I will have a list of all the recent articles submitted. On my nav bar are links to the different categories which will display the most recent articles about only the news items in that category. What I want to do is list the first 120 characters (probably more) from the article and use the articletext to link to the full article. Here's what I have so far: [code]$sql = 'SELECT id,LEFT(articletext, 120)          FROM article INNER JOIN articlecategory          ON article.id=articlecategory.articleid         WHERE articlecategory.categoryid=4'; if(!result){ die("sql error: ".mysql_error()); } while ($article = mysql_fetch_array($result)) {   $id = $article['id'];   echo '<p>' . $article['LEFT(articletext, 120)'] . '</p>'; [/code] Could someone point me in the right direction?  ???
  4. I don't suppose you could explain a little bit more?
  5. Ok, I would like my article submission for my audience to be as simple as possible - therefore very little knowledge of HTML would even be necessary. Everything outputs as it should right now, but the content submitted is not broken into paragraphs, i.e the text is continuous. What I want to achieve is that when the user hits 'enter', the interpretation will be that of a new paragraph (or unless there's a better way to do it). Here is what I'm working with: [code]// Filter out HTML code $articletext = htmlspecialchars($articletext); // If no page specified, default to the first page ($page = 0) if (!isset($_GET['page'])) {   $page = 0; } else {   $page = $_GET['page']; } // Split the text into an array of pages $textarray = spliti('\[PAGEBREAK]', $articletext); // Select the page we want $articletext = $textarray[$page]; // Bold and italics $articletext = str_replace(array('[b]', '[B]'), '<strong>', $articletext); $articletext = str_replace(array('[eb]', '[EB]'), '</strong>', $articletext); $articletext = str_replace(array('[i]', '[I]'), '<em>', $articletext); $articletext = str_replace(array('[ei]', '[EI]'), '</em>', $articletext); // Paragraphs and line breaks function to_paragraphs($text) {     $str = '';     foreach (preg_split('#(\r\n|\r|\n)+\s*(\r\n|\r|\n)#', trim((string) $text)) as $p) {         $str .= "<p>" . preg_replace('#\r\n|\r|\n#', "<br />\n", trim($p)) . "</p>\n";     }     return $str; } // Hyperlinks $articletext = eregi_replace(   '\\[L]([-_./a-z0-9!&%#?+,\'=:;@~]+)\\[EL]',   '<a href="\\1">\\1</a>', $articletext); $articletext = eregi_replace(   '\\[L=([-_./a-z0-9!&%#?+,\'=:;@~]+)]([^\\[]+)\\[EL]',   '<a href="\\1">\\2</a>', $articletext); $PHP_SELF = $_SERVER['PHP_SELF']; if ($page != 0) {   $prevpage = $page - 1;   echo "<p><a href=\"$PHP_SELF?id=$id&amp;page=$prevpage\">".       'Previous Page</a></p>'; } echo "<p>$articletext</p>"; if ($page < count($textarray) - 1) {   $nextpage = $page + 1;   echo "<p><a href=\"$PHP_SELF?id=$id&amp;page=$nextpage\">".       'Next Page</a></p>'; } ?>[/code]
  6. Hi, my first CMS I'm working on is almost near completion. However, I've came across an annoying problem that I thought would be easy to implement. The basic idea is that users submit sports articles, and moderators of my choice will get the chance to approve or deny any submitted article for public viewing. In My SQL I added: [code]ALTER TABLE articles ADD COLUMN visible ENUM('N', 'Y') NOT NULL;[/code] and added a checkmark that said 'visible' in the admin article listings. So, I know the query I'm meant to use is [code]WHERE visible='Y'[/code] but to which query do I add it? I have current articles that I've wrote myself and right now they are all set to invisible. I wish to make some of those visible by using the edit article page that I've made: [code]if (isset($_POST['articletext'])):   // The article's details have   // been updated.     $id = $_POST['id'];   $aid = $_POST['aid'];   $articletext = $_POST['articletext'];   $sql = "UPDATE articles SET           articletext='$articletext',           authorid='$aid'           WHERE id='$id'";   if (mysql_query($sql)) {     echo '<p>Article details updated.</p>';   } else {     exit('<p>Error updating article details: ' .         mysql_error() . '</p>');   }   // Delete all existing entries for this   // article from the article category table   $ok = mysql_query("DELETE FROM articlecategory                     WHERE articleid='$id'");   if (!$ok) {     exit('<p>Error removing article from all categories:' .         mysql_error() . '</p>');   }   if (isset($_POST['cats'])) {     $cats = $_POST['cats'];   } else {     $cats = array();   }   foreach ($cats as $catID) {     $sql = "INSERT IGNORE INTO articlecategory             SET articleid='$id', categoryid='$catID'";     $ok = @mysql_query($sql);     if (!$ok) {       echo "<p>Error inserting article into category $catID: " .           mysql_error() . '</p>';     }   } ?> <p><a href="articles.php">New article search</a></p> <?php else: // Allow the user to edit the article   $id = $_GET['id'];   $article = @mysql_query(     "SELECT articletext, authorid FROM articles WHERE id='$id'");   if (!$article) {     exit('<p>Error fetching article details: ' .         mysql_error() . '</p>');   }   $article = mysql_fetch_array($article);   $articletext = $article['articletext'];   $authid = $article['authorid'];   // Convert HTML special characters   // in database value for use in   // an HTML document.   $articletext = htmlspecialchars($articletext);   // Get lists of authors and categories for   // the select box and checkboxes.   $authors = @mysql_query('SELECT id, name FROM author');   if (!$authors) {     exit('<p>Unable to obtain author list from the database.</p>');   }   $cats = @mysql_query('SELECT id, name FROM category');   if (!$cats) {     exit('<p>Unable to obtain category list from the database.</p>');   } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <p>Edit the article:<br /> <textarea name="articletext" rows="15" cols="45"> <?php echo $articletext; ?></textarea> <p>Author: <select name="aid" size="1"> <?php   while ($author = mysql_fetch_array($authors)) {     $aid = $author['id'];     $aname = htmlspecialchars($author['name']);     if ($aid == $authid) {       echo "<option selected='selected' value='$aid'>$aname</option>\n";     } else {       echo "<option value='$aid'>$aname</option>\n";     }   } ?> </select></p> <p>In categories:<br /> <?php   while ($cat = mysql_fetch_array($cats)) {     $cid = $cat['id'];     $cname = htmlspecialchars($cat['name']);     // Check if the article is in this category     $result = @mysql_query(       "SELECT * FROM articlecategory       WHERE articleid='$id' AND categoryid='$cid'");     if (!$result) {       exit('<p>Error fetching article details: ' .           mysql_error() . '</p>');     }     // mysql_num_rows gives the number of entries     // in a result set. In this case, if the result     // contains one or more rows, the condition     // below will evaluate to true to indicate that     // the article does belong to the category, and the     // checkbox should be checked.     if (mysql_num_rows($result)) {       echo "<input type='checkbox' checked='checked' name='cats[]' value='$cid' />$cname<br />\n";     } else {       echo "<input type='checkbox' name='cats[]' value='$cid' />$cname<br />\n";     }   } ?> </p> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <input type="submit" value="SUBMIT" /> </form> <?php endif; ?>[/code]
  7. So, I have a database with sports related articles, and I'm having problems with users running a specific search. The user can search by author, category and 'containing text'. Despite that, it returns all articles listed in the database. Another, nay, several pair of eyes would be appreciated. [code] $authors = @mysql_query('SELECT id, name FROM author'); if (!$authors) {   exit('<p>Unable to obtain author list from the database.</p>'); } $cats = @mysql_query('SELECT id, name FROM category'); if (!$cats) {   exit('<p>Unable to obtain category list from the database.</p>'); } ?> <form action="articlelist.php" method="post"> <p>View articles satisfying the following criteria:</p> <label>By author: <select name="aid" size="1">   <option selected value="">Any Author</option> <?php while ($author = mysql_fetch_array($authors)) {   $aid = $author['id'];   $aname = htmlspecialchars($author['name']);   echo "<option value='$aid'>$aname</option>\n"; } ?> </select></label><br /> <label>By category: <select name="cid" size="1">   <option selected value="">Any Category</option> <?php while ($cat = mysql_fetch_array($cats)) {   $cid = $cat['id'];   $cname = htmlspecialchars($cat['name']);   echo "<option value='$cid'>$cname</option>\n"; } ?> </select></label><br /> <label>Containing text: <input type="text" name="searchtext" /></label><br /> <input type="submit" value="Search" /> </form> [/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.