Reading XML RSS Feed

These days there are many websites from which you you can publish their latest information on YOUR site, How ? The XML way.

Sites like Devshed.com, Devarticles.com, XML.com provide an XML format which you can use. But since the format is XML, it can’t be just shown directly, there has to be some sort of formatting done to it. XML-Stylesheet is one way and the other one, that I’ll be explaining to you is using PHP.

xmlCommonly you can see an image like this for feed This is the link from where you can get the XML Feed, or syndicate its content

Code for writing the comment to the DB

Now create a new page called ‘addcomment.php’

<?php
$conn = mysql_connect('localhost', 'username', 'password');
mysql_select_db('yourdb');

$comdate = $_POST['comdate'];
$articleid = $_POST['articleid'];
$comsubject = htmlspecialchars(addslashes($_POST['comsubject']));
$comuser = htmlspecialchars(addslashes($_POST['comuser']));
$comtext = htmlspecialchars(addslashes($_POST['comtext']));

//write the query
$sql = "insert into comments(comdate, articleid, comsubject, comuser, comtext)";
$sql .= " values ('" . $comdate . "', " . $articleid . ", '" . $comsubject . "', '" . $comuser . "', '" . $comtext . "');";

if (!@mysql_query($sql)) {
  echo ('We are unable to register your comment, sorry');
} else {
  echo ("Your comment was added successfully<br>");
  echo ("<A HREF="article.php">Back to Articles</A>");
}

mysql_close($conn);
?> 

User Interface for adding comments

Now that we have had some article in our dB, it is now time to show the article to the world. Plus we need to show the comment to them

Let us make a page called as ‘article.php’ and the article is fetched by getting the a url as ‘article.php?articleid=1’ This will fetch the article # 1 and is stored in the DB as articleid=1

If the articleid query is not given then the page has to display all the aritcle listing with the article subject as an link to ‘article.php?article=[the articleid]’

