...

View Full Version : Id receiver php



grebud
04-11-2012, 09:03 AM
Hello, I have this code that takes the id and send it to the showFullArticle.php:



$rs_result = mysql_query ($sql,$mysql_connection);
while ($row = mysql_fetch_assoc($rs_result)) {
?>
<div><a href="showFullArticle.php?id=<?php echo $row["id"];?>" target="Article">
<?php echo $row['title']; ?></a>
</div>
<div class="description"><?php echo $row["description"];?></div>
<?php
};
?>


I put that code in the showFullArticle.php file:



<?php
$id = $_GET["id"];
echo $id;
$mysql_connection = mysql_connect("host", "user", "password") or die ('Eror: ' .mysql_error());
$database_myconnection = "database";
$query = "select * from tablename where id = '".$id."'";
if (mysql_query($query)) {
echo "

'".$title."'

";
}
mysql_close($mysql_connection);
?>


but something is wrong. mysql data are not displayed. Can you please help me? Thank you in advance!

Nightfire
04-11-2012, 10:34 AM
You connect to the database there, but you're not selecting one.



$mysql_connection = mysql_connect("host", "user", "password") or die ('Eror: ' .mysql_error());
$database_myconnection = "database";
mysql_select_db($database_myconnection,$mysql_connection) or die('Failed to select database: 'mysql_error());


Also, echo out $query and see if that's getting filled with $id.

litebearer
04-11-2012, 10:53 AM
Aside...

1. you can simplify this


$query = "select * from tablename where id = '".$id."'";
to this

$query = "select * from tablename where id = '$id'";


2. Do you want to display the title and the article?


$query = "select * from tablename where id = '$id'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo $row['title'] . "<br>";
echo nl2br($row['article']);

grebud
04-11-2012, 02:12 PM
Great! It worked perfectly! Thank you very much Nightfire and litebearer!

grebud
04-11-2012, 08:49 PM
Great! It worked perfectly! Thank you very much Nightfire and litebearer!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum