shashank
shashank

Reputation: 399

URL manipulation in php

I have a table called blogtable where I have two fields. One is title and the other is content. I retrieved the only title rows in the form of links and saved it in a file called result.php.

Here is my code:

<?php
mysql_connect("localhost","root","");
mysql_select_db("test");
$data = mysql_query("select title from blogtable");

while($col = mysql_fetch_field($data))
{
    echo $col->name;
}

while($row = mysql_fetch_row($data))
{
    for($i = 0; $i < count($row); $i++)
    {
        echo"<br/>";
        echo "<a href=\"".$row[$i]."\">".$row[$i]."</a>";
        echo "<br/>";
    }
}
?>

I want to retrieve particular title along with content by using URL manipulation. I tried this but I don't know how to pass file URL. I wrote the following and the file name is parse.php.

<?php
$a = $_GET['title'];
mysql_connect("localhost","root","");
mysql_select_db("test");
$sqlstmt=select * from blogtable where title=$a;
mysql_query($sqlstmt);
?>

I am not getting how to parse the results.php URL and retrieve the data dynamically.

Upvotes: 1

Views: 1584

Answers (1)

Subedi Kishor
Subedi Kishor

Reputation: 5986

In your results.php file instead of:

echo "<a href=\"".$row[$i]."\">".$row[$i]."</a>";

Use:

echo "<a href=\"parse.php?title=".$row[$i]."\">".$row[$i]."</a>";

to use the $_GET['title'] in your "parse.php".

This is one of the simplest way.

And in "parse.php" you have to change:

$sqlstmt=select * from blogtable where title=$a;

To:

$sqlstmt = "select * from blogtable where title='".$a."'";

Then you can manipulate your detail, after fetching it from database.

A suggestion:

Use mysqli or PDO instead of mysql.

Upvotes: 1

Related Questions