The dynamic tabs are presenting the same records - php

I am trying to create a dynamic tab with PHP and MySQL using Bootstrap Framework for the movie website that I am creating. The movies will be segregated into Now Showing and Coming Soon.
Expected Result: The movies should be displayed based on the category (Now Showing or Coming Soon).
Actual Result: The dynamic tab is not working. Movies that are under “Coming Soon” are displayed in “Now Showing”. In addition, the website only displays 2nd record onwards (from the database). The first record for “Now Showing” which is theand “Coming Soon” are not displayed.
The same content is displayed regardless of clicking “Now Showing” or “Coming Soon” tab (The “Coming Soon” tab can only be seen if I hover which is another issue that I need to fix). The movie 'The cursed lesson' should be shown in Coming Soon. The first record for 'Now Showing' and 'Coming Soon' are not shown.
I truly appreciate your help and advice in fixing these problems. I have been trying to solve these for days but I just can't seem to figure it out.
Here are my codes:
<?php
$servername = 'localhost';
$username = 'root';
$password = '';
$dbname = 'movie';
$conn = new mysqli($servername, $username, $password, $dbname);
$tab_query = "SELECT * FROM category ORDER BY Category_ID";
$tab_result = mysqli_query($conn, $tab_query);
$tab_menu = '';
$tab_content = '';
$count = 0;
while ($row = mysqli_fetch_array($tab_result)) {
if ($count == 0) {
$tab_menu .= '<li class="nav-item"><a class="nav-link active" href="#' . $row["Category_ID"] . '" data-toggle="tab">' . $row["Category_Name"] . '</a></li>';
$tab_content .= '<div id="'.$row["Category_ID"].'" class="tab-pane fade in active"';
} else {
$tab_menu .= '<li class="nav-item"><a class="nav-link" href="#' . $row["Category_ID"] . '" data-toggle="tab">' . $row["Category_Name"] . '</a></li>';
$tab_content .= '<div id="'.$row["Category_ID"].'" class="tab-pane fade"';
}
$product_query = "SELECT * FROM movie WHERE Category_ID = '".$row["Category_ID"]."'";
$product_result = mysqli_query($conn, $product_query);
while($sub_row = mysqli_fetch_array($product_result))
{
$tab_content .= '
<div class="col-md-3" style="margin-bottom:36px;">
<img src="'.$sub_row["Image_URL"].'" class="img-responsive img-thumbnail" />
<h4>'.$sub_row["Title"].'</h4>
</div>
';
}
$tab_content .= '<div style="clear:both"></div></div>';
$count++;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Movie Testing Website</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="HandheldFriendly" content="true">
<!--Bootstrap CSS-->
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity=
"sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!--Custom CSS-->
<link rel="stylesheet" href="css/main.css">
<!--jQuery-->
<script defer
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
<!--Bootstrap JS-->
<script defer
src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.bundle.min.js"
integrity="sha384-6khuMg9gaYr5AxOqhkVIODVIvm9ynTT5J4V1cfthmT+emCG6yVmEZsRHdxlotUnm"
crossorigin="anonymous"></script>
<script defer src="js/main.js"></script>
</head>
<body>
<div class="container">
<ul class="nav nav-tabs">
<?php echo $tab_menu; ?>
</ul>
<div class="tab-content">
<?php echo $tab_content; ?>
</div>
</div>
</body>
</html>
Here are snippets of my database:
Movie Table:
Category Table:

I was found the problem in the view and not in data collection from db.
I modified the html structure based on this sample: https://bootsnipp.com/snippets/exE6D
Find out more about Bootstrap tab navigations: https://www.w3schools.com/bootstrap4/bootstrap_navs.asp
<?php
$servername = 'localhost';
$username = 'root';
$password = '';
$dbname = 'movie';
$conn = new mysqli($servername, $username, $password, $dbname);
$tab_query = "SELECT * FROM category ORDER BY Category_ID";
$tab_result = mysqli_query($conn, $tab_query);
$tab_menu = '';
$tab_content = '';
$count = 0;
while ($row = mysqli_fetch_array($tab_result)) {
if ($count == 0) {
$tab_menu .= '<a class="nav-item nav-link active" id="' . $row["Category_ID"] . '" data-toggle="tab" href="#nav-' . $row["Category_ID"] . '" role="tab" aria-controls="nav-' . $row["Category_ID"] . '" aria-selected="true">' . $row["Category_Name"] . '</a>';
$tab_content .= '<div class="tab-pane fade show active" id="nav-' . $row["Category_ID"] . '" role="tabpanel" aria-labelledby="nav-' . $row["Category_ID"] . '-tab">';
} else {
$tab_menu .= '<a class="nav-item nav-link" id="' . $row["Category_ID"] . '" data-toggle="tab" href="#nav-' . $row["Category_ID"] . '" role="tab" aria-controls="nav-' . $row["Category_ID"] . '" aria-selected="false">' . $row["Category_Name"] . '</a>';
$tab_content .= '<div class="tab-pane fade show" id="nav-' . $row["Category_ID"] . '" role="tabpanel" aria-labelledby="nav-' . $row["Category_ID"] . '-tab">';
}
$product_query = "SELECT * FROM movie WHERE Category_ID = '".$row["Category_ID"]."'";
$product_result = mysqli_query($conn, $product_query);
while($sub_row = mysqli_fetch_array($product_result))
{
$tab_content .= '
<div class="col-md-3" style="margin-bottom:36px;">
<img src="'.$sub_row["Image_URL"].'" class="img-responsive img-thumbnail" />
<h4>'.$sub_row["Title"].'</h4>
</div>';
}
$tab_content .= '<div style="clear:both"></div></div>';
$count++;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Movie Testing Website</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="HandheldFriendly" content="true">
<!--Bootstrap CSS-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!--Custom CSS-->
<link rel="stylesheet" href="css/main.css">
<!--jQuery-->
<script defer
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
<!--Bootstrap JS-->
<script defer src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.bundle.min.js"
integrity="sha384-6khuMg9gaYr5AxOqhkVIODVIvm9ynTT5J4V1cfthmT+emCG6yVmEZsRHdxlotUnm"
crossorigin="anonymous"></script>
<script defer src="js/main.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-12 ">
<nav>
<div class="nav nav-tabs nav-fill" id="nav-tab" role="tablist">
<?php echo $tab_menu; ?>
</div>
</nav>
<div class="tab-content py-3 px-3 px-sm-0" id="nav-tabContent">
<?php echo $tab_content; ?>
</div>
</div>
</div>
</div>
</body>
</html>

Related

Filling boostrap cards with data from a mySQL database

I am trying to fill bootstrap cards with data from a database.
I am very close.
I have the mainphp file called project.php
A file with a function called component to fill them, called component.php.
And a connectDB.php file, that connect the DB and extracts the information from a table.
I am aware this is alot of code so I highlighted 2 areas the problem is definitely in...Apologies if too much, I can remove the function if necessary as it works..
here is an extract from project.php
<?php
require_once('connect/connectDB.php');
require_once('component.php');
?>
<!doctype html>
<html lang="en">
<head>
<title>The Wild Music Shop</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!--Font awesome-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w==" crossorigin="anonymous" />
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<!-- i have no idea why it won't link -->
<!-- <link type="text/css" rel="stylesheet" href="myCSS/somecss.css"> -->
<link rel="stylesheet" href="myCSS/somecss.css">
</head>
<body>
<!-- the cards -->
<div class = "container" id="thecards">
<div class = "row text-center py-5">
//Definite problem here
<?php
$result = getData();
while ($row = mysqli_fetch_assoc($result)){
component($row['InstName'], $row['Price'], $row['ProductImg'], $row['description']);
}
?>
</div>
</div>
</html>
This component definitely works as I tested it
<?php
function component($pInstName, $pPrice, $pProductImg, $pdescription){
$element = "
<div class=\"col-md-3 col-sm-6 my-3 my-md-0\">
<form action=\"index.php\" method=\"post\">
<div class=\"card shadow\">
<div>
<img src=\ $pProductImg\" alt=\"Image1\" class=\"img-fluid card-img-top\">
</div>
<div class=\"card-body\">
<h5 class=\"card-title\">Our $pInstName</h5>
<h6>
<i class=\"fas fa-star\"></i>
<i class=\"fas fa-star\"></i>
<i class=\"fas fa-star\"></i>
<i class=\"fas fa-star\"></i>
<i class=\"far fa-star\"></i>
</h6>
<p class=\"card-text\">
$pdescription
</p>
<h5>
<span class=\"price\">$$pPrice</span>
</h5>
<button type=\"submit\" class=\"btn btn-warning my-3\" name=\"add\">Add to Cart </button>
</div>
</div>
</form>
</div>
";
echo $element;
}
?>
and finally here is the connectDB.php
<?php
//Create a database connection
$dbhost = "localhost";
$dbuser = "root";
$dbpassword = "";
$dbname = "g00398295";
$connection = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbname);
//Test if connection occoured
if(mysqli_connect_errno()){
die("DB connection failed: " .
mysqli_connect_error() .
" (" . mysqli_connect_errno() . ")"
);
}
if (!$connection)
{
die('Could not connect: ' . mysqli_error());
}
$sql = "select * from Instruments where itemno = 1; ";
$result = mysqli_query($connection,$sql);
$row=mysqli_fetch_assoc($result);
echo "Pls work".$row['InstName'];
mysqli_close($connection);
//get product from Database
//Definite problem here
function getData(){
$sql = "select * from $this->tablename";
$result = mysqli_query($this->con,$sql);
if(mysqli_num_rows($result) > 0){
return $result;
}
}
?>
I am awar the problem is somewhere in the connection step. I am very new to php in general and have been at this very long, I would appreciate help!
You have a function getData() that has "$this->table". Dont copy paste the codes without understanding what it does.
Clean up your connectDB.php:
<?php
//Create a database connection
$dbhost = "localhost";
$dbuser = "root";
$dbpassword = "";
$dbname = "g00398295";
$connection = mysqli_connect($dbhost, $dbuser, $dbpassword, $dbname);
//Test if connection occoured
if(mysqli_connect_errno()){
die("DB connection failed: " .
mysqli_connect_error() .
" (" . mysqli_connect_errno() . ")"
);
}
?>
In project.php:
<div class = "row text-center py-5">
//Definite problem here
<?php
$sql = "select * from Instruments where itemno = 1; ";
$result = mysqli_query($connection,$sql);
while ($row = mysqli_fetch_assoc($result)){
component($row['InstName'], $row['Price'], $row['ProductImg'], $row['description']);
}
?>
</div>

Why are the tabs squeezed together and does not change colour?

I am trying to create a dynamic tab with PHP and MySQL using the Bootstrap Framework.
I am wondering why the dynamic tab is squeezed together. In addition, when I click the tab, it does not change color to show that I clicked that tab.
Actual Result:
The tabs 'Now Showing' and 'Coming Soon' are squeezed together. The selected tab does not change color even when it is clicked.
Expected Result:
The tabs 'Now Showing' and 'Coming Soon' should not be squeezed together. When either of the tab is clicked, that particular tab should change color.
How do I solve this problem such that the tabs will not be squeezed together AND the tabs will change color when it is clicked (to differentiate it from the tabs that are not clicked ---> as shown in the Expected Result)
Here are my codes:
<?php
$servername = 'localhost';
$username = 'root';
$password = '';
$dbname = 'movie';
$conn = new mysqli($servername, $username, $password, $dbname);
$tab_query = "SELECT * FROM category ORDER BY Category_ID";
$tab_result = mysqli_query($conn, $tab_query);
$tab_menu = '';
$count = 0;
while ($row = mysqli_fetch_array($tab_result)) {
if ($count == 0) {
$tab_menu .= '<li class="active">' . $row["Category_Name"] . '</li>';
} else {
$tab_menu .= '<li>' . $row["Category_Name"] . '</li>';
}
$count++;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Testing Movie Website</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="HandheldFriendly" content="true">
<!--Bootstrap CSS-->
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity=
"sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!--Custom CSS-->
<link rel="stylesheet" href="css/main.css">
<!--jQuery-->
<script defer
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
<!--Bootstrap JS-->
<script defer
src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.bundle.min.js"
integrity="sha384-6khuMg9gaYr5AxOqhkVIODVIvm9ynTT5J4V1cfthmT+emCG6yVmEZsRHdxlotUnm"
crossorigin="anonymous"></script>
<script defer src="js/main.js"></script>
</head>
<body>
<?php include "nav.inc.php"; ?>
<div class="container">
<br>
<ul class="nav nav-tabs">
<?php echo $tab_menu; ?>
</ul>
</div>
</body>
</html>
I followed this video: https://www.youtube.com/watch?v=qkmqncXTiLU
The structure and classes for .tabs is:
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
</ul>
Looks like you missed some classes.
The active class needs to go to <a> tag and the <li> tag needs a class nav-item. This will make it work. So it should essentially be:
<?php
while ($row = mysqli_fetch_array($tab_result)) {
if ($count == 0) {
$tab_menu .= '<li class="nav-item"><a class="nav-link active" href="#' . $row["Category_ID"] . '" data-toggle="tab">' . $row["Category_Name"] . '</a></li>';
} else {
$tab_menu .= '<li class="nav-item"><a class="nav-link" href="#' . $row["Category_ID"] . '" data-toggle="tab">' . $row["Category_Name"] . '</a></li>';
}
$count++;
}

Use database information as dropdownlist option

I'm making a website for school about MLB with a database. But now I want information in the database as an option in a dropdownlist. This is my HTML Code:
<!DOCTYPE html>
<html>
<head>
<link rel="icon" type="image/png" href="./images/favicon-32x32.png"
sizes="32x32" />
<link rel="icon" type="image/png" href="./images/favicon-16x16.png"
sizes="16x16" />
<title>MLB: Major League Baseball</title>
<link href="css folder/MLBstylesheet.css" rel="stylesheet"
type="text/css"/>
</head>
<body>
<div id="container">
<div id="titel">
<img class="MLBTitel" src="./images/MLBtitel.jpg" alt="MLBTitel" >
<div id="titeltekst">
MAJOR LEAGUE BASEBALL
<br>
</div>
<nav>
<ul>
<li><a class= "menu" href="index.html">Home</a></li>
<li><a class= "menu" href="spelers.php">Spelers</a></li>
<li><a id = "active" class= "menu" href="teams.php">Teams</a></li>
<li><a class= "menu" href="wedstrijden.html">Wedstrijden</a></li>
<li><a class= "menu" href="contact.html">Contact</a></li>
</ul>
</nav>
<br><br>
</div>
<div id="teamtabel">
<?php
$servername = "localhost";
$username = "id1419279_root";
$password = "*******";
$dbname = "id1419279_mlb";
// Create connection
$conn = new mysqli($localhost, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM teams";
$result = $conn->query($sql);
echo "<select name='naamteam'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['teamnaam'] ."'>" . $row['teamnaam'] ."
</option>";
}
echo "</select>";
?>
</div>
</div>
</body>
</html>
The options would be the teamnames, but it seems like my dropdownlist is still empty: picture of the dropdownlist on the website
This is what my database looks like:
picture of my database
I hope someone could help me and I would really appreciate it.
<!DOCTYPE html>
<html>
<head>
<link rel="icon" type="image/png" href="./images/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./images/favicon-16x16.png" sizes="16x16" />
<title>MLB: Major League Baseball</title>
<link href="css folder/MLBstylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="container">
<div id="titel">
<img class="MLBTitel" src="./images/MLBtitel.jpg" alt="MLBTitel" >
<div id="titeltekst">
MAJOR LEAGUE BASEBALL
<br>
</div>
<nav>
<ul>
<li><a class= "menu" href="index.html">Home</a></li>
<li><a class= "menu" href="spelers.php">Spelers</a></li>
<li><a id = "active" class= "menu" href="teams.php">Teams</a></li>
<li><a class= "menu" href="wedstrijden.html">Wedstrijden</a></li>
<li><a class= "menu" href="contact.html">Contact</a></li>
</ul>
</nav>
<br><br>
</div>
<div id="teamtabel">
<?php
$servername = "localhost";
$username = "id1419279_root";
$password = "*******";
$dbname = "id1419279_mlb";
// Create connection
$conn = new mysqli($localhost, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM teams";
$result = $conn->query($sql);
$dropdownlist = '';
while($row = mysqli_fetch_array($result)) {
$teamnaam = $row['teamnaam'];
$dropdownlist .="<option value='" . $teamnaam . "'>" . $teamnaam . "</option>";
}
if(isset($dropdownlist)){
echo "<select name='naamteam'>";
echo $dropdownlist;
echo "</select>";
}
?>
</div>
</div>
</body>
</html>

Php code not displaying the data right from database

I'm working on a movie database project and I got my database the way it needs to be, but having issues with the front-end part of it. I finally got it to show all the information and have it be clickable, but I'm pretty sure this isn't the way to do it.
I'm having trouble displaying the genres. I either can groupconcat and display all of them like that, but then I can't have them be links or I could do them individual and have the links, but not get them all. I finally got them all, but then when I try it on the phone or tablet I only see the last genre and not the others. So I did another database and pull request to get all the data over again, but I'm pretty sure that isn't right.
<?php
require '../database.php';
$Code = null;
if ( !empty($_GET['Code'])) {
$Code = $_REQUEST['Code'];
}
if ( null==$Code ) {
header("Location: index.php");
} else {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT Movies.Code, Title, Plot, Movies.Type, Movies.Category, Image, Score, Rated, Alt, Status, YearReleased, Duration, SUBSTRING(Duration, 1, CHAR_LENGTH(Duration) - 3) AS Duration2, TotalEps, Types.code as tcode, Types.Type as ttype, Categories.Code as ccode, Categories.Category as ca, Ratings.Code as rc, Ratings.Rating as rr, Genre, GenreCode FROM Movies, Types, Categories, Ratings, MovieGenres, Genres WHERE Movies.Type=Types.Code AND Movies.Rated=Ratings.Code AND Movies.Category=Categories.Code AND Movies.Code=MovieGenres.MovieCode AND MovieGenres.GenreCode=Genres.Code AND Movies.Code = ?";
$q = $pdo->prepare($sql);
$q->execute(array($Code));
$data = $q->fetch(PDO::FETCH_ASSOC);
Database::disconnect();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="description" content="">
<meta name="author" content="">
<title>MovieDB - <?php echo $data['Title'];?></title>
<!-- Bootstrap Core CSS -->
<link href="../css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="../css/modern-business.css" rel="stylesheet">
<link href="../css/custom.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="../font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Navigation -->
<?php include '../include/nav.php';?>
<!-- Page Content -->
<div class="container">
<!-- Page Heading/Breadcrumbs -->
<div class="row">
<div class="col-lg-12">
<h2 class="page-header"><?php echo $data['Title'];?>
</h2>
</div>
</div>
<!-- /.row -->
<!-- Portfolio Item Row -->
<div class="row">
<div class="col-md-4">
<img class="img-responsive" src="../Images/<?php echo $data['Image'];?>" alt="">
</div>
<div class="col-md-8 hidden-sm hidden-xs">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#Plot">Plot</a></li>
<li><a data-toggle="tab" href="#Details">Details</a></li>
</ul>
<div class="tab-content">
<div id="Plot" class="tab-pane fade in active">
<p><?php echo $data['Plot'];?></p>
</div>
<div id="Details" class="tab-pane fade">
<?php
echo'<li>Alternative Title: '. $data['Alt'] .'</li>';
echo'<li>Type: '. $data['ttype'] .'</li>';
echo'<li>Rated: '. $data['rr'] .'</li>';
echo'<li>Episodes: '. $data['TotalEps'] .'</li>';
echo'<li>Duration: '. $data['Duration2'] .'</li>';
echo'<li>Genre: ';
echo''. $data['Genre'] .'';
foreach($q as $data){
echo", ";
echo''. $data['Genre'] .'';
}
echo '</li>';
echo'<li>Status: '. $data['Status'] .'</li>';
echo'<li>Category: '. $data['ca'] .'</li>';
echo'<li>Year Released: '. $data['YearReleased'] .'</li>';
echo'<li>Score: '. $data['Score'] .'</li>';
?>
</div>
</div>
</div>
<div class="col-md-4 hidden-md hidden=-lg">
<h3>Plot</h3>
<p><?php echo $data['Plot'];?></p>
</div>
<div class="col-md-4 hidden-md hidden=-lg ">
<h3>Details</h3>
<ul>
<?php
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT Movies.Code, Title, Plot, Movies.Type, Movies.Category, Image, Score, Rated, Alt, Status, YearReleased, Duration, SUBSTRING(Duration, 1, CHAR_LENGTH(Duration) - 3) AS Duration2, TotalEps, Types.code as tcode, Types.Type as ttype, Categories.Code as ccode, Categories.Category as ca, Ratings.Code as rc, Ratings.Rating as rr, Genre, GenreCode FROM Movies, Types, Categories, Ratings, MovieGenres, Genres WHERE Movies.Type=Types.Code AND Movies.Rated=Ratings.Code AND Movies.Category=Categories.Code AND Movies.Code=MovieGenres.MovieCode AND MovieGenres.GenreCode=Genres.Code AND Movies.Code = ?";
$q = $pdo->prepare($sql);
$q->execute(array($Code));
$data = $q->fetch(PDO::FETCH_ASSOC);
Database::disconnect();
echo'<li>Alternative Title: '. $data['Alt'] .'</li>';
echo'<li>Type: '. $data['ttype'] .'</li>';
echo'<li>Rated: '. $data['rr'] .'</li>';
echo'<li>Episodes: '. $data['TotalEps'] .'</li>';
echo'<li>Duration: '. $data['Duration2'] .'</li>';
echo'<li>Genre: ';
echo''. $data['Genre'] .'';
foreach($q as $data){
echo", ";
echo''. $data['Genre'] .'';
}
echo '</li>';
echo'<li>Status: '. $data['Status'] .'</li>';
echo'<li>Category: '. $data['ca'] .'</li>';
echo'<li>Year Released: '. $data['YearReleased'] .'</li>';
echo'<li>Score: '. $data['Score'] .'</li>';
?>
</ul>
</div>
</div>
<!-- /.row -->
<hr>
<!-- Footer -->
<?php include '../include/footer.php';?>
<!-- /.container -->
<!-- jQuery -->
<script src="../js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="../js/bootstrap.min.js"></script>
</body>
</html>
formated:
SELECT Movies.Code, Title, Plot, Movies.Type, Movies.Category, Image, Score, Rated, Alt, Status, YearReleased, Duration, SUBSTRING(Duration, 1, CHAR_LENGTH(Duration) - 3) AS Duration2, TotalEps, Types.code as tcode, Types.Type as ttype, Categories.Code as ccode, Categories.Category as ca, Ratings.Code as rc, Ratings.Rating as rr, Genre, GenreCode
FROM Movies, Types, Categories, Ratings, MovieGenres, Genres
WHERE Movies.Type=Types.Code
AND Movies.Rated=Ratings.Code
AND Movies.Category=Categories.Code
AND Movies.Code=MovieGenres.MovieCode
AND MovieGenres.GenreCode=Genres.Code
AND Movies.Code = ?;
SELECT Genre, GenreCode
FROM MovieGenres, Genres
WHERE MovieGenres.GenreCode=Genres.Code
AND MovieCode = ?;
You aren't looping over the rows returned by the query.
Have a look at this answer https://stackoverflow.com/a/160365/6632744
You'll want something like this:
while ($row = $q->fetch(PDO::FETCH_ASSOC)) {
echo''. $row['Genre'] .'';
}
And you'll want to strip away your initial fetch.
$data = $q->fetch(PDO::FETCH_ASSOC); // remove this line

Display <ul> from database

I'm making a script that i use my database to show the menu of a page. But i ran into a problem...
The script on my website. : Click here
Problem
So i have this code
UPDATED CODE AND ADDED LINK
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Heroic Features - Start Bootstrap Template</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/heroic-features.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Start Bootstrap</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<?php
$db = new mysqli('xxxxxxxxxxx');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
if($_GET['action'] == '')
{
$sql = "SELECT * FROM li_psp";
if(!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
while($row = $result->fetch_assoc()){
echo " <li>
<a href='{$row['li_href']}'>{$row['li_label']}</a>
</li>";
}
}
?>
<?php
$db = new mysqli('xxxxxxxxxxx');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
if($_GET['action'] == '')
{
$sql = "SELECT * FROM ul_psp";
error_reporting(E_ALL);
if(!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
while($row = $result->fetch_assoc()){
echo "<li class='dropdown'>
<a href='#' class='dropdown-toggle' data-toggle='dropdown'>{$row['ul_name']} <b class='caret'></b></a>
<ul class='dropdown-menu'>";
if($_GET['action'] == '')
{
$sql = "SELECT * FROM ul_data_psp WHERE belong_to = {$row['ul_name']}";
if(!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
while($row = $result->fetch_assoc()){
echo " <li>
<a href='{$row['ul_data_href']}'>{$row['ul_data_label']}</a>
</li>";
echo "</ul>
</li>";
}
}
}
}
?>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
But for some reason it does not work. I get this error: Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /home/u799303375/public_html/beta/include/menu.php on line 98
What have i tried?
I tried changing all the " to ' but it didn't work, i need help fixing this code, if you have any other things i can do better please tell it! Thanks!
You have malformed quotationmarks. Put variables not directly into strings, concat them with a .:
echo '<li><a href=' . $row['ul_data_href'] . '>' . $row['ul_data_label'] . '</a></li>'

Categories