PHP - Error In Nesting My News Feed
I am working on a feed but am getting the nesting wrong, the </event> is appearing at the end of the whole feed and not at the end of the particular event.
Here is a link to the feed http://www.horseeventsuk.com/events-feed-test.php and my code is Code: [Select] ?> <?php :'( $output_as_html=false; if ($output_as_html) echo '<html><head><title>Events Feed</title></head><body><h1>Events Feed</h1>'; $xml='<events>'; $sql="SELECT * FROM `events` WHERE event_status='live' ORDER BY event_created DESC LIMIT 3;"; $xml.='<event>'; $result=mysql_query($sql); if ($result) { while ($row=mysql_fetch_array($result)) { $event_id=$row['event_id']; $venue_id=$row['ven_id']; $county_id=FindVenueCountyId($venue_id); //print("Found event ".$event_id.'<br />'); $xml.=EchoRowItem($row,'title',$output_as_html); //$xml.=EchoRowItem($row,'description',$output_as_html,'event_details'); $xml.=EchoTag('contact_email','gilly@rackfield.co.uk',$output_as_html); $xml.=EchoTag('county',FindVenueCountyName($venue_id),$output_as_html); $xml.=EchoTag('postcode',FindVenuePostcode($venue_id),$output_as_html); $xml.=EchoTag('website_address',BuildEventURL($event_id,$county_id),$output_as_html); $xml.=EchoRowItem($row,'startdate',$output_as_html); $xml.=EchoTag('category','Animals, Convservation',$output_as_html); $xml.=EchoTag('category','Sport',$output_as_html); $xml.=EchoTag('category','Exhibitions, Shows',$output_as_html); } } $xml.='</event>'; $xml.='</events>'; if ($output_as_html) echo '</body></html>'; else { // serve the xml file header("Content-type: text/xml"); echo '<?xml version="1.0" encoding="UTF-8"?>'; echo $xml; } exit; Similar TutorialsWhat's the best way to create a news feed? How would you guys do it? Would you have to have a time stamp stored for when each action occurred? I was wondering what approach you would take to code a news feed like Facebook has. I have a status, users, and photo mysql tables. Would you create a new table called "feed" and have a query run everytime someone updates, inserts, etc anything in those three tables? or something else? What would be the most efficient way to code a news feed? Thanks in advanced! When a post is approved I only want $details = $_POST['newstitle']; update_user_actions(8, $details); Being posted once with the corresponding news article title. Any way to achieve this? Right now it is looping through all of the titles and is posting them all. Code: [Select] foreach($posts as $post) { $displayName = ucwords("${post['firstname']} ${post['lastname']}"); if (isset($_POST['approve'])) { if(is_array($_POST['approve'])) { $keys = array_keys($_POST['approve']); $id = $keys[0]; $details = $_POST['newstitle']; update_user_actions(8, $details); $sql = "UPDATE `news` SET `newsdate` = NOW(), `approved` = 1 WHERE `id` = '$id'"; header("Location: " . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'] ); } } else if (isset($_POST['deny'])) { if(is_array($_POST['deny'])) { $keys = array_keys($_POST['deny']); $id = $keys[0]; $sql = "UPDATE `news` SET `newsdate` = NOW(), `approved` = -1 WHERE `id` = '$id'"; header("Location: " . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'] ); } } else if (isset($_POST['delete'])) { if(is_array($_POST['delete'])) { $keys = array_keys($_POST['delete']); $id = $keys[0]; $sql = "DELETE FROM `news` WHERE `id` = '$id'"; header("Location: " . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'] ); } } if(isset($sql) && !empty($sql)) { mysql_query($sql) or die(mysql_error()); } ?> How does facebook do their news feed? Or can you think of an algorithm that will do this effectively? I thought of an algorithm, but it's not that effective. My algorithm goes like this, choose 10 random friends from their friends list, and then put the latest updates of these friends into an array in order, then output the updates onto the feed in order. The problems with this algorithm are that this makes the feed change every time because there are new random friends shown. Then there's the problem of choosing friends that are inactive, therefore showing updates from a long time ago. Any suggestions? I've been hacking at this for 3 hours now.. My syntax seems to be screwed up on something, but I cannot find it for the life of me! Error thrown is obvious I am missing or have something nested wrong! Parse error: parse error in C:\wamp\www\php\php_study\login_processor.php on line 22 Here is my code. Error is being thrown on the line of the elseif statment. <?php include('db_cxn.php'); $cxn = mysqli_connect($host, $user, $pass, $db) or die("Query died: connect"); $sql = "SELECT username FROM users WHERE username = '$_POST[username]'"; $result = mysqli_query($cxn, $sql) or die("Query Died: username"); $num = mysqli_num_rows($result); if ($num > 0) { $sql = "SELECT username FROM users WHERE username='$_POST[username]' AND password=md5('$_POST[password]')"; $result2 = mysqli_query($cxn, $sql) or die("Query died: password"); $num2 = mysqli_num_rows($result2); if ($num2 > 0) { $_SESSION['auth']; $_SESSION['logname'] = $_SESSION['username']; } //if ($num2 > 0) header("Location: the_secret_page.php"); } //if ($num > 0) else { $message1 = "The login name, '$_POST[username]' does not exist in the database. Please try again"; $username = strip_tags(trim($_POST[username])); include('login_form.php'); } //else elseif ($num == 0) { $message1 = "The username you entered does not exist. Please try again.s"; include("login_form.php"); } //elseif ($num == 0) ?> I don't think my form html/php code is necessary, but I'll include it for reference: <h1>Login Form</h1> <?php $fields_1 = array("username" => "User Name", "password" => "Password"); ?> <form method="post" action="login_processor.php"> <fieldset> <legend>Login Form</legend> <?php if (isset($message_1)) { echo "$message_1"; } //if (isset($message_1)) foreach ($fields_1 as $field => $value) { if (preg_match("/pass/i", $field)) $type = "password"; else $type = "text"; echo "<div id='field'> <label for='$field'>$value</label> <input id='$field' name='$field' type='$type' value='" . @$$field . "' size='20' maxlength='50' /> </div>\n"; } //foreach ($fields_1 as $field => $value) ?> <input type="submit" name="Button" value="Login" /> </fieldset> </form> Hello everyone, I have a script that shows the news posted on my website in a bigger format with comments ect... but it gives me the error Code: [Select] Parse error: syntax error, unexpected '}' in /home/stormgc/public_html/sources/news_view.php on line 50 I reviewed the code, I know what the error fix would be, but I cannot find the proper place to put it. If someone could please review the script and help that would be awesome! --> Code: [Select] <? $id = $_GET['id']; $news = mysql_query("SELECT * FROM `news` WHERE id='$id'"); if(mysql_num_rows($news) > 0){ $newz = mysql_fetch_array($news); loadHeader($newz['title']); } if($_GET['update'] == 1){ confirm('You have successfully updated this news.'); } ?> <br /> <div class="title"><? echo $newz['title']; ?><span class="options"><a href="index.php">Home</a> / <? echo $newz['title']; ?></span></div> <div class="content"> <? $username = $newz['username']; ?> <div class="category"><a href="index.php?action=news_view&id=<? echo $newz['id']; ?>"><? echo $newz['title']; ?></a> posted on <? displayTime($newz['time'], 'F jS, Y \a\t g:i a'); ?> <span class="options">By <? $accounts = mysql_query("SELECT * FROM accounts JOIN profiles ON accounts.username=profiles.username WHERE accounts.username='$username'"); if(mysql_num_rows($accounts) > 0){ $account = mysql_fetch_array($accounts); ?> <a href="index.php?action=profile&user=<? echo $account['username']; ?>">{<? } echo $account['display_name']; ?></a> <? } else { echo $username; } ?> </span></div> <div class="cell1"> <? echo parseText($newz['message']); ?> <br /><br /> <a href="index.php?action=forums">Discuss this in the forums...</a> <? if($cur_account['staff'] == "on" || $cur_admin == 1){ ?> <br /> <br /> <a href="index.php?action=news_modify&id=<? echo $newz['id']; ?>">Modify</a> | <a href="" onClick="if(confirm('Are you sure you want to delete this news?')){ location.href='index.php?action=news_delete&id=<? echo $newz['id']; ?>'; } return false;">Delete</a> <? } ?> </div> <? loadFooter(); } else { fatalError('The news article you are trying to view does not exist.'); } ?> Thanks, NW I couldn't fix this issue for 3 three days, please help me.. code: http://trante.heliohost.org/devrss/yol2.php source: http://trante.heliohost.org/devrss/yol2.txt I want to create an RSS feed to put on my site but i couldn't add it to Google Reader etc. I couldn't validate as well. http://validator.w3.org/feed/ ------------ I take variables from "rssdata.php" file. I set one variable with $mytitle=$arrayPlainText[0]; encoding of $mytitle is ASCII. I use XMLWriter class of php. I set the encoding of xml file as UTF-8 in header. When i open the file in my browser, it shows with no error, but the source code of the output has characters like ü ö. My issue in my php page where i need to show all the news that have the status only active. in my mysql table i have 3 fiels news,posted date and expiry date. on page load i check the status of the news and displays only the active news.For that i am doing the following code,which gives me error. that is on page load, first i select all the news ,update the status inactive for the news which has crossed expiry time i check the status of the news and displays only the active news.For that i am doing the following code,which gives me error. $query1="select time(date_posted),time(expiry_time) from muh_title where status='Active'"; $res=mysql_query($query1); $row=mysql_fetch_row($res); $expiry_time=$row[0];$dateposted=$row[1]; $query11="select addtime(time(date_posted),time(expiry_time)) from muh_title"; $res11=mysql_query($query11); $row11=mysql_fetch_row($res11); $newtime=$row11[0]; $query2="SELECT TIMEDIFF(time(date_posted) ,time(NOW())) FROM muh_title"; $res2=mysql_query($query2); $row2=mysql_fetch_row($res2); $diff=$row2[0]; //while($newtime){ $query5="select *from muh_main_title where date_posted> date_sub(now(),interval (expiry_time) hour-minute )"; //$query3="update muh_title set status='Inactive' "; $res3=mysql_query($query5); } $q="select * from muh_title where status='Active' "; $r= mysql_query($q); $row= mysql_fetch_row($r); echo "<font size='6' color='white'><b><marquee direction='left' loop='-1' align='absmiddle' behaviour='scroll' scrolldelay='90'>$row[1]</marquee></b></font>"; ?> i am sure some where i have lost the flow of code. I am writing a script that can handle either csv or xls files. Once the data is parsed for either type it goes into an array $data and all the same operations are done on it. Right now, it is only set up to handle a csv file. This is the code I have right now: //Load the CSV files in the UPLOAD_PATH directory $fileList = $fs->loadFiles(UPLOAD_PATH, "csv"); // Loop through fileList array to processes each file foreach($fileList as $filename) { // Attempt to open the next file in the list and process it. if (($handle = fopen(UPLOAD_PATH.$filename, "r")) != FALSE) { // Create the input array while(($data = fgetcsv($handle, 0, ",")) != FALSE) { // ... do the magic How do I add another set of instructions to goto the parseXLS function that performs basically what fgetcsv does? I think in this case a try...catch statement would be too loose, and wouldnt be the best way. What I would LIKE to do is if (a csv file) { while(($data = fgetscv($handle, 0, ",")) != FALSE) { } else if (an xls file) { while ($data = parseXLS()) { } // Do the magic } // end of while I know this won't work but i need to do something along those lines. Any ideas? I have a query that is very messy. I have tried using () to seperate everything and when I do it just all goes wrong. here is the query SELECT posts.*, users.*, countries.countryID, countries.country FROM posts INNER JOIN users ON users.userID = posts.postUserID INNER JOIN countries ON countries.countryID = users.userCountry WHERE posts.cityID = '".$row_rs_city['cityID']."' AND posts.type = 'sightseeing' OR posts.cityID = '".$row_rs_city['cityID']."' AND posts.type = 'Inner city sightseeing' OR posts.cityID = '".$row_rs_city['cityID']."' AND posts.type = 'Outer city sightseeing' ORDER BY posts.postID DESC Is there a way of re-writing this so that it has brackets seperating everything and it will still work. It works for the minute but re- writing posts.cityID = '".$row_rs_city['cityID']."' inbetween every OR just seems wrong. Thanks for your help guys This code returns part but not all of what I'm asking it to do. Variable $av1 is drawn from the database and always has a value of 1 or 0 (tinyint). If value is 1 a green ON is displayed and if 0 a red OFF is displayed. That works. The variable $group1 exists or not, and if exists the code should proceed and if not exist there should be a display of "". In other words, I do not want to see any display if $group1 does not exist, but this is not working. There is always a display. Can anyone point out my mistake? Code: [Select] <?php if($group1 != "") { { echo "<input type='radio' name='1' value='$group1' />"; ?> <?php echo $group1; } ?> is switched <?php if($group1 != "") if($av1 !== 0) echo ("<span style=\"color:#080\">ON</span>"); else echo ("<span style=\"color:#F00\">OFF</span>"); }else{ echo ""; } ?> if($AClass->select_error || $BClass->ErrorFile){ include("/path/to/files/".($AClass->select_error ? 'no_selector' : 'error_file_missing').".php"); exit; } if($CClass->WriteError){ include("/path/to/files/FileWriteError.php"); exit; } Probably a simple one for you folks, but I can't for the life of me work out how to make the above into 1 line of ternarys. Cheers, Rw Hi all, I'm new to php and I was trying to send the results of one query to another query. I need the results of both queries. Here are the queries $cui1 = mysql_query("SELECT DISTINCT CUI FROM MRSTY WHERE STY='ABC' "); $cui2 = mysql_query("SELECT DISTINCT CUI FROM MRSTY WHERE STY='XYZ' "); I want to know if this is possible $cuis = mysql_query("SELECT CUI1,CUI2,REL FROM MRREL WHERE CUI1 IN $cui1 OR CUI1 IN $cui2 "); Thanks. I think this is the right place to post this but please move if needed as this is my first time on this site. You can also contact me through AIM: MadLittleMods@gmail.com Okay so I have a multidimensional array that is giving me an error when I put it in a function: ERROR: Warning: Invalid argument supplied for foreach().. line 123 LINE 123: foreach ( $affiliates as $affiliate ) This does work when in one file test2.php which is attached to this post... Here is my whole function: // affiliate content function start: function affiliates_content() { global $context, $settings, $options, $scripturl, $txt; foreach ( $affiliates as $affiliate ) { echo ' <table> <tr> <td> <a href="',$affiliate[href],'"><img src="',$affiliate[image],'"></a> </td> <td> ',$affiliate[title],' <br> <small><a href="',$affiliate[href],'">',$affiliate[href],'</a></small> </td> </tr> </table> <br> '; } } // affiliate content function end Here is my whole array which is located on another file (subs.php - smf) // affiliates array for affiliates page $affiliates = array( array( "title" => "aff_blah1", "image" => "http://aff_blah1.net/images/aff_blah1.png", "href" => "http://aff_blah1.net/" ), array( "title" => "aff_blah2", "image" => "http://aff_blah2.net/images/aff_blah2.png", "href" => "http://aff_blah2.net/" ), array( "title" => "aff_blah3", "image" => "http://aff_blah3.net/images/aff_blah3.png", "href" => "http://aff_blah3.net/" ), ); // affiliates array end Does anyone know how to fix this problem? Hi all, i have a form for add-/edit- news. my fields are :id postdate title newstxt formember preimg img1 img2 img3 authr. i store (modified by concat date)names of news images in table and upload theme in folder /dir/newsimg. i want my images in jpg/gif format and for preimage (103*103 pixel & <5KB) and for img1,2,3 (width:650 pixel & <50KB ). Here is my (multipart)form: <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" enctype="multipart/form-data"> <div><input id="post_title" type="text" size="30" tabindex="1" value="news title" /></div> <textarea cols="80" rows="10"></textarea> <div > <h3>Just For Members:</h3> <ul> <li> <label><input type="checkbox" name="chbox" />yes</label></li> </ul><BR/> <ul> <h4>news pics</h4> <li><p>preimg pic must be 103*103 pixel and maxsize <5kb. </p></li> <li><p> for image1,image2,image3 weightsize must ebe 650pixel and maxsize mustbe <50 kb. </p></li> <li> <INPUT TYPE=file NAME="preimg" size=20 accept="image/jpeg,image/gif"> </li> <li><INPUT TYPE=file NAME="image1" size=20 accept="image/jpeg,image/gif"> </li> <li><INPUT TYPE=file NAME="image2" size=20 accept="image/jpeg,image/gif"> </li> <li><INPUT TYPE=file NAME="image3" size=20 accept="image/jpeg,image/gif"> </li> </ul> <p> <input type="submit" value="preview" /> <input type="submit" value="save" /> </p> </div> </form> in INSERT and for TEST MY IMAGES what should i add? my php code is : include_once '../../config.inc.php'; if (!include '../autorization.php') { echo 'Access denied!'; exit (); } if ($_POST['submit']) { $SQL = 'INSERT INTO news VALUES(?:for images); if (!(mysql_query ($SQL))) { exit ('Can\'t PUBLISH news!'); ; } if ($_FILES['logo']['name']) { if (copy ($_FILES['preimg']['tmp_name'], $documentroot . ('' . ' /dir/newsimg/' . NOW() . '.') . substr ($_FILES['preimg']['type'], 6))) { unlink ($_FILES['logo']['tmp_name']); } } if ($_FILES['image1']['name']) { if (copy ($_FILES['image1']['tmp_name'], $documentroot . ('' . ' /dir/newsimg/' . NOW() . '.') . substr ($_FILES['image1']['type'], 6))) { unlink ($_FILES['image1']['tmp_name']); } } if ($_FILES['image2']['name']) { if (copy ($_FILES['image2']['tmp_name'], $documentroot . ('' . ' /dir/newsimg/' . NOW() . '.') . substr ($_FILES['image2']['type'], 6))) { unlink ($_FILES['image2']['tmp_name']); } } if ($_FILES['image3']['name']) { if (copy ($_FILES['image3']['tmp_name'], $documentroot . ('' . ' /dir/newsimg/' . NOW(). '.') . substr ($_FILES['image3']['type'], 6))) { unlink ($_FILES['image3']['tmp_name']); } } } TNX. Hi guys i have been racking my brains been on about 5 different forums now with no joy either.. so here goes I am looking for a PHP news script thing, so I can have a column on the right hand side of my home page updating students results in passing or failing. I have looked and looked for php news scripts and none work they all are defect i am using a windows server, using wampserver to test my files locally.. any ideas or help.. would be oh so much appreciated I have this code.. <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { mysql_query("INSERT INTO blog (date, name, desc) VALUES ('" . date("Y-m-d") . "', '". realEscape($_POST['name']) ."', '". realEscape($_POST['desc']) ."') ") or die(mysql_error()); echo "News Added."; } ?> <center><h1>Adding News</h1> <form action="news.php" method="POST"> Your News Name:<br> <input id="name" type="text" name="name" autocomplete="off" maxlength="25"><br>Your News Description: <br> <textarea name="desc" id="desc" rows="3" cols="60" maxlength="250"> </textarea><br> <input type="submit" name="submit" value="Add News"> </form> And the error is Code: [Select] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc) VALUES ('2010-09-02', 'vcv', ' xcvxc')' at line 1 Note: vcv and xcvxc are the inputs we(I) used for a test so we(I) could get the error. Before I posted in here about a content management system for posting news. I was wondering how I could make so that when you fill out a form and send all the data to the database, it creates a new page from a template and includes that data within it? I know I asked this before, and some mentioned the _get method, but im using _post to process the form data and have no idea where to integrate the _get method. Here's the form in question: Code: [Select] <form action="http://www.djsmiley.net/cms/news/process.php" method="post" id="news"> <h1>Post New Article</h1> <p>Please fill out all of the following fields:</p> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="55" class="cmsNewsformText">Type*:</td> <td><font size="1"> <input name="type" type="text" class="Form1" size="50" /> </font></td> </tr> <tr> <td height="55" class="cmsNewsformText">News Topic/Title*: </td> <td><font size="1"> <input name="title" type="text" class="Form1" size="50" /> </font></td> </tr> <tr> <td height="55" class="cmsNewsformText">Username*:</td> <td><font size="1"> <input name="user" type="text" class="Form1" value="DJ Smiley" size="50" /> </font></td> </tr> <tr> <td height="55" class="cmsNewsformText">Url*:</td> <td><font size="1"> <input name="url" type="text" class="Form1" size="50" /> </font></td> </tr> <tr> <td height="55" class="cmsNewsformText">Message*:</td> <td><font size="1"> <textarea name="message" cols="43" rows="10" class="TextField1"></textarea> </font></td> </tr> <tr> <td height="55" class="cmsNewsformText"> </td> <td><font size="1"> <input name="Submit" type="submit" class="Button1" value="Submit" /> <input name="Submit2" type="reset" class="Button1" value="Reset" /> </font></td> </tr> </table> </form> and here's the code that sends the data from the forms to the database: Code: [Select] <?php $user=$_POST['user']; $title=$_POST['title']; $message=$_POST['message']; $type=$_POST['type']; $url=$_POST['url']; mysql_connect("hostname", "username", "password") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); $sql = sprintf("INSERT INTO mynews (user, title, message, type, url) VALUES ('%s', '%s', '%s', '%s', '%s')", mysql_real_escape_string($user), mysql_real_escape_string($title), mysql_real_escape_string($message), mysql_real_escape_string($type), mysql_real_escape_string($url)); $result = mysql_query($sql); Print "The article has successfully been posted"; ?> can someone help or at least point me in the right direction? Hello everyone, I'm making a site with PHP script and PHPmyadmin database, i need some help with how to add news and then edit them or delete them on the site, not in the Database(if that is even possible to do it there), so far i can only delete the news, but when i try to add new stuff i just get the error message of my code, which is not very nice of it but hey, i'm a noob at this PHP so i must be doing something wrong. this is the code i have for the current situation. Code: [Select] <?php include_once( 'database_functions.php' ); $connectID = connectToDatabase( 'login' ); mysql_set_charset( 'utf8', $connectID ); $categories = mysql_query('SELECT * FROM ref_categories', $connectID); if( @$_POST && @$_POST['submitted'] && ( !@$_GET[ 'id' ] ) ) { $title = ( $_POST[ 'topic_name' ] ); $topic = ( $_POST[ 'topic_desc' ] ); //write to database mysql_query ( "INSERT into news (title, topic) VALUES ('$title', '$topic')", $connectID ) or die ("Unable to insert record into database"); print "Record successfully added"; } elseif( !$_POST && $_GET && $_GET['id'] ) { $id = $_GET['id']; $thisRecord = mysql_query("SELECT * FROM ref_categories WHERE id = $id", $connectID ) or die( "Can't Read this record." ); $recordData = mysql_fetch_array( $thisRecord, MYSQL_ASSOC ); } elseif( $_POST && $_POST['submitted'] && ( $_GET['id'] ) ) { $title = ( $_POST[ 'title' ] ); $topic = ( $_POST[ 'topic_desc' ] ); $id = $_GET['id']; $success = mysql_query( "SELECT * FROM news", $connectID ) or die( "Can't Update this record" ); if( $success ) { header( 'Location: links_admin.php?updated=1' ); } } else { } ?> |