I have a working php/mysql database to show/search my films collection.
When I call for a php page with all the films of an actor I see, as actor, only that actor, and not the other ones.
I’d like to see also the others, as is in the main film page.
This is the code:
the main page
<?php
$sql = "SELECT
f.mov_id
, f.titolo
, f.titolo_italiano
, f.imagelink
, f.regia
, f.regia_nome
, f.data
, f.contenuti
, f.genere
, f.keywords
, c.act_id
, c.role
, c.mov_reg_id
, e.id AS 'act_id'
, e.evento AS 'cognome'
, e.`evento.spec` AS 'nome'
, e.data AS 'act_data'
, e.data_fine AS 'act_data_morte'
, e.imagelink AS 'act_imagelink'
FROM `films__olon` f
LEFT JOIN `films__cast` c
ON c.mov_id = f.mov_id
LEFT JOIN `eventi` e
ON e.id = c.act_id
LEFT JOIN `films__registi` r
ON r.id = c.mov_reg_id
WHERE f.genere LIKE '%$genere%'
ORDER by f.data";
$data=array();
$query = $pdo->prepare($sql);
$query->execute();
while($row = $query->fetch(PDO::FETCH_ASSOC)){
$data[$row['mov_id']]['movie']['mov_id'] = $row['mov_id'];
$data[$row['mov_id']]['movie']['titolo'] = $row['titolo'];
$data[$row['mov_id']]['movie']['titolo_italiano'] = $row['titolo_italiano'];
$data[$row['mov_id']]['movie']['imagelink'] = $row['imagelink'];
$data[$row['mov_id']]['movie']['regia'] = $row['regia'];
$data[$row['mov_id']]['movie']['regia_nome'] = $row['regia_nome'];
$data[$row['mov_id']]['movie']['reg_id'] = $row['mov_reg_id'];
$data[$row['mov_id']]['movie']['data'] = $row['data'];
$data[$row['mov_id']]['movie']['contenuti'] = $row['contenuti'];
$data[$row['mov_id']]['movie']['keywords'] = $row['keywords'];
$data[$row['mov_id']]['genere'][$row['genere']] = $row['genere'];
if(!empty($row['act_id'])):
$data[$row['mov_id']]['cast'][$row['act_id']]['act_id'] = $row['act_id'];
$data[$row['mov_id']]['cast'][$row['act_id']]['role'] = $row['role'];
$data[$row['mov_id']]['cast'][$row['act_id']]['cognome'] = $row['cognome'];
$data[$row['mov_id']]['cast'][$row['act_id']]['nome'] = $row['nome'];
$data[$row['mov_id']]['cast'][$row['act_id']]['data'] = $row['act_data'];
$data[$row['mov_id']]['cast'][$row['act_id']]['data_fine'] = $row['act_data_morte'];
$data[$row['mov_id']]['cast'][$row['act_id']]['imagelink'] = $row['act_imagelink'];
$data[$row['mov_id']]['cast'][$row['act_id']]['mov_reg_id'] = $row['mov_reg_id'];
endif;
}
?>
<?php
if(!empty($data)):
foreach($data as $mov_id => $arr):
// People details
if(!empty($_GET['people']) && array_key_exists($_GET['people'],$data[$mov_id]['cast'])):
echo '<h2>'.$data[$mov_id]['cast'][$_GET['people']]['nome'].' '.$data[$mov_id]['cast'][$_GET['people']]['cognome'].'<br />'."\r";
if(!empty($data[$mov_id]['cast'][$_GET['people']]['imagelink'])):
echo '<img src="'.$data[$mov_id]['cast'][$_GET['people']]['imagelink'].'" height="200px" class="fr">'."\r";
endif;
echo '</h2><blockquote style="width:50%;">'.$data[$mov_id]['cast'][$_GET['people']]['data'].'<br /><a href="film.new.php">Close</a></blockquote>'."\r";
endif;
//Basic display
echo '<h2><span class="tooltip"><span class="tooltiptext">'.$data[$mov_id]['movie']['titolo_italiano'].' - '.$data[$mov_id]['movie']['mov_id'].'</span>'.$data[$mov_id]['movie']['titolo'].'</span>'."\r";
if(!empty($data[$mov_id]['movie']['imagelink'])):
echo '<img src="'.$data[$mov_id]['movie']['imagelink'].'" height="200px" class="fr" alt="'.$data[$mov_id]['movie']['titolo'].'" />'."\r";
endif;
echo '</h2>
<p>data: <b>'.$data[$mov_id]['movie']['data'].'</b> - regista: '.$data[$mov_id]['movie']['regia_nome'].' <span class="tooltip"><span class="tooltiptext">'.$data[$mov_id]['movie']['reg_id'].'</span> <a href="hashtag-registi.php?tag='.$data[$mov_id]['movie']['regia'].'&mode=regia">'.$data[$mov_id]['movie']['regia'].'</a></span></p>
<blockquote><p>'.$data[$mov_id]['movie']['contenuti'].'</p></blockquote>'."\n";
//attori
if(!empty($data[$mov_id]['cast'])):
echo '<p class="cast"><b>attori</b>: ';
foreach($data[$mov_id]['cast'] as $actor_id => $cast):
echo '<span class="tooltip">
<span class="tooltiptext"><img src="' .$cast['imagelink'].'" alt="'.$cast['cognome'].'" />
(' .$cast['data'].' / ' .$cast['data_fine'].')</span>
<a href="hashtag-actors.php?tag='.$cast['act_id'].'&mode=act">'.$cast['nome'].' '.$cast['cognome']. '</a></span>
<span class="as">(as ' .$cast['role']. ')</span> ';
endforeach;
echo '</p>'."\n";
endif;
//keywords
$keywords = $data[$mov_id]['movie']['keywords'];
if(!empty($data[$mov_id]['movie']['keywords'])):
echo " <p class=\"keywords\"><b>temi</b>:";
foreach (explode(',', $keywords) as $key):
echo "<span><a href=\"hashtag-keywords.php?tag=$key&mode=libere\">{$key}</a></span>";
endforeach;
echo "</p>";
endif;
endforeach;
endif;
?>
for hashtags
<?php
//hashtag.php
if(isset($_GET["tag"]))
{
$_GET['tag'] = (!empty($_GET['tag']) ? preg_replace('/(?<!\S)#([0-9a-zA-Z]+)/', '', $_GET['tag']) : '');
$tag = preg_replace('/(?<!\S)#([0-9a-zA-Z]+)/', '', $_GET['tag']);
$sql = "SELECT
CONCAT(se.evento,' ',se.`evento.spec`) as '$keyspec'
, f.mov_id
, f.titolo
, f.titolo_italiano
, f.imagelink
, f.regia
, f.regia_nome
, f.data
, f.contenuti
, f.genere
, f.keywords
, c.act_id
, c.role
, e.id AS 'act_id'
, e.evento AS 'cognome'
, e.`evento.spec` AS 'nome'
, e.data AS 'act_data'
, e.data_fine AS 'act_data_morte'
, e.imagelink AS 'act_imagelink'
FROM `films__cast` sc
LEFT JOIN `eventi` se
ON se.id = sc.act_id
LEFT JOIN `films__cast` c
ON c.mov_id = sc.mov_id
LEFT JOIN `eventi` e
ON e.id = c.act_id
LEFT JOIN `films__olon` f
ON f.mov_id = c.mov_id
WHERE $specifico LIKE '%".$tag."%'
ORDER by f.data";
$data=array();
$query = $pdo->prepare($sql);
$query->execute();
while($row = $query->fetch(PDO::FETCH_ASSOC)){
$data[$row['mov_id']]['movie']['mov_id'] = $row['mov_id'];
$data[$row['mov_id']]['movie']['titolo'] = $row['titolo'];
$data[$row['mov_id']]['movie']['titolo_italiano'] = $row['titolo_italiano'];
$data[$row['mov_id']]['movie']['imagelink'] = $row['imagelink'];
$data[$row['mov_id']]['movie']['regia'] = $row['regia'];
$data[$row['mov_id']]['movie']['regia_nome'] = $row['regia_nome'];
$data[$row['mov_id']]['movie']['data'] = $row['data'];
$data[$row['mov_id']]['movie']['contenuti'] = $row['contenuti'];
$data[$row['mov_id']]['movie']['keywords'] = $row['keywords'];
$data[$row['mov_id']]['genere'][$row['genere']] = $row['genere'];
$actor = "$row[nome] $row[cognome]";
$libere = $row['keywords'];
$regia = "$row[regia_nome] $row[regia]";
if(!empty($row['act_id'])):
$data[$row['mov_id']]['cast'][$row['act_id']]['act_id'] = $row['act_id'];
$data[$row['mov_id']]['cast'][$row['act_id']]['role'] = $row['role'];
$data[$row['mov_id']]['cast'][$row['act_id']]['cognome'] = $row['cognome'];
$data[$row['mov_id']]['cast'][$row['act_id']]['nome'] = $row['nome'];
$data[$row['mov_id']]['cast'][$row['act_id']]['data'] = $row['act_data'];
$data[$row['mov_id']]['cast'][$row['act_id']]['data_fine'] = $row['act_data_morte'];
$data[$row['mov_id']]['cast'][$row['act_id']]['imagelink'] = $row['act_imagelink'];
endif;
}
$mode = (!empty($_GET['mode']) ? $_GET['mode'] : '');
switch ($mode) {
case "act":
$title = $actor;
break;
case "libere":
//$title = $libere;
$title = $tag;
break;
case "regia":
$title = $regia;
break;
default:
//$title = $regia;
$title = "Mode not defined";
//$title = $tag;
}
include "$root/intell/header-intell.inc";
?>
<?php
if(!empty($data)):
foreach($data as $mov_id => $arr):
// People details
if(!empty($_GET['people']) && array_key_exists($_GET['people'],$data[$mov_id]['cast'])):
echo '<h2>'.$data[$mov_id]['cast'][$_GET['people']]['nome'].' '.$data[$mov_id]['cast'][$_GET['people']]['cognome'].'<br />'."\r";
if(!empty($data[$mov_id]['cast'][$_GET['people']]['imagelink'])):
echo '<img src="'.$data[$mov_id]['cast'][$_GET['people']]['imagelink'].'" height="200px" class="fr">'."\r";
endif;
echo '</h2><blockquote style="width:50%;">'.$data[$mov_id]['cast'][$_GET['people']]['data'].'<br /><a href="film.new.php">Close</a></blockquote>'."\r";
endif;
//Basic display
echo '<h2>'.$data[$mov_id]['movie']['titolo'].'<br />'."\r";
if(!empty($data[$mov_id]['movie']['imagelink'])):
echo '<img src="'.$data[$mov_id]['movie']['imagelink'].'" height="200px" class="fr" alt="'.$data[$mov_id]['movie']['titolo'].'" />'."\r";
endif;
echo '</h2>
<p>data: <b>'.$data[$mov_id]['movie']['data'].'</b> - regista: '.$data[$mov_id]['movie']['regia_nome'].' <a href="hashtag-registi.php?tag='.$data[$mov_id]['movie']['regia'].'&mode=regia">'.$data[$mov_id]['movie']['regia'].'</a></p>
<blockquote><p>'.$data[$mov_id]['movie']['contenuti'].'</p></blockquote>'."\n";
//attori
if(!empty($data[$mov_id]['cast'])):
echo '<p class="cast"><b>attori</b>: ';
foreach($data[$mov_id]['cast'] as $actor_id => $cast):
echo '<span class="tooltip">
<span class="tooltiptext"><img src="' .$cast['imagelink'].'" alt="'.$cast['cognome'].'" />
(' .$cast['data'].' / ' .$cast['data_fine'].')</span>
<a href="hashtag-actors.php?tag='.$cast['act_id'].'&mode=act">'.$cast['nome'].' '.$cast['cognome']. '</a></span>
<span class="as">(as ' .$cast['role']. ')</span> ';
endforeach;
echo '</p>'."\n";
endif;
//keywords
$keywords = $data[$mov_id]['movie']['keywords'];
if(!empty($data[$mov_id]['movie']['keywords'])):
echo " <p class=\"keywords\"><b>temi</b>:";
foreach (explode(',', $keywords) as $key):
echo "<span><a href=\"hashtag-keywords.php?tag=$key&mode=libere\">{$key}</a></span>";
endforeach;
echo "</p>";
endif;
endforeach;
endif;
}
?>
When I click on a keyword or a director (“regia”) I see all the actors of a film. But when I click an actor aI see a list of the films with only that actor.
I add an html output:
<h2>Star Wars.4 A new hope<br />
<img src="my-image.jpg" height="200px" class="fr" alt="Star Wars.4 A new hope" />
</h2>
<p>data: <b>1977</b> - regista: George <a href="hashtag-registi.php?tag=Lucas&mode=regia">Lucas</a></p>
<blockquote><p>[...]</p></blockquote>
<p class="cast"><b>attori</b>: <span class="tooltip">
<span class="tooltiptext"><img src="http://localhost/img/ritratti/Hamill, Mark.jpg" alt="Hamill" />
(1951 / )</span>
<a href="hashtag-actors.php?tag=1377&mode=act">Mark Hamill</a></span>
<span class="as">(as Luke Skywalker)</span> </p>
<p class="keywords"><b>temi</b>:<span><a href="hashtag-keywords.php?tag=lotta bene/male&mode=libere">lotta bene/male</a></span><span><a href="hashtag-keywords.php?tag=star wars&mode=libere">star wars</a></span></p>
the same film, in the main page
(I add only the most important selection: the actors)
<p class="cast"><b>attori</b>: <span class="tooltip">
<span class="tooltiptext"><img src="http://localhost/img/ritratti/Hamill, Mark.jpg" alt="Hamill" />
(1951 / )</span>
<a href="hashtag-actors.php?tag=1377&mode=act">Mark Hamill</a></span>
<span class="as">(as Luke Skywalker)</span> <span class="tooltip">
<span class="tooltiptext"><img src="http://localhost/img/ritratti/Ford, Harrison.jpg" alt="Ford" />
(1942 / )</span>
<a href="hashtag-actors.php?tag=1344&mode=act">Harrison Ford</a></span>
<span class="as">(as Ian Solo)</span> </p>
Thank you!