1
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 clicking on the link it only gives a refresh on the page, and does not direct to the page of the variable element in question (), which is added by DB mysql and exposed at home, but when clicking on the link I would like you to direct to the details page of this specific 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;
}
Okay, you directed me to another page, but error 404... I will try to explain better: It is a portal where register information of places and generates an id (post_id), and I want that when click on the title of each place (<span>), direct to a page with more details of this place, this page is ready and returning the information correctly, but the direction is not.
– Paulo Lima
Then the link was generated wrong, can show where the
[post_id]
? the file to redirect is theindex.php
? @Paulolima– rray
How can I show you more clearly my SQL? posting here has gotten extremely bad to view.. Thanks @rray
– Paulo Lima
Puts the php code that picks up the
post_id
, use the edit link in your question.– rray
see if this way the question became clearer (sorry ignorance in some questions, I am begginer in PHP).
– Paulo Lima
@Paulolima, no problem the query you make of php could add it in the question?
– rray
I believe that’s it, right?
– Paulo Lima
I changed the answer see if this is it @Paulolima.
– rray