Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 hours ago.
Improve this question
I want to generate a Fee Voucher for students of any class. Actually i want to generate the fee voucher of the whole class at once.
By writing this I am able to fetch data with two parameters , class and due date.
when i select the class and date and click on the print button a simple html page appears with data which is exactly i want.
The code is as follows,
<?php
// Include the database connection file
include 'connections.php';
// Check if the form has been submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Get the values submitted in the form
$class = $_POST['class'];
$due_date = $_POST['due_date'];
// Construct the query to fetch the data
$query = "SELECT Student_Name, father_name, admission_no, class, section, due_date, due_amount
FROM Bulk_Print_Report
WHERE class = '$class' AND due_date <= '$due_date' AND due_amount > 0
ORDER BY Student_Name ";
$result = mysqli_query($conn, $query);
// Check if any records were found
if (mysqli_num_rows($result) > 0) {
// Generate the report
echo '<h2>Report for Class '.$class.' Due on '.$due_date.'</h2>';
$current_group = '';
while ($row = mysqli_fetch_assoc($result)) {
if ($row['Student_Name'] !== $current_group) {
// Display the group header row only if the student name is different from the previous row
echo '</tbody></table>';
// echo '<h3>'.$row['Student_Name'].'</h3>' ;
echo '<h3>Decent Public School</h3>';
echo '<h3>Fee Voucher Of : '.$row['Student_Name'].' </h3>';
echo '<h4>Fathers Name: '.$row['father_name'].'</h4>';
echo '<h4>Class & Section: '.$row['class'].' ( '.$row['section'].' )</h4>';
echo '<h4>Admission No: '.$row['admission_no'].'</h4>';
echo '<table>';
echo '<thead>
<th>Due Date</th>
<th>Due Amount</th>
</tr></thead>';
echo '<tbody>';
$current_group = $row['Student_Name'];
}
// Display the row for the current record
echo '<tr>';
echo '<td>'.$row['due_date'].'</td>';
echo '<td>'.($row['due_amount'] ?: 0).'</td>';
echo '</tr>';
}
echo '</tbody></table>';
} else {
// If no records were found, display a message
echo '<p>No records found for Class '.$class.' Due on '.$due_date.'</p>';
}
// Close the database connection and exit the script
mysqli_close($conn);
exit();
}
?>
<style>
/* CSS code here
<style>
/* Style for the table */
table {
border-collapse: collapse;
margin: 20px 0;
width: 100%;
}
th,
td {
border: 1px solid #ccc;
padding: 8px;
text-align: left;
}
th {
background-color: #ddd;
}
/* Style for the group header */
h3 {
margin-top: 40px;
}
h4 {
margin-bottom: 10px;
}
/* Style for the form */
.row {
display: flex;
flex-wrap: wrap;
margin: 20px 0;
}
label {
margin-right: 10px;
font-weight: bold;
}
select,
input[type="text"] {
padding: 5px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 4px;
margin-right: 10px;
margin-bottom: 10px;
}
input[type="submit"] {
background-color: #4CAF50;
color: #fff;
border: none;
border-radius: 4px;
padding: 10px 20px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #45a049;
}
</style>
<!DOCTYPE html>
<html>
<head>
<title>Bulk Printing Reports</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.13.1/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="//code.jquery.com/ui/1.13.1/jquery-ui.min.js"></script>
<style>
/* CSS code here */
</style>
</head>
<body>
<h1>Bulk Printing Reports</h1>
<form method="POST">
<div class="row">
<label for="class">Class:</label>
<select id="class" name="class">
<?php
$class_query = "SELECT DISTINCT class FROM Bulk_Print_Report";
$class_result = mysqli_query($conn, $class_query);
while ($row = mysqli_fetch_assoc($class_result)) :
?>
<option value="<?php echo $row['class']; ?>"><?php echo $row['class']; ?></option>
<?php endwhile; ?>
</select>
<label for="due_date">Due Date:</label>
<input type="text" id="due_date" name="due_date">
<script>
$(function() {
$("#due_date").datepicker({
dateFormat: "yy-mm-dd"
});
});
</script>
<input type="submit" value="Print">
Actually my code gives data in html form without any css styles. and im unable to create the challan on pdf like School copy, Bank, and student copy
I Have a Database Table Name Bulk_Print_Report in which the fields are as follows
id| Student_Name|father_name|class|section|admission_no|due_date|due_amount
But I want to convert this data to a beautiful Fee Voucher of Students.
and i want to print the proper fee voucher in the form of PDF. i have tried fpdf but failed.
Actually i want that each student record print on single page and it print 3 copies of data, like one for School copy, one for Bank copy and one for Student copy, as follows...
Decent Public School
Contact:0300xxxxxxxx
Fee Voucher
School Copy
Student Name:
Father Name:
Class:
Section:
Admission NO:
Due Date: Due Amount:
dates and amount come from database
Related
Okay I tried this before and it got closed because it wasn't specific. Below is my entire page code. Please ignore the font and html stuff because all of that is working fine. My Specific question is how to alter this so that the column called "Given" is reset to 0 (zero) at the first day of each month automatically. I am only specifically asking for how to make this happen.
Everything else is working to manually add and subtract, etc. I only need assistance in making that column reset to zero on the first day of each month.
TO BE EVEN MORE SPECIFIC the column "OWED" in the database should be reset to 0 (zero) at the first day of each month automatically to achieve this.
I am new to coding and this code was made for me months ago, and while I have learned a lot since then, I do not seem to find any example to learn from on how to make what I am asking happen. Thank you
EDIT - The objective is to reset all of the rows in the "Owed" column at the same time. Either automatically each month, or manually with one button (or image button)
<?php
$servername = "localhost";
$username = " ";
$password = " ";
$db=" ";
$conn = mysqli_connect($servername, $username, $password,$db);
// $sql = "INSERT INTO `number`( `number`)
// VALUES ('$qty')";
$sql = "SELECT id,name,requests,owed FROM record ORDER BY name";
$result = $conn->query($sql);
?>
<!DOCTYPE html>
<html>
<head>
<style>
table#customers {
width: fit-content;
margin: auto;
margin-top: 2px;
}
#customers {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
#customers td, #customers th {
border: 2px solid #B7B7B7;
padding: 4px;
}
#customers tr:nth-child(even){background-color: #ffffff;}
#customers tr:nth-child(odd){background-color: #f2f2f2;}
#customers tr:hover {background-color: aliceblue;}
#customers th {
padding-top: 2px;
padding-bottom: 2px;
text-align: center;
background-color: #FFB951;
color: black;
}
.sub-add{
float: right;
}
span.sub-add a {
text-decoration: none;
margin: 1px;
}
</style>
</head>
<body leftmargin="0" topmargin="0">
<meta http-equiv="refresh" content="10" >
<table id="customers" bgcolor="#CCCCCC">
<tr>
<th height="5" width="20%">Name</th>
<th height="5" width="20%" style="display:none">Requests</th>
<th height="5" width="10%">Earned</th>
<th height="5" width="10%">Given</th>
<th height="5" width="10%">Owed</th>
</tr>
<?php
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$earned = $row["requests"]/1;
$owed = $row["owed"];
$earned = (int)$earned;
$owedtoo = $earned - $owed;
echo '<tr><td><center><b><font color="Orange">'.$row["name"].'<font></b><br><a onclick="return confirm(\'Are You SURE You Want To Delete?\')" href="delete.php?id='.$row['id'].'">Delete</a> | Edit
</center></td><center><td style="display:none"><center>'.$row["requests"].'<span class="sub-add"><span>-</span> <span> +  </center></span></span></td></center><td><center><b><font color="green">'.$earned.'</font></b></td><center><td><center><b>'.$row["owed"].'</b><span class="sub-add"><span> - </span> <span> + </span></span></center></td><td><center><b><font color="red">'.$owedtoo.'</font></b></td></tr>';
}
}
?>
</table>
</body>
</html>
<?php $conn->close(); ?>
Use cron jobs for routine or date/time specific tasks.
Good question thread here: How to create cron job using PHP?
I have a php table retrieved dynamically from Mysql, and i also have an input field in the table to edit a column.
When i clicked anywhere on the table, the table would disappear - so i used pointer-events: none; in the css. This cured the problem, however now when i click the input field to type something in, the table disappears again.
I do not want the table to disappear when i click on the input field to type something in.
I have tried many different Pointer events in the css of the input field without any luck...and if i take the pointer-events: auto; out of the css for the input field, i cannot click on the input field at all
Below is my code - Does anyone know what i am doing wrong?
Code for my Table:
<div id="table1" class="table1">
<form action="" method="post">
<?php
if(isset($_POST["submit"]))
{
$searchTerm=$_POST['search'];
$stmt = $conn->prepare(" SELECT question.description AS question, answer.description AS answer, discipline.name AS name, response.responseid AS responseid, response.response AS response, response.student_id AS student_id, response.Date_Time AS Date
FROM response
INNER JOIN answer ON response.question_id = answer.answerid
INNER JOIN question ON response.question_id = question.qid
INNER JOIN discipline ON response.discipline_id = discipline.disciplineid WHERE Date_Time LIKE :searchTerm");
$stmt->bindValue(':searchTerm','%'.$searchTerm.'%');
$stmt->execute();
$result=0;
/*
The above code is a query which selects attributes according to the search term
*/
echo "<table> <tr><th>Discipline</th><th>Question</th><th>Student ID</th><th>Response</th><th>Date & Time</th><th>Answer</th><th>Final Marks</th></tr>";
while ($response = $stmt->fetch()) /* This is a While loop which iterates each row */
{
echo " <tr><td>".$response["name"]."</td><td>".$response["question"]."</td><td>".$response["student_id"]."</td><td>".$response["response"]."</td><td>".$response["Date"]."</td><td><input type='text' name='date' value=". $response["answer"]."></td></tr> ";
$result++;
}
} /* This bit of code closes the connection with the database */
?>
<input type="submit" name="save" value="save">
</form>
</div>
CSS:
.table1 {
position: fixed;
pointer-events: none;
background-color: white;
border-collapse: collapse;
width: 40px;
color: black;
margin-left: 50px;
margin-top: 66px;
white-space: nowrap;
}
.table1 input {
pointer-events: auto;
width: 20px;
height:25px;
}
So I've been working on a small system which involves codes which is used for a user to redeem them for some sort of reward.
So far I have this script in PHP and HTML:
http://pastebin.com/UUsEKpev
It's only showing one result which you can see here, I want it to display multiple results in a table going down showing all results.
<?php
$yn;
mysql_connect("localhost", "root", "password") or die(mysql_error());
mysql_select_db("mcv") or die(mysql_error());
$result = mysql_query("SELECT * FROM Codes")
or die(mysql_error());
$row = mysql_fetch_array( $result );
// Print out the contents of the entry
if ($row['Used'] == 1) {
$yn = "Yes";
}
else{
$yn = "No";
}
?>
<html>
<head>
<title>Minecraft Codes</title>
<style type="text/css">
tbody {
display: table-row-group;
vertical-align: middle;
border-color: inherit;
}
tr {
display: table-row;
vertical-align: inherit;
border-color: inherit;
}
th {
border: 1px solid #C3C3C3;
padding: 3px;
vertical-align: top;
width: 20%;
background-color: #E5EECC;
}
table.reference {
background-color: white;
border: 1px solid #C3C3C3;
border-collapse: collapse;
width: 50%;
}
table.reference td {
border: 1px solid #C3C3C3;
padding: 3px;
vertical-align: top;
width: 20%;
}
table, th, td, input, textarea {
font-size: 100%;
}
body, p, h1, h2, h3, h4, table, td, th, ul, ol, textarea, input {
font-family: verdana,helvetica,arial,sans-serif;
}
</style>
</head>
<body>
<center>
<br />
<h1><u>Minecraft Server VIP Codes</u></h1>
<br />
<table class="reference">
<tr>
<th>Code</th>
<th>Used?</th>
</tr>
<?php echo "<tr><td>".$row['Code']."</td><td>".$yn."</td></tr>"; ?>
</table>
</center>
</body>
</html>
Your problem is that you are only fetching one row:
$row = mysql_fetch_array( $result );
That line fetches the current row of the result set. You want to do that in a loop:
$rows = array();
while ($row = mysql_fetch_array($result)) {
$rows[] = $row;
}
If you can please avoid using the mysql_ functions, they are deprecated, see the giant warning here and read this
<table class="reference">
<tr>
<th>Code</th>
<th>Used?</th>
</tr>
<?php while ($row = mysql_fetch_array($result)): ?>
<?php
if ($row['Used'] == 1) {
$yn = "Yes";
}
else{
$yn = "No";
}
?>
<tr>
<td><?php echo $row['Code']; ?></td>
<td><?php echo $yn; ?></td>
</tr>
<?php endwhile; ?>
</table>
Well yes, you call mysql_fetch_row() only a single time, thus you only retrieve a single row. You have to wrap that into a loop that is executed as many times as there are rows.
There are millions of examples on the internet that you can learn from...
I have just "created" a script that orders the songs by number of votes (see here : http://radiowhisper.com/demo/demo.php), using a tutorial. And now, the problem: Everytime when i refresh the page i see the song names randomized. How can i order them by number of votes? (FOR ALL THE TIME -> NOT TO BE RANDOMIZED).
Info: The song names are writed in "sort-objects" table from PhpMyAdmin.
The tutorial: http://tutorialzine.com/2009/11/jquery-sort-vote/
Files:
demo.php
<?php
// Hiding notices:
error_reporting(E_ALL^E_NOTICE);
// Including file for the DB connection:
define("INCLUDE_CHECK",1);
require 'connect.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Radio Whisper - Top 40</title>
<link rel="stylesheet" type="text/css" href="demo.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<div id="main">
<h1>Radio Whisper - Top 40</h1>
<h2>Ordonati melodiile in functie de preferinte.</h2>
<hr />
<?php
// Checking whether the user has voted today:
$voted=false;
$vcheck=mysql_query(" SELECT 1 FROM sort_votes
WHERE ip='".$_SERVER['REMOTE_ADDR']."'
AND date_submit=CURDATE()");
if(mysql_num_rows($vcheck)==1)
$voted=true;
// If we are not on the data.php?results page:
if(!array_key_exists('results',$_GET))
{
echo '<ul class="sort">';
// Showing the tutorials by random
$res = mysql_query("SELECT * FROM sort_objects ORDER BY RAND()");
while($row=mysql_fetch_assoc($res))
{?>
<li id="li<?php echo $row['id']?>">
<div class="tut">
<div class="tut-img">
<img src="<?php echo $row['img']?>" width="50" height="50" alt="<?php echo $row['title']?>" />
<div class="drag-label"></div>
</div>
<div class="tut-title">
<?php echo $row['title']?>
</div>
<div class="tut-description"><?php echo $row['description']?></div>
<div class="clear"></div>
</div>
</li>
<?php } ?>
</ul>
<div class="button-holder">
<?php if(!$voted):?>Trimite topul<span></span><?php endif;?>
Vezi rezultatele<span></span>
</div>
<?php
}
else require "results.php";
// The above require saves us from having to style another separate page
?>
<!-- The form below is not directly available to the user -->
<form action="?results" id="sform" method="post">
<input name="sortdata" id="sortdata" type="hidden" value="" />
</form>
</body>
</html>
demo.css
body,h1,h2,h3,p,quote,small,form,input,ul,li,ol,label{
/* A simple page reset */
margin:0px;
padding:0px;
}
body{
color:white;
font-size:13px;
background: url(img/bg.jpg) repeat-x #003951;
font-family:Arial, Helvetica, sans-serif;
text-shadow:2px 2px 5px #333333;
}
.tut-title{
font-size:20px;
font-weight:bold;
}
.tut-description{
color:#DDDDDD;
font-family:Arial,Helvetica,sans-serif;
font-size:17px;
padding-top:5px;
}
.tut-img{
border:0px solid white;
float:right;
margin:0 110px 0 0;
width:50px;
height:50px;
overflow:hidden;
/* CSS3 Box Shadow */
-moz-box-shadow:2px 2px 3px #333333;
-webkit-box-shadow:2px 2px 3px #333333;
box-shadow:2px 2px 3px #333333;
cursor:n-resize;
position:relative;
}
.drag-label{
/* The DRAG label that scrolls into visibility on hover */
background:url(img/label_small.png) no-repeat;
width:71px;
height:25px;
position:relative;
margin-left:25px;
}
a.button{
/* The pretty buttons on the bottom are actually hyperlinks.. */
color:#434343 !important;
display:block;
float:left;
font-size:10px;
font-weight:bold;
height:23px;
margin:10px;
padding:12px 10px 0 12px;
position:relative;
text-shadow:none;
text-transform:uppercase;
/* This is the left part of the button background image */
background:transparent url(img/button_gray_bg.png) no-repeat;
}
a.button:hover{
text-decoration:none !important;
background-position:bottom left;
}
a.button:active{
/* Offsetting the text 1px to the bottom on mouse-click*/
padding-top:13px;
height:22px;
}
a.button span{
/* This span holds the right part of the button backgound */
background:transparent url(img/button_gray_bg.png) no-repeat right top;
height:35px;
position:absolute;
right:-2px;
top:0;
width:10px;
display:block;
}
a.button:hover span{
background-position:bottom right;
}
.button-holder{
padding-left:107px;
}
ul.sort{
/* This UL gets converted to a sortable by jQuery */
font-family:"Myriad Pro",Arial,Helvetica,sans-serif;
font-size:20px;
}
ul.sort li{
margin:25px 50px 25px 0;
height:102px;
list-style:none;
}
.chart{
/* Styling the chart container */
background:#002A3C;
border:1px solid #005A7F;
height:300px;
width:550px;
}
.bar{
/* Each bar in the chart is a div. Colors and width are assigned later */
height:17px;
margin:15px;
overflow:hidden;
padding:15px 10px 10px;
text-shadow:none;
white-space:nowrap;
}
.bar a, .bar a:visited{
color:white;
font-size:12px;
}
.tot-votes{
float:right;
font-size:10px;
font-weight:bold;
position:relative;
right:50px;
text-transform:uppercase;
top:18px;
}
/* General styles for the demo page */
h1{
/* The title of the page */
color:white;
font-family:"MyRiad Pro",Arial,Helvetica,sans-serif;
font-size:38px;
font-weight:normal;
}
h2{
/* The subtitle */
font-family:"MyRiad Pro","Arial Narrow",Arial,Helvetica,sans-serif;
font-size:16px;
font-weight:normal;
letter-spacing:1px;
padding-left:2px;
text-transform:uppercase;
white-space:nowrap;
margin:10px 0 25px;
}
#orig{
/* The link that is positioned above the title */
font-family:"MyRiad Pro",Arial;
font-size:10px;
letter-spacing:1px;
padding-bottom:15px;
text-transform:uppercase;
}
hr{
/* The horizontal ruler */
background-color:#BBBBBB;
border:medium none;
color:#BBBBBB;
height:1px;
margin:30px auto;
width:450px;
}
.clear{
/* The clearfix hack */
clear:both;
}
#main{
/* The main container */
width:600px;
margin:30px auto;
}
a img{
border:none;
}
a, a:visited {
color:#00BBFF;
text-decoration:none;
outline:none;
}
a:hover{
text-decoration:underline;
}
.tutorial-info{
text-align:center;
padding:10px;
}
connect.php
<?php
if(!defined('INCLUDE_CHECK')) die('You are not allowed to execute this file directly');
/* Database config */ (Edit: I don't want to see them)
$db_host = '*********';
$db_user = '***********';
$db_pass = '******';
$db_database = '***************';
/* End config */
$link = mysql_connect($db_host,$db_user,$db_pass) or die('Unable to establish a DB connection');
mysql_select_db($db_database,$link);
mysql_query("SET names UTF8");
?>
results.php
<?php
if(!defined('INCLUDE_CHECK')) die('You are not allowed to execute this file directly');
// If the poll has been submitted:
if($_POST['sortdata'])
{
// The data arrives as a comma-separated string,
// so we extract each post ids:
$data=explode(',',str_replace('li','',$_POST['sortdata']));
// Getting the number of objects
list($tot_objects) = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM sort_objects"));
if(count($data)!=$tot_objects) die("Wrong data!");
foreach($data as $k=>$v)
{
// Building the sql query:
$str[]='('.(int)$v.','.($tot_objects-$k).')';
}
$str = 'VALUES'.join(',',$str);
// This will limit voting to once a day per IP:
mysql_query(" INSERT INTO `sort_votes` (ip,date_submit,dt_submit)
VALUES ('".$_SERVER['REMOTE_ADDR']."',NOW(),NOW())");
// If the user has not voted before today:
if(mysql_affected_rows($link)==1)
{
mysql_query(' INSERT INTO `sort_objects` (id,votes) '.$str.'
ON DUPLICATE KEY UPDATE votes = votes+VALUES(votes)');
}
}
// Selecting the sample tutorials and ordering
// them by the votes each of them received:
$res = mysql_query("SELECT * FROM sort_objects ORDER BY votes DESC");
$maxVote=0;
$bars=array();
while($row=mysql_fetch_assoc($res))
{
$bars[]=$row;
// Storing the max vote, so we can scale the bars of the chart:
if($row['votes']>$maxVote) $maxVote = $row['votes'];
}
$barstr='';
// The colors of the bars:
$colors=array('#ff9900','#66cc00','#3399cc','#dd0000','#800080');
foreach($bars as $k=>$v)
{
// Buildling the bar string:
$barstr.='
<div class="bar" style="width:'.max((int)(($v['votes']/$maxVote)*450),100).'px;background:'.$colors[$k].'">
'.$v['short'].'
</div>';
}
// The total number of votes cast in the poll:
list($totVotes) = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM sort_votes"));
?>
<div class="chart">
<?php echo $barstr?>
</div>
Go Back<span></span>
<div class="tot-votes"><?php echo $totVotes?> votes</div>
script.js
$(document).ready(function(){
// Executed once all the page elements are loaded
// Convert the UL with all the tutorials into a sortable list:
$("ul.sort").sortable({
handle : '.tut-img',
axis:'y',
containment: 'document',
opacity: 0.6
});
// The hover method takes a mouseover and a mouseout function:
$(".tut").hover(
function(){
$(this).find('.drag-label').stop().animate({marginTop:'-25px'},'fast');
},
function(){
$(this).find('.drag-label').stop().animate({marginTop:'0'},'fast');
}
);
// Binding an action to the submitPoll button:
$('#submitPoll').click(function(e){
// We then turn the sortable into a comma-separated string
// and assign it to the sortdata hidden form field:
$('#sortdata').val($('ul.sort').sortable('toArray').join(','));
// After this we submit the form:
$('#sform').submit();
// Preventing the default action triggered by clicking on the link
e.preventDefault();
});
});
So, what's the problem ?!?
Don't want to be rude but instead of just copying and pasting code, you would actually read the code and try to understand it you might see these 2 lines
// Showing the tutorials by random
$res = mysql_query("SELECT * FROM sort_objects ORDER BY RAND()");
Seriously, one of them is a comment on what the next line of code does!
ORDER BY is the part of the query that tells it how to sort the results. ORDER BY RAND() will, not surprisingly, give you randomly sorted results. Instead, you should do ORDER BY votes or whatever the name of the column that contains votes is. ORDER BY votes asc will sort them in ascending order (fewest votes first) and ORDER BY votes desc will sort them in descending order (most votes first).
This assumes that you have votes stored in a single field in your table. If that's not the case (e.g., if you have a table with one record per vote), you'll need to tell us about your database schema.
I have a website that loads a CSV, divides it into parts, and shows these parts.
There are 7 parts, and since it is for a music store it is sliced like this:
the name of the product
the subname
the price
the stock in one shop
the stock of the other shop
the group name
the brandname
What i have now is that it shows 12 products on 1 page, with a next and previous link on top of the page.
The pages are made with the group name, every group has it's own page, so you have a drums page, guitar page, speaker page.
That all works great.
What i programmed in there is a dropdownlist, it drops down a list of brandnames, which should narrow the search for a person who is looking at the products.
Problem is right now, that the dropdown menu works, i see the brands, but they are NONE clickable, only the brands that are currently on the page are shown, so NOT all the brands from that group are shown, only the 12 that are currently showing, when you press next, it shows 12 more brands, but i want them to be shown right on the start.
And the third problem is, when it is showing the brands, it shows them double or triple, depending on how many products have the same brand.
Is there a way what i want, with this code as a basis ?
<html>
<body bgcolor=#E2E965 link=black vlink=black alink=black text=#D5DF23>
<style type="text/css">
#nav, #nav ul {
padding: 0;
margin: 0;
list-style: none;
}
#nav li {
float: left;
width: 120px;
}
#nav ul {
position: absolute;
width: 120px;
left: -1000px;
}
#nav li:hover ul {
left: auto;
}
<!--
a {text-decoration:none}
//-->
body
{
scrollbar-arrow-color: #E2E965;
scrollbar-face-color: #D7182A;
scrollbar-highlight-color: #000000;
scrollbar-3dlight-color: #D6DF23;
scrollbar-shadow-color: #00000;
scrollbar-darkshadow-color: #00000;
scrollbar-track-color: #D6DF23;
}
input:link {text-decoration: none; color: #E2E965;}
input:visited {text-decoration: none; color: #E2E965;}
input:active {text-decoration: none; color: #E2E965;}
.spacer_black {
margin: 0px;
padding: 0px;
border: 5px;
height: 2px;
width: 100%;
line-height: 0px;
font-size: 0px;
background-color: #000000;}
</style>
<table width=800 border=0><td>
</html>
<?PHP
$offset = isset($_GET['offset'])?$_GET['offset']:0;
$LinesToDisplay = 12;
$row = $offset + $LinesToDisplay;
$row2 = $offset - $LinesToDisplay;
$file_handle = fopen("web.txt", "rb");
error_reporting( E_ALL ); // DEBUGGING
$SelectArray=array();
while ((($parts = fgetcsv($file_handle,4096,"|")) !== FALSE) && ($LinesToDisplay > 0) && (!feof($file_handle)))
{
//new code
//skip first $offset lines
$num = count($parts[6]);
$SelectArray[]=$parts[6];
if ($parts[5] == 9999)
{
if ($offset-- > 0)
{continue;}
$parts[0] = ucwords(strtolower($parts[0]));
$parts[1] = ucwords(strtolower($parts[1]));
?>
<td>
<?php
echo "<table BACKGROUND='background.jpg' border=0 width=250><td width='243' height='105'>";
echo "<font size=-1 face='helvetica' color=#812990><b>$parts[0]</b></font>";
echo "<i>";
?>
<html>
<div onMouseOver="this.style.color = 'black';" onMouseOut="this.style.color = '#D5DF23';">
</html><?php
echo "<font size=2>-$parts[1]</font>";
echo "</div></i>";
?><html><a href="#" title="Koop nu de <?php echo $parts[0]; ?>" onClick="window.open('form.php?p=<?php echo urlencode($parts[0]); ?>','popuppage','width=400,height=400,top=250,left=250,resizable=0,statusbar=0,titlebar=yes,toolbar=no,scrollbars=no,location=no,directories=no');">
<div><img src='ster.jpg' border=0 width='46' align='right'></a>
<a href="#"><img src='envelope.jpg' border=0 width='46' align='right'title="Heeft u een vraag over <?php echo $parts[0]; ?>" onClick="window.open('vraag.php?p=<?php echo urlencode($parts[0]); ?>','popuppage','width=400,height=400,top=250,left=250,resizable=0,statusbar=0,titlebar=yes,toolbar=no,scrollbars=no,location=no,directories=no');">
<div></a>
<TABLE BORDER='0' cellpadding='0' CELLSPACING='0'>
<TR>
<TD WIDTH='70' HEIGHT='20' BACKGROUND='pricebackground.jpg' VALIGN='bottom'>
<center>
<font size=2 color=white face='helvetica'>
<b></html>
<?php echo "€ $parts[2]";
?>
</b>
</td>
</tr>
</table>
<?php echo "<b><font size=3 color=#D7182A>Op Voorraad In:<br></font>";
echo ("<font color=black> Amsterdam </font>");
if ( $parts[3] >= 1 ) echo ("<IMG SRC =green.gif>")."";
if ( $parts[3] <= 0 ) echo ("<IMG SRC =red.gif>")."";
echo ("<font color=black> Utrecht </font>");
if ( $parts[4] >= 1 ) echo ("<IMG SRC =green.gif>")."</td></table></b><p style='margin:9px;'>";
if ( $parts[4] <= 0 ) echo ("<IMG SRC =red.gif>")."</td></table></b><p style='margin:9px;'>";
$LinesToDisplay--;
if ($LinesToDisplay/3==intval($LinesToDisplay/3))
{
echo "<tr><td>";
}
}}
fclose($file_handle);
?>
<tr align=right>
<select style="background-color: #FFFFFF; color: #000000; font-family: Arial; font-weight: none; font-size: 12; width: 150px; ">
<?php
$i=1;
foreach ($SelectArray as $val){
echo "<option value=\"$i\">$val</option>\n";
$i++;
}
?>
</select>
<font color=black><body alink=black vlink=black link=black text=black>
<center>next »</table></html>
You determine the offset and then fill $SelectArray with 12 lines. That way your script has no way of knowing what else is in the .csv, and it can't display anything except for the data you got from the file.
If you want to display all the brands you need to import the full .csv. Depending on how larget that file is, this might nog be a good idea, because you'll be loading that complete file every time you load the page. If it's a possibility: use a database instead, import the .csv and select only the necessary information.
At the moment the file is only 180kbytes so that is no problem, the problem is how to do it.