I'm trying this way:
<?php
$link = "'index.php?id=echo ['post_id']; "
?>
<?php
while ($row = mysql_fetch_array($result)) {
echo "<span class='survey-name'><a href='$link'>". $row['title'] ."</span>";
?>
But when you click on the link it just gives a refresh on the page, and does not point to the page of the variable element in question (), which is added by the mysql DB and exposed in the home, but clicking on the link would like it to be directed to the details page of this particular element that is already working, just not directing correctly.
SQL:
CREATE TABLE IF NOT EXISTS 'categories' (
'id' int(3) NOT NULL,
'name' text COLLATE utf8_bin NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE TABLE IF NOT EXISTS 'posts' (
'id' int(6) NOT NULL,
'cat_id' int(3) NOT NULL,
'title' varchar(255) COLLATE utf8_bin NOT NULL,
'endereco' text COLLATE utf8_bin NOT NULL,
'cidade' text COLLATE utf8_bin NOT NULL,
'email' text COLLATE utf8_bin NOT NULL,
'telefone' text COLLATE utf8_bin NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
function get_posts($id = null, $cat_id = null){
$posts = array();
$query = "SELECT 'posts'.'id' AS 'post_id' , 'categories'.'id' AS 'category_id', 'title','endereco','cidade','email','telefone','categories'.'name' FROM 'posts' INNER JOIN 'categories' ON 'categories'.'id' = 'posts'.'cat_id' " ;
if(isset($id)){
$id = (int)$id;
$query .= " WHERE 'posts'.'id' = {$id} ";
}
if(isset($cat_id)){
$cat_id = (int)$cat_id;
$query .= " WHERE 'cat_id' = {$cat_id} ";
}
$query .= "ORDER BY 'post_id' DESC";
$query = mysql_query($query);
while($row = mysql_fetch_assoc($query)){
$posts[] = $row;
}
return $posts;
}