Et projekt har mange skydere, til dette bør du have to tabeller projekter og projektskydere med relation.
projekttabel:
CREATE TABLE `projects` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`project_name` varchar(50) NOT NULL
)
projektskydere:
CREATE TABLE `projectsliders` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`solution` varchar(50) NOT NULL,
`image` text NOT NULL,
`alt` text NOT NULL,
`project_id` int(11),
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1
hente projectSliders til et projekt, Master side - projectSlider.php
Den bedste måde at hente projektskydere til et projekt på er at bruge OOP, du kan kalde en metode og sende projekt-id og metode skulle returnere dig en matrix med projektskydere til dette projekt, men jeg forbedrer din kode.
error_reporting(E_ALL);
ini_set('display_errors', 1);
$servername = 'localhost';
$username = 'root';
$password = '';
try {
$con = new PDO('mysql:host='.$servername.';dbname=mb', $username,
$password);
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//$page = mysql_real_escape_string($page);
//SQL Call
$sql_project = "SELECT * FROM projectsliders ps inner join projects p
on p.id = ps.project_id
WHERE p.project_name = '. $project_page .'";
if ($project_stmt = $con->prepare($sql_project)) {
$project_stmt->execute();
$count = project_stmt->rowCount();
if( $count != 0 ){
$project_rows = $project_stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($project_rows as $project_row) {
$project_solution = $project_row['solution'];
$project_img = $project_row['image'];
$project_alt = $project_row['alt'];
$project_img = '<img class="home-comment-profile-pic" src=" '.
$project_img .'" alt="' . $project_alt .'">';
echo '<section id="solProj">';
echo '<div class="projSlide">';
echo $project_img;
echo '</div>';
echo '</div>';
}
}else{
echo 'No projects found.';
}
}
}
catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
Individuelle sider:
error_reporting(E_ALL);
ini_set('display_errors', 1);
$project_page = "enclosures";
include_once("projectSlider.php");
Jeg håber, at dette kan hjælpe dig med at nyde kodning.