<?php
//if articleid query is not set, show all the article listing
if (!isset($_GET['articleid'])) {

$conn = mysql_connect('localhost', 'username', 'password');
mysql_select_db('yourdb');

$sql = "select * from articles;";
$result = mysql_query($sql);

echo('<table boder=0 cellpadding=3 cellspacing=1>');
while ($row = mysql_fetch_assoc($result)) {
  echo('<tr>);
  echo('<td>);
  echo('<a href="aricle.php?articleid='.$row['articleid'].'"><b>'.$row['articlesubject'].'</b></a>');
  echo('<tr>);
  echo('<td>);
  echo($row['articlesubject']);
}
echo('</table>')
mysql_close($conn);

} else {

$conn = mysql_connect('localhost', 'username', 'password');
mysql_select_db('yourdb');

$sql = "select * from articles where articleid=" . $_GET['articleid'] . ";";

if (!($result = @mysql_query($sql))) {
  echo('Sorry We are not able to process your request');
} else {
  //now display the data
  $row = mysql_fetch_assoc($result);
  echo ("<p><b>" . nl2br(htmlspecialchars($row['articlesubject'])) .
"</b>");
  echo ("<p>".nl2br(htmlspecialchars($row['articletext']))."<p>");
?>

  Add Comment
  <table>
  <form name='comment' action'addcomment.php' method=post >
  <input type=hidden name='comdate' value="<?php echo(date("Y-m-d H:i:s"))?>">
  <input type=hidden name='articleid' value="<?php echo($_GET['articleid'])?>">
  <tr><td>
  Subject<input type=text name='comsubject' />
  <tr><td>
  User<input type=text name='comuser' />
  <tr><td>
  <textarea name='comtext' rows=15 cols=50></textarea>
  <input type=submit value='Post Comment' />
  </form>
  </table>

<?php
  //now show all the comments for this article
  
  $sql = "select * from comments where articleid=" . $_GET['articleid'] . ";";   $result = mysql_query($sql);
  if (mysql_num_rows($result)<1) {
    echo('No comments posted for this article');
} else {
    while ($row = mysql_fetch_assoc($result)) {
      echo('<p>');
      echo( htmlspechialchars(stripslashes($row['comsubject'])) . ' by ' . htmlspechialchars(stripslashes($row['comuser'])) . ' on ' date("d M Y h:i a", strtotime($row['comdate'])) . '<br>');
      echo( nl2br(htmlspechialchars(stripslashes($row['comtext']))) );
    }
  }
  mysql_close($conn);
  }

}
?>

This now completes the code for viewing the article, the page also displays a form which as a subject textbox, a username textbox and a textarea for comment text.
When user clicks the ‘Post Comment’ button, the data is ‘post’ fed to the page ‘addcomment.php’

Creating tables

The first and most important charecteristic for such type of a system is that the article whatever it may be must be in a database with an articleID associated with it.

So first create an table for an article like this

# Create a table for articles over here
create table articles (
  articleid int(5) primary key auto_increment,
  articlesubject varchar(255),
  articletext text
);

Once done with creating the articles table you need to create a posting table where user can post comments on the article. For that create a table as comments as follows

# Create a table for comments
create table comments (
  comid int(5) primary key auto_increment,
  articleid int(5),
  comsubject varchar(255),
  comuser varchar(255),
  comdate datetime,
  comtext text,
);

Here the articleid is the foreign key, don’t worry about foreign or home. It is just to link the comment to what article. The date time records the date, time in “YYYY-MM-DD HH:MM:SS” format.
comtext is a text field and can store big text values.

Now once you have created the table for article, it is time to fill some values into them let us fill some easy values into it.

> insert into articles(articletext) values ('This is some easy article and is for some testing purpose only');
> insert into articles(articletext) values ('This is another easy article and is for some testing purpose only and not to be fiddled with'); 

PHP Tutorials

Welcome ! to this PHP Tutorials page. I’m not a great PHP code buster, but still I feel that the tricks that I have learnt, found, should be shared with others as well.

Basics

This entry is part 2 of 41 in the series Guitar

An acoustic guitar has 6 strings, hence the “6 string” 🙂
It starts from the E string (this is the string with the lowest pitch, or lowest frequency note), then the A string, followed by the D, G, B strings. And the last one is the e string. This one is the string with the highest pitch. This e sting produces the “E” note of the next octave begining from the base E string.

We’ll denote it as.., This is the plan view (top view) of the guitar, facing the strings.

e +---------------+
B +---------------+
G +---------------+
D +---------------+
A +---------------+
E +---------------+

Now hold the guitar as you generally hold it, the body of it on the lap, and your base of your right hand (considering your are right-handed) on the bridge. Bridge is the point from where the guitar strings start, it is NOT the end where you tune the string with the knobs.

Hold your thumb and index finger as you hold a pen, withing that grip hold the plectrum (pick). The blade of the pick should be at an angle to the strings, and not directly flat to the strings.

Now practice picking the strings, begining from the base E string to the high e string. All the picking should be down strokes. Go in an easy manner, till you get a feel of distances between the strings, etc…

Once you are comfortable with the simple picking start picking alternate strings. i.e. pick E, D, then A, G, then D, B, and G, e. and then back up again. This will help you in getting a hold of picking alternate, different strings.

I’ll explain you a notation that you will follow all over, It is not my notation, probably you must have seen it somewhere.
When I say you play C note, I’ll specify a fret. A fret is marking on which you play a note, to play a note you press your finger just before the nth fret (the fret that is mentioned to produce the note).
So…

e +---------------+
B +---------------+
G +---------------+
D +----0----------+
A +--3------------+
E +---------------+

..means play the 3rd fret on the A string to produce the C note, then the play open D string (i.e do not fret the string anywhere) to play the D note.

Guitar Tutorial

This entry is part 1 of 41 in the series Guitar

This is my guitar class diary, you may consider it to be as your tutorial, guide or whatever, my purpose to publish this one is to keep the contents of my guitar class on the web.
thats it.

I start from my first class where I knew only 1 thing about guitar and that is “6 string” guitar or something… 🙂 quite an information to begin with.

Lets start now…

FIFA 2001 Tips and Tricks

Get some great tips to play FIFA 2001

The Formation

The Fifa 2001 defence is a strong one and normally doesn’t let you inside the area, To tackle that proper formation is required. The image shown along side is the formation of 4-4-2 with the flanks move up and down the pitch. This strategy is found the most suitable if you want to give a cross from wide. The flanks move up and down pretty neatly. To move them ahead, the forwards should wait for a second allow the flanks to come up and then give a through pass to them. The through pass is very necessary as it allows the player to make space for himself.

The Strategy
The strategy will develop your game plan how you want to move ahead and defend. This is very much complementry to the formation. The possesion style will help to keep the possesion of the ball while attacking, This is the most vulnerable time when you lose the possesion. While defensive mode, the pressure style is useful as it will help to move the ball up the field. The possesion style should not be kept while defending as it will lead to the ball being in your half and a possibility of losing possesion in your half which is dangerous.

While defending the offside trap should be kept by pressing ALT once. This will help to move all the defenders towards the half line and not letting the forwards of the other team to creep through. But this offside trap should be kept only if you are capable of breaking a run from the opposite forward and if you know your team’s defensive capabilities.

Camera
The normal TELE camera in the FIFA 2001 game is too very close to judge the other player’s postion. Hence the settings shown in the figure should optimize the game play as you are aware of the positions of your teammates.

Free kicks
Taking free kicks is quite difficult in this game, but once you get hold of it, bingo!! you can certainly master those.
If the free kick obtained is close to the D line then only one should attempt to curl the ball straight into the net. Or else he should try the ball passing to the players in the D. If the free kick that is obtained to the left of the net as in the image, then try to curl the ball to the left, as there is more space for the ball to go and greater probability of hitting the target. Well if you are a master you can certainly try to curl the ball through the left to right direction as chances are you’ll miss the target. Now for the directioning of the curve. Curl the ball as most as possible as it should move away from the keeper. Now by moving the direction keys take the center of the arrow just after the second defender (See the adjoining image). Be careful in doing that as if you move the ball away too much, Then the ball would definitely hit the wall. Then move the curve little downwards from the original height. This shall help to keep the ball down if extra force is applied. After that it is time to power your shot,The power should be the maximum as ball will travel at a greater speed. But be careful that the power indicator should be green only, If dark red appears the ball will definitely go away from the goal. Relax before hitting, Think and Shoot.

Movement on the pitch
The movement on the pitch should be definate and steady, Dont just try to pass directly to the forwards, try to move the ball to the flanks and then try getting the ball in from a cross. I have noticed that if a cross is given just around the D corner, and if the forward is made to hit a bicycle kick or a volley the chances are that ball will end up in the back of net are very high.

Defending
Defending is something that you need to learn as to prevent the opposite team from scoring. While in the D never ever try to tackle by sliding, If the tackle is from behind you are definitely going to defend a penalty. The best way to defend is to stand and tackle. If outside the D, A sliding tackle will do but be sure that it is not from behind.

Tips to play FIFA 99

ऋतुराज का Home Page