Im trying to add a form so I can select a date range then resubmit the form so I can have rows only from a specific date range listed in the table, but I cant get it to work very well. Whats wrong in the code ? (php newbie alert) (UPDATED)
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="HandheldFriendly" content="true">
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>EBS Service Skjema</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="print.css" rel="stylesheet" media="print" type="text/css" />
</head>
<body>
<?php
include 'connection.php';
// Check if session is not registered, redirect back to main page.
// Put this code in first line of web page.
session_start();
if (!isset($_COOKIE["user"])) {
header("location:login.php");
}
echo "<div class=\"blackbar\">Sjåfør:" .$_COOKIE["user"]."</div>";
$dbx = $_POST["databases"];
$con=mysqli_connect("$host", "$username", "$password","$db_name")or die("cannot connect");
?>
<div class="bluebox"><form action="data.php" method="post">
<h2 align="center">Utskrift av logger</h2>
<label>Velg type logg du vil skrive ut:</label><br />
<select name="databases">
<option value="trallevask">Trallevask</option>
<option value="bilvask">Bilvask</option>
<option value="maintenance">Vedlikehold</option>
<option value="diesel">Diesel Stats</option>
<option value="workhours">Arbeidstid</option>
</select>
<input type="date" name="df" /><input type="date" name="dt" />
<input type="submit" value="Submit"><input type="button" value="Tilbake" onClick="parent.location='index.php'" />
<input type="button" value="Skriv ut" onclick="window.print();return false;" />
</form></div>
<?php
//Row Colors setting
$color1 = "#E1EEf4";
$color2 = "#FFFFFF";
$row_count = 0;
echo "<div class=\"datagrid\"><table width=\"100%\" cellspacing=\"0\" cellpadding=\"5\" border=\"0\">";
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if ($dbx == "trallevask") {
//$result = mysqli_query($con,"SELECT trallevask.regnr, trallevask.date, trallevask.type, equipment.eqname AS vaske_type FROM trallevask JOIN equipment ON equipment.eqid = trallevask.type WHERE userid = ". $_COOKIE['userid']);
$result = mysqli_query($con, "SELECT trallevask.regnr, trallevask.date,
trallevask.type, equipment.eqname AS vaske_type
FROM trallevask JOIN equipment ON equipment.eqid = trallevask.type
WHERE userid = ". $_COOKIE['userid'] . " AND trallevask.date
BETWEEN " . $_POST['df'] . " AND " . $_POST['dt']);
echo "<thead><tr><th>Dato</th><th>Tralle nr.</th><th>Vaskemiddel</th><th>Utført av</th></tr></thead><tbody>";
while($row = mysqli_fetch_array($result))
{
$row_color = ($row_count % 2) ? $color1 : $color2;
echo "<tr bgcolor=\"$row_color\"><td>" . $row['date'] . "</td><td>" . $row['regnr'] ."</td><td>" . $row['vaske_type'] . "</td><td>".$_COOKIE['user']."</td></tr>";
$row_count++;
}
}
elseif ($dbx == "bilvask") {
//$result = mysqli_query($con,"SELECT * FROM bilvask, equipment");
$result = mysqli_query($con,"SELECT bilvask.date, bilvask.type, equipment.eqname AS vaske_type FROM bilvask JOIN equipment ON equipment.eqid = bilvask.type WHERE userid = ". $_COOKIE['userid']);
echo "<thead><tr><th>Dato</th><th>Beskrivelse</th></tr></thead><tbody>";
while($row = mysqli_fetch_array($result))
{
$row_color = ($row_count % 2) ? $color1 : $color2;
echo "<tr bgcolor=\"$row_color\"><td>" . $row['date'] . "</td><td>" . $row['vaske_type'] ."</td></tr>";
$row_count++;
}
}
elseif ($dbx == "workhours") {
$result = mysqli_query($con,"SELECT * FROM workhours WHERE userid = ". $_COOKIE['userid']);
echo "<thead><tr><th>Dato</th><th>Status</th><th>Klokka</th></tr></thead><tbody>";
while($row = mysqli_fetch_array($result))
{
$row_color = ($row_count % 2) ? $color1 : $color2;
echo "<tr bgcolor=\"$row_color\"><td>" . $row['date'] . "</td><td>" . $row['status'] ."</td><td>" . $row['time'] . "</td></tr>";
$row_count++;
}
}
elseif ($dbx == "diesel") {
$result = mysqli_query($con,"SELECT * FROM diesel WHERE userid = ". $_COOKIE['userid']);
echo "<thead><tr><th>Dato</th><th>Km.stand</th><th>Liter</th><th>KR/L</th><th>Stasjon</th><th>Sted</th></tr></thead><tbody>";
while($row = mysqli_fetch_array($result))
{
$row_color = ($row_count % 2) ? $color1 : $color2;
echo "<tr bgcolor=\"$row_color\"><td>" . $row['dato'] . "</td><td>" . $row['km'] . "</td><td>" . $row['liter'] . "</td><td>" . $row['krl'] . "</td><td>" . $row['stasjon'] . "</td><td>" . $row['sted'] . "</td></tr>";
$row_count++;
}
}
elseif ($dbx == "maintenance") {
$result = mysqli_query($con,"SELECT * FROM maintenance WHERE userid = ". $_COOKIE['userid']);
echo "<thead><tr><th>Dato</th><th>Km.stand</th><th>Reg.nummer</th><th>Beskrivelse</th></tr></thead><tbody>";
while($row = mysqli_fetch_array($result))
{
$row_color = ($row_count % 2) ? $color1 : $color2;
echo "<tr bgcolor=\"$row_color\"><td>" . $row['date'] . "</td><td>" . $row['mileage'] ."</td><td>" . $row['registration'] ."</td><td>" . $row['info'] ."</td></tr>";
$row_count++;
}
}
else {
echo "Velg en rapport fra menyen over!";
}
echo "</tbody></table></div>";
mysqli_close($con);
?>
</body>
</html>
May be this will help. You haven't used df and dt parameters in SQL query:
$result = mysqli_query($con, "SELECT trallevask.regnr, trallevask.date,
trallevask.type, equipment.eqname AS vaske_type
FROM trallevask JOIN equipment ON equipment.eqid = trallevask.type
WHERE userid = ". $_COOKIE['userid'] . " AND trallevask.date
BETWEEN " . $_POST['df'] . " AND " . $_POST['dt']);
First thing I see that HTML is formatted incorrectly:
Change line:
echo "<div class=\"datagrid\"><table width=\"100%\" cellspacing=\"0\" cellpadding=\"5\" border=\"0\"><input type=\"submit\" /></form>";
to
echo "<input type=\"submit\" /></form><div class=\"datagrid\"><table width=\"100%\" cellspacing=\"0\" cellpadding=\"5\" border=\"0\">";
Also in the very last line before ?> add </table></div> because you need to close DIV and TABLE tags.
I also can't see where $_POST["databases"]; is coming from, that might cause code to work incorrectly.
select *
from table
where date >= [start date] and date <= [end date]
or (i'm not 100% sure if this works in mysql but it does in postgres!)
select *
from table
where date between [start date] and [end date]
Related
I am trying to develop a program that search in mysql database and return the search results but in when I hit the submit it displays all the results I don't know why this is happening, so any help will be appreciated
<?php
include('connect2.php');
?>
<?php
echo "<center>";
echo "<table border = '3'>";
echo "<thead>";
echo "<tr>";
echo "<th><u>id</u></th>";
echo "<th><u>name</u></th>";
echo "<th><u>countrycode</u></th>";
echo "<th><u>district</u></th>";
echo "<th><u>population</u></th>";
echo "</center>";
echo "</tr>";
echo "</thead>";
$name = isset($_POST['search']) ? $_POST['search'] : '';
$result = mysqli_query($conn, "SELECT id, name, district, population, countrycode FROM city WHERE concat(id, name, district, population, countrycode) LIKE '%$name%' ");
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_array($result)) {
echo "<tr><td>" . $row['id'] . "</td><td>" . $row['name'] . "</td><td>" . $row['countrycode'] . "</td><td>" . $row['district'] . "</td><td>" . $row['population'] . "</td></th>";
}
}
else {
header( "Location:error page.html" ); die;
}
echo "</table>";
mysqli_close($conm);
?>
the search page search.php
<?php
include('connect2.php') ;
?>
<!DOCTYPE html>
<head>
<title>city results</title>
<link href="style-table.css" rel="stylesheet">
<link href="animate.css" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<script>
function validateform() {
var x = document.forms["myform"]["input"].value;
if (x == "") {
alert("input must be filled out");
return false;
}
}
</script>
</head>
<body>
<form method="POST" action="display-results-city.php" name="myform" onsubmit="return validateform()">
<input type="text" name="input" placeholder="search.........">
<button name="submit" type="submit">go</button>
</form>
<?php
echo '<div class="animated fadeInUp">';
echo '<i class="fa fa-arrow-left fa-lg" aria-hidden="true" ></i>';
echo "<div id='records'>";
echo "<table border = '0'>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>name</th>";
echo "<th>countrycode</th>";
echo "<th>district</th>";
echo "<th>population</th>";
echo "</tr>";
echo "</div>";
echo '</div>';
$sql = "select * from city limit 50";
$result = $conn->query($sql);
if( $result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row['ID']. "</td><td>" . $row['Name']. "</td><td>" . $row['CountryCode'] . "</td><td>" . $row['District'] . "</td><td>" . $row['Population'] . "</td></tr>";
}
} else {
echo " 0 results";
}
echo '</table>';
$conn->close();
?>
</body>
</html>
Try running this query..
$result = mysqli_query($conn, "SELECT id, name, district, population, countrycode FROM city WHERE UPPER(concat(id, name, district, population, countrycode)) LIKE UPPER('%$name%') ");
It will match both "Name" and "name".
I'm trying to open a new php page from the sNumber and display the data from the student table on student profile page from the sNumber. But I can't retrieve the data, it goes right to the error. Any help will be appreciated. Thanks
studentlist.php
<div class="memtable">
<?php
$reload = $_SERVER['PHP_SELF'] . "?tpages=" . $tpages;
echo '<div class="pagination"><ul>';
if ($total_pages > 1) {
echo paginate($reload, $show_page, $total_pages);
}
echo "</ul></div>";
// display data in table
echo "<table class='table table-bordered'>";
echo "<thead><tr><th>Last Name</th> <th>First Name</th> <th>School</th> <th>Snumber</th></tr></thead>";
// loop through results of database query, displaying them in the table
for ($i = $start; $i < $end; $i++) {
// make sure that PHP doesn't try to show results that don't exist
if ($i == $total_results) {
break;
}
// echo out the contents of each row into a table
$lastName = "<a href = 'studentprofile.php?id= " .mysql_result($result, $i, 'sNumber'). "'>" . mysql_result($result, $i, 'lastName') . "</a>";
echo "<tr " . $cls . ">";
echo '<td>' . $lastName . '</td>';
echo '<td>' . mysql_result($result, $i, 'firstName') . '</td>';
echo '<td>' . mysql_result($result, $i, 'school') . '</td>';
echo '<td>' . mysql_result($result, $i, 'sNumber') . '</td>';
echo "</tr>";
}
// close table>
echo "</table>";
// pagination
?>
</div>
studentprofile.php
<?php
include('phpdocs/connect.inc.php');
include('header.php');
if ( isset( $_GET[ "sNumber" ] ) )
$student_sNumber = $_GET['sNumber'];
$getStudentInfo = " SELECT sNumber FROM student WHERE student.sNumber = " . $student_sNumber;
?>
<!DOCTYPE html>
<html>
<head>
<title>Student</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="transoverlay">
<?php
if ($result = mysql_query($getStudentInfo)) {
/* fetch associative array */
while ($row = mysql_fetch_assoc($result)) {
echo "<h1 class='tv'>" . $row["sNumber"]. ", ". $row['firstName']."</h1>";
}
mysql_free_result($result);
}else{
echo "<div class='tv'>Student Data could not be listed. </div>";
}
?>
<hr color="#1a1a1a">
</div>
</body>
<?php include('footer.php');?>
</html>
the url uses id but you checking for sNumber change one of those
you need to quote student number in the query as its a string
$getStudentInfo = "SELECT sNumber FROM student WHERE student.sNumber ='". $student_sNumber."'";
My issue is that when I try to access my cart after adding products to it I keep getting the same error,
"mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean
given"
with this line of code:
$itemnumrows = mysqli_num_rows($itemsresult);
<?php
function showcart()
{
require('connect.php');
if (isset($_SESSION['SESS_ORDERNUM'])) {
if (isset($_SESSION['SESS_LOGGEDIN'])) {
$custquery = "SELECT id, status from orders WHERE customer_id = " . $_SESSION['SESS_USERID'] . " AND status < 2;";
$custresult = mysqli_query($con, $custquery);
$custrow = mysqli_fetch_assoc($custresult);
$itemsquery = "SELECT products.*, orderitems.*, orderitems.id AS itemid FROM products, orderitems WHERE orderitems.product_id =products.id AND order_id = " . $custrow['id'];
$itemsresult = mysqli_query($con, $itemsquery);
$itemnumrows = mysqli_num_rows($itemsresult);
} else {
$custquery = "SELECT id, status from orders WHERE session = '" . session_id() . "' AND status < 2;";
$custresult = mysqli_query($con, $custquery);
$custrow = mysqli_fetch_assoc($custresult);
$itemsquery = "SELECT products.*, orderitems.*, orderitems.id AS itemid FROM products, orderitems WHERE orderitems.product_id = products.id AND order_id = " . $custrow['id'];
$itemsresult = mysqli_query($con, $itemsquery);
$itemnumrows = mysqli_num_rows($itemsresult);
}
} else {
$itemnumrows = 0;
}
if ($itemnumrows == 0) {
echo "You have not added anything to your shopping cart yet.";
} else {
echo "<table cellpadding='10'>";
echo "<tr>";
echo "<td></td>";
echo "<td><strong>Item</strong></td>";
echo "<td><strong>Quantity</strong></td>";
echo "<td><strong>Unit Price</strong></td>";
echo "<td><strong>Total Price</strong></td>";
echo "<td></td>";
echo "</tr>";
while ($itemsrow = mysqli_fetch_assoc($itemsresult)) {
$quantitytotal = $itemsrow['price'] * $itemsrow['quantity'];
echo "<tr>";
if (empty($itemsrow['image'])) {
echo "<td><img src='productimages/dummy.jpg' width='50' alt='" . $itemsrow['name'] . "'></td>";
} else {
echo "<td><img src='productimages/" . $itemsrow['image'] . "' width='50' alt='" . $itemsrow['name'] . "'></td>";
}
echo "<td>" . $itemsrow['name'] . "</td>";
echo "<td>" . $itemsrow['quantity'] . "</td>";
echo "<td><strong>£" . sprintf('%.2f', $itemsrow['price']) . "</strong></td>";
echo "<td><strong>£" . sprintf('%.2f', $quantitytotal) . "</strong></td>";
echo "<td>[<a href='delete.php?id=" . $itemsrow['itemid'] . "'>X</a>]</td>";
echo "</tr>";
#$total = $total + $quantitytotal;
$totalquery = "UPDATE orders SET total = " . $total . " WHERE id = " . $_SESSION['SESS_ORDERNUM'];
$totalresult = mysqli_query($con, $totalquery);
}
echo "<tr>";
echo "<td></td>";
echo "<td></td>";
echo "<td></td>";
echo "<td>TOTAL</td>";
echo "<td><strong>£" . sprintf('%.2f', $total) . "</strong></td>";
echo "<td></td>";
echo "</tr>";
echo "</table>";
echo "<p><a href='checkout.php'>Go to the checkout</a></p>";
}
}
?>
Heres my showcart page, also getting the same error with this line:
$numrows = mysqli_num_rows($result);
<?php
session_start();
require("header.php");
require("functions.php");
echo "<h1>Your shopping cart</h1>";
showcart();
if (isset($_SESSION['SESS_ORDERNUM']) == TRUE) {
$query = "SELECT * FROM orderitems WHERE order_id = " . $_SESSION['SESS_ORDERNUM'] . ";";
$result = mysqli_query($con, $query);
$numrows = mysqli_num_rows($result);
if ($numrows >= 1) {
echo "<h2><a href='checkout.php'>Go to the checkout</a></h2>";
}
}
require("footer.php");
?>
My header page as well, when I click the viewcart link it outputs same errors as above blocks of code..
<?php
if (!isset($_SESSION)) {
session_start();
}
if (isset($_SESSION['SESS_CHANGEID']) == TRUE) {
session_unset();
session_regenerate_id();
}
include("connect.php");
?>
<html>
<head>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="header">
<h1 style="color:#ffffff"> <?php echo $site; ?> </h1>
</div>
<div id="menu">
Home
View Basket/Checkout</div>
<div id="container">
<div id="bar">
<?php
include("bar.php");
echo "<hr />";
if (isset($_SESSION['SESS_LOGGEDIN']) == TRUE) {
echo "Logged in as <strong>'" . $_SESSION['SESS_USERNAME'] . "'</strong>[<a href='" . $access . "logout.php'>logout</a>]";
} else {
echo "<a href='" . $access . "login.php'>Login</a>";
} ?></div>
<div id="main">
I seem to be getting Undefined offset 1 error when I hit submit. I have been trying to play with the numbers but nothing seems to help. I added a fourth column right after the commented last name. Before the addition the code worked. I realized later on that I needed that third column. Ever since then I get an error and can not update the sql table.
Thank you in advance,
Avi
<!DOCTYPE html>
<?php
echo '<link rel="stylesheet" type="text/css" href="css/newStyle.css"></head>';
session_start();
if (isset($_SESSION['loggedIn']) && ($_SESSION['loggedIn'] == true) && $_SESSION['admin'] == true) {
echo "<br><h3>Welcome to the administrative area Prof. " . $_SESSION['firstname'] . "!</h3><br><br>";
} else {
//echo "<br>Please log in first to see this page.";
header ('Location: index.php');
}
require_once 'login.php';
$connection = new mysqli($hn,$un,$pw,$db);
if($connection->connect_error) die($connection->connect_error);
if(isset($_POST['submit'])){
for($i = 0; $i < $_POST['totalGrades']; $i++){
echo $i . ': ' . $_POST['grade' .$i] . '<br>';
$parts = explode("|", $_POST['grade' .$i]);
$newGrade = "UPDATE Grades SET grade = '" . $parts[1] . "' WHERE gradeID = " .$parts[0];
$result = $connection->query($newGrade);
}
}
$username = "";
$courseId = "";
$grade = "";
$courseName = "";
?>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="">
</head>
<body>
<form method= "post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<link rel="stylesheet" href="css/style.css">
<?php
// $courseSct =
"SELECT username, courseName, grade, gradeID FROM Courses\n"
// . "JOIN Grades\n"
// . "ON courses.courseId = Grades.courseId";
$courseSct =
"SELECT u.firstname, u.lastname, c.courseName, g.grade "
. " FROM Grades g "
. " INNER JOIN Courses c ON c.courseID = g.courseID "
. " INNER JOIN Users u ON u.userID = g.userID "
. " WHERE c.professorID = " .$_SESSION['userID'];
$result = $connection->query($courseSct);
$rows = $result->num_rows;
echo
"<table border = '1' width = '50%'>"
. "<caption><h2>Grades Table</h2></caption>"
. "<tr>"
. '<th>First Name</th>'
. "<th>Last Name</th>"
. "<th>Course Name</th>"
. "<th>Grade</th>"
//. "<th>New Value</th>"
. "</tr>";
for($j = 0; $j < $rows; ++$j) {
$result->data_seek($j);
$row = $result->fetch_array(MYSQLI_NUM);
echo
"<tr>" .
"<td>" . $row[0] . "</td>" . //First Name
"<td>" . $row[1] . "</td>" . //Last Name
"<td>" . $row[2] . "</td>";
"<td>"; //Grade
echo '<select name="grade' . $j . '" size="1" id="' . $row[3] . '">';
echo '<option value="select">Select</option>';
$letterGrade = 'A';
for($x = 0; $x < 6; $x++) {
echo '<option value="' . $row[3] . '|' . $letterGrade . '"';
if($letterGrade == $row[3]) {
echo ' selected';
}
echo '>' . $letterGrade++ . '</option>';
}
echo '</select><br>'. "</td>" . "</tr>";
}
echo "</table>";
?>
<input type="hidden" name="totalGrades" value="<?php echo $rows;?>">
<br>
<input type="submit" name="submit" value="Submit">
<br>
</form>
<a href='index.php?logout'><br>click here to log out<br></a>
</body>
</html>
Have you tried a foreach instead?
if(isset($_POST['submit'])){
foreach($_POST['totalGrades'] as $key => $value) {
echo $key . ': ' . $value . '<br>';
$parts = explode("|", $value);
$newGrade = "UPDATE Grades SET grade = '" . $parts[1]
. "' WHERE gradeID = " .$parts[0];
$result = $connection->query($newGrade);
}
}
I have PHP code we can call this code BLOCKONE:
$maker = "SELECT vidMaker FROM videoinformation";
if ($result = mysqli_query($con, $maker)) {
while ($row = mysqli_fetch_row($result)) {
$values = explode(',',$row[0]);
foreach($values as $v)
if (!empty($v)) {
printf ("<img class=\"makerImg\" src=\"addVid/maker/%s.jpg\">", $v);
}
}
mysqli_free_result($result);
}
else{
echo"PM administrator with an error";
}
I have big PHP code like:
<!DOCTYPE html>
<head>
</head>
<body>
<?php>
.
.
.
.
.
.
.
.
.
.
.
.
BLOCKONE
.
.
.
.
.
.
.
.
.
.
.
?>
</body>
</html>
The question is BEFORE BLOCKONE all the mysqli queries are working, I can display information, images and so on, but AFTER BLOCKONE none of the queries are working.
Why I know that the problem exactly in this code? Because if delete it... full code working fine. And I'm not sure hot to solve it.
This is full code:
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<?php include 'BSH.php' ?>
<link rel="stylesheet" type="text/css" href="CSS/ldvid.css">
<script type="text/javascript" src="java/FWDUVPlayer.js"></script>
<!-- Setup video player-->
<script type="text/javascript">
<?php include 'video/settings.php'; ?>
</script>
</head>
<body>
<?php include_once 'userPages/check_login_status.php';?>
<?php include_once 'incIndex/headerTop.php'; ?>
<?php include_once 'incIndex/footer.php'; ?>
<?php
// here we get the incomming video id (videoinfo.php?id=123)
$video_id = $_GET['id'];
// build a database query to select the videoInformation
// here we use WHERE to select the video_id we want
$query = 'SELECT newsvid.id, videoinformation.id, videomain.id, newsvid.vidTitle, newsvid.imgCover, videoinformation.vidLD, videoinformation.vidYear, videoinformation.vidCity, videoinformation.vidZanr, videoinformation.vidZanr2,videoinformation.vidZanr3,videoinformation.vidQuality, videoinformation.vidTranslated, videoinformation.vidMaker, videoinformation.vidRoles, videoinformation.vidTime, videoinformation.imgShot1, videoinformation.imgShot2, videoinformation.imgShot3, videomain.vidMUrl FROM newsvid, videomain, videoinformation WHERE newsvid.id = videoinformation.id AND newsvid.id = videomain.id AND newsvid.id = '. $video_id ;
// lets connect and do the query
include 'connect/con.php';
$result = mysqli_query($con, $query);
echo "<div class=\"ldCover\">";
while($row = mysqli_fetch_array($result)) {
echo "<div class=\"panel panel-default\"><div class=\"panel-heading\">";
echo "<div><strong><h3>" . $row['id']. " | " . $row['vidTitle'] . "</h3></strong></div>";
echo "</div><div class=\"panel-body\">";
echo "<div class=\"imgCover\"><img style=\"width:200; height:320px\" class=\"img-thumbnail\"src=\"upload/videoCover/" . $row['imgCover'] . "\"></div>";
echo "<div class=\"vidLD\">
<table>
<tr><td class=\"tdBR\"><strong> Years: </strong></td><td >" . $row['vidYear'] . "</td></tr>
<tr><td class=\"tdBR\"><strong> City: </strong></td><td >". $row['vidCity'] . "</td></tr>
<tr><td class=\"tdBR\"><strong> Zanr: </strong></td><td >". $row['vidZanr'] ." , ". $row['vidZanr2'] ." , ". $row['vidZanr3'] . "</td></tr>
<tr><td class=\"tdBR\"><strong> Quality: </strong></td><td >". $row['vidQuality'] . "</td></tr>
<tr><td class=\"tdBR\"><strong> Translated: </strong></td><td >". $row['vidTranslated'] . "</td></tr>
<tr><td class=\"tdBR\"><strong> Video time: </strong></td><td >". $row['vidTime'] . "</td></tr>
</table>" . $row['vidLD'] . "</div></div>";
echo "<div class=\"panel-body\" style=\"border-top: 1px solid; border-bottom: 1px solid; border-color:#ddd\"><div class=\"vidDesc\">
</div>";
echo "<div class=\"vidMR\">
<div><strong> Maker: </strong>" . $row['vidMaker'] . "</div><div>";
$maker = "SELECT vidMaker FROM videoinformation WHERE id=".$row['id'];
if ($result = mysqli_query($con, $maker)) {
while ($row = mysqli_fetch_row($result)) {
$values = explode(',',$row[0]);
foreach($values as $v)
if (!empty($v)) {
printf ("<img class=\"makerImg img-circle\" src=\"addVid/maker/%s.jpg\">", $v);
}
}
mysqli_free_result($result);
}
else{
echo"PM administrator with an error";
}
echo"</div><div><strong> Roles: </strong>". $row['vidRoles'] . "</div>
<div><table>";
$role = "SELECT vidRoles FROM videoinformation WHERE id=".$row['id'];
if ($result = mysqli_query($con, $role)) {
while ($row = mysqli_fetch_row($result)) {
$values = explode(',',$row[0]);
foreach($values as $v)
if (!empty($v)) {
printf ("<img class=\"roleImg img-circle\" src=\"addVid/roles/%s.jpg\">", $v);
}
}
mysqli_free_result($result);
}
else{
echo"PM administrator with an error";
}
echo "</table></div></div></div>";
echo"<div class=\"panel-body\"><div class=\"screenshots\">";
echo "<div class=\"imgShot1\"><img style=\"width:245px; height:140px\" class=\"img-thumbnail\" src=\"upload/" . $row['imgShot1'] . "\"></div>";
echo "<div class=\"imgShot2\"><img style=\"width:245px; height:140px\" class=\"img-thumbnail\" src=\"upload/" . $row['imgShot2'] . "\"></div>";
echo "<div class=\"imgShot3\"><img style=\"width:245px; height:140px\" class=\"img-thumbnail\" src=\"upload/" . $row['imgShot3'] . "\"></div>";
echo"</div>";
echo "</div><div class=\"panel-footer\">";
echo "<div class=\"vidMUrl\">
<div id=\"myDiv\"></div>
<ul id=\"playlists\" style=\"display:none;\">
<li data-source=\"playlist1\" data-playlist-name=\"MY HTML PLAYLIST\" data-thumbnail-path=\"content/thumbnails/large1.jpg\">
</li></ul>
<ul id=\"playlist1\" style=\"display:none;\">
<li data-thumb-source=\"content/thumbnails/small-fwd.jpg\" data-video-source=\"". $row['vidMUrl'] . "\" data-poster-source=\"upload/videoCover/" . $row['imgCover'] . "\" data-downloadable=\"yes\">
</li></ul>
</div>";
echo "</div></div></div>";
}
mysqli_close($con);
?>
</body>
</html>
You are assuming to get more than one row, but you are always rewriting that:
while ($row = mysqli_fetch_array($result)) {
In your main loop, you are always rewrite your $result and $row variable.
Inside the while loop, use $result2, and $row2.