getting events from database to calendar page - php

Database:
Calendar 1:
Calendar 2:
Calendar 3:
I'm trying to getting both events from the database onto Monday 4th and I'm wondering why I am only getting one event for April and May.
$sql = "SELECT title, contact, contact_email, DAYOFMONTH(start_date)
FROM $caltbl WHERE start_date LIKE '$year-$month%'";
$result = mysql_query($sql)or die(mysql_error());
$row_count = mysql_num_rows($result);
$record = mysql_fetch_array($result);
while ($day_num <= $days_in_month) {
echo "<td width=\"42\" valign=\"top\">
<a href='index.php?day=$day_num-$title-$year'>
$day_num</a><p/>";
if ($day_num == $record['DAYOFMONTH(start_date)']){
echo " ".$record['title']. "<br/>";
} else{
echo "<br /> " . "<br/> ";
}
echo "</td>";
$day_num++;
$day_count++;
EDIT:
while ($day_num <= $days_in_month) {
echo "<td width=\"42\" valign=\"top\"> <a href='index.php?day=$day_num-$title-$year'>$day_num</a><p/>";
if ($day_num == $record['DAYOFMONTH(start_date)']){
while ($event = mysql_fetch_assoc($result)) {
$array[] = $event;
}
print_r($array);
echo " ".$event['title']. "<br/>";
} else{
echo "<br /> " . "<br/> ";
}
echo "</td>";
$day_num++;
$day_count++;
// Make sure we start a new row each week
if ($day_count > 7) {
echo "</tr><tr>";
$day_count = 1;
}
}

Open a blank array:
$arr = array();
while ($event = mysql_fetch_assoc($result)) {
$arr[] = $event;//store all the data in the $arr array
}
Run a foreach loop to to print the event detail:
foreach($arr as $k=>$v){
if($v['DATEOFMONTH(start_date)']==$day_num){
echo ''.$v['title'].'<br/>';
}else{
echo "<br /> " . "<br/> ";
}
}
Hope this may help. demo

Related

paging is not working for jquery datatable

i am using jquery table to show table on a web page.The table is coming up properly but paging for the table and showing number of records and search options are not working for the table generated.All the records are populating at the load of the page.This is my code
PHP code
$qry = " SELECT AssetId,";
$qry .= $data;
$qry .= " from Completedetails";
mysql_select_db($database_finalkms, $finalkms);
$query_getcolumns = $qry;
$getcolumns = mysql_query($query_getcolumns, $finalkms) or die(mysql_error());
$row_getcolumns = mysql_fetch_assoc($getcolumns);
$totalRows_getcolumns = mysql_num_rows($getcolumns);
if (($getcolumns)||(mysql_errno == 0))
{
echo "<table width='50%' id='sample_2'><thead><tr>";
if (mysql_num_rows($getcolumns)>0)
{
//loop thru the field names to print the correct headers
$i = 0;
while ($i < mysql_num_fields($getcolumns))
{
echo "<th align='center'>". mysql_field_name($getcolumns, $i) . "</th>";
$i++;
}
echo "</tr></thead>";
//display the data
while ($rows = mysql_fetch_array($getcolumns,MYSQL_ASSOC))
{
echo "<tbody><tr >";
foreach ($rows as $data)
{
echo "<td align='center'>". $data . "</td>";
}
}
}else{
echo "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr>";
}
echo "</tbody></table>";
}else{
echo "Error in running query :". mysql_error();
}
?>
Java Script
<script>
jQuery(document).ready(function() {
// initiate layout and plugins
$("#sample_2").dataTable({"bPaginate": true});
});
</script>
<input name="hdnfld" id="hdnfld" type="hidden" value="<?php echo $qry;?>"/>
Please help me in this regard.
Try the following modified code of yours, if still not working then give the live URl where ur html output is displyed.
if (($getcolumns)||(mysql_errno == 0))
{
// Displying the headers
$i = 0;
echo "<table width='50%' id='sample_2'><thead><tr>";
while ($i < mysql_num_fields($getcolumns))
{
echo "<th align='center'>". mysql_field_name($getcolumns, $i) . "</th>";
$i++;
}
echo "</tr></thead>";
// Data Section
echo "<tbody>";
if (mysql_num_rows($getcolumns)>0)
{
while ($rows = mysql_fetch_array($getcolumns, MYSQL_ASSOC))
{
echo "<tr>";
foreach ($rows as $data)
{
echo "<td align='center'>". $data . "</td>";
}
echo "</tr>";
}
}else{
echo "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr>";
}
echo "</tbody></table>";
}else{
echo "Error in running query :". mysql_error();
}

Database query info to dropdown menu

I am taking info from a database query and adding it to a dropdown menu form (that is placed inside a table). The query is in a separate function that is called from within the form. It adds the info from the database to the correct location on the table, but it is not in the dropdown menu. I used variables $a, $b, and $c to test my syntax, and it works fine with those variables. Is it an issue with the function call? Any ideas?
Here is the code:
<?php
function fill_dropdown(){
include("../secure/database.php");
$conn = pg_connect(HOST." ".DBNAME." ".USERNAME." ".PASSWORD)
or die('Could not connect: ' . pg_last_error()); //error if could not connect to database
$query = "SELECT country_code, name FROM lab5.country ORDER BY name ASC";
$result = pg_query($query) or die("Unable to execute: " . pg_last_error($conn));
$numRow = 0;
//results are good so output them to HTML
//echo "test<br />";
while ($line1 = pg_fetch_array($result, null, PGSQL_ASSOC)){
$counter = 0;
//echo "test<br />";
foreach ($line1 as $col_value){ // then add all data for attributes in succeeding columns
if($counter == 0){
$code[$numRow] = $col_value;//array($numRow => $col_value);
echo "\t\t<input type=\"hidden\" name=\"code\" value=\"$code[$numRow]\" />";
//echo $code[$numRow] . "<br />";
}
elseif($counter == 1){
$country_name[$numRow] = $col_value;
echo "<option value=$country_name[$numRow]>$country_name[$numRow]</option>";
//echo $country_name[$numRow] . "<br />";
}
$counter++;
}
$numRow++;
}
//echo "end test<br />";
}
echo "<table border = \"1\">";
echo "<form method=\"POST\" action=\"exec.php\">"; //save and cancel buttons
for($i=1; $i<5; $i++) //building initial table
{
echo "\t<tr>\n";
echo "\t\t<td>";
if($i == 1)
echo "Name";
elseif($i == 2)
echo "Country Code";
elseif($i == 3)
echo "District";
else
echo "Population";
echo "</td>\n";
echo "<td>\n";
if($i == 1){
echo "<input type=\"text\" name=\"name\">";
}
elseif($i == 2){
echo "<select name=\"country_code\">"; //dropdown box
$c = 0; //these are just to show that this way works
$a = "IOT";
$b = "test2";
$numRow = 1;
echo "<option value=\"IOT\">British Indian Ocean Territory</option>";
echo "<option value=$a>$b</option>";
//echo "<option value=" . $country_name[$numRow] . ">" . $country_name[$numRow] . "</option>";
fill_dropdown();
//echo "<option value=\"Brunei\">Brunei</option>";
echo "</select>";
}
elseif($i == 3){
echo "<input type=\"text\" name=\"district\">";
}
else{
echo "<input type=\"text\" name=\"population\">";
}
}
echo "</td>";
echo "</tr>";
echo "</table>";
echo "\t\t<input type=\"submit\" value=\"Save\" name=\"save\" />";
echo "<input type=\"button\" value=\"Cancel\" onclick=\"top.location.href='" . $_SERVER['HTTP_REFERER'] . "';\" />\n";
echo "</form>";
?>
It would seem you can replace
while ($line1 = pg_fetch_array($result, null, PGSQL_ASSOC)){
$counter = 0;
//echo "test<br />";
foreach ($line1 as $col_value){ // then add all data for attributes in succeeding columns
if($counter == 0){
$code[$numRow] = $col_value;//array($numRow => $col_value);
echo "\t\t<input type=\"hidden\" name=\"code\" value=\"$code[$numRow]\" />";
//echo $code[$numRow] . "<br />";
}
elseif($counter == 1){
$country_name[$numRow] = $col_value;
echo "<option value=$country_name[$numRow]>$country_name[$numRow]</option>";
//echo $country_name[$numRow] . "<br />";
}
$counter++;
}
$numRow++;
}
with
while ($row = pg_fetch_assoc($result)) {
// why do you want this line at all?
echo "\t\t<input type=\"hidden\" name=\"code\" value=\"$row[country_code]\"/>";
echo "<option value=\"$row[name]\">$row[name]</option>";
}
The only thing I can see that is wrong, is not having quotes around the option's value attribute. I don't understand what you are expecting to achieve by interleaving hidden inputs with options, though. Judging by your $a, $b, $c template, maybe what you actually want is:
while ($row = pg_fetch_assoc($result)) {
echo "<option value=\"$row[country_code]\">$row[name]</option>";
}

how to generate random password

i just want to have random password from all the query results i did of the students. on my situation, i tried to generate but it returns only 1 generated password to all queried students(about 45 students). how should i make a random one. plss help..
heres my code
<?php
if(isset($_POST['generate'])){
$charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!##$%^&*()_+';
$generated_pass = substr(str_shuffle($charset), 0, 12);
$generate = $_POST['generate'];
}
?>
<form method="post" action='enroll_student.php' name ='register'>
<?php
$yr = date("Y");
if ($result = $mysqli->query("SELECT
tbl_studentreg.studId,
tbl_studentreg.fname,
tbl_studentreg.lname,
tbl_studentreg.mname,
tbl_studentreg.dob,
tbl_studentreg.address,
tbl_department.departmentName,
tbl_studentreg.sy
FROM tbl_studentreg
Inner Join tbl_department ON tbl_studentreg.departmentId = tbl_department.departmentId WHERE tbl_studentreg.sy = '$yr' "))
{
if ($result->num_rows > 0)
{
echo "<table width= '1000'>";
echo "<tr><th>StudentID</th><th>Name</th><th>Date of Birth</th><th>Address</th><th>Department</th><th>School Year</th><th>Password</th></tr>";
while ($row = $result->fetch_object())
{
echo "<tr>";
echo "<td align='center'>" . $row->studId . "</td>";
echo "<td align='center'>" . $row->fname . " ". $row->mname ." ". $row->lname ." </td>";
echo "<td align='center'>".$row->dob."</td>";
echo "<td align='center'>" . $row->address. "</td>";
echo "<td align='center'>".$row->departmentName."</td>";
echo "<td align='center'>".$row->sy."</td>";
if(isset($generated_pass)) {
//how could i make this one generate random password for every students..?
for($i=0; $i <= $row->studId; $i++){
echo "<td>$generated_pass</td>";
}
}
echo "</tr>";
}
echo "</table>";
}
else
{
echo "No Results.";
}
}
else
{
echo "Error: " . $mysqli->error;
}
$mysqli->close();
echo '<br>';
include 'count.php'; //this one will give the total no. of results, just ignore.
?>
<br />
<tr><td></td></tr><tr><td><input type='submit' name='generate' value='Generate'/></td></tr>
</table>
</form>
function genpass(){
$charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!##$%^&*()_+';
return substr(str_shuffle($charset), 0, 12);
}
// INSIDE THE LOOP
$generated_pass = genpass();
echo "<td>$generated_pass</td>";
Something like that.

PHP - Pagination and place results is a table

I have tried my hand at some pagination but it gives me very unexpected results....
The first is that it on the first page of the pagination it seems to override the CSS and align all divs to the right hand side of the page... when you then click 'next' to view the next three results and so on the page goes back as per the CSS tells it!
The second problem is that the table displaying the results doesn't seem to work. The very first result on each page of the pagination is in the table, the next two results (three results per page) are displayed on the page however below and not in the table!
The code is quite long but here we go:
<?php
session_start();
if ( !isset($_SESSION['username']))
{
header("Location:index.php");
exit();
}
//connect to database
require "dbconn.php";
$per_page = 3;
$start = $_GET['start'];
$sort = #$_POST['order'];
if (!empty($sort)) {
$query = "SELECT bookname, bookauthor, bookpub, bookisbn
FROM booktable
ORDER BY ".mysql_real_escape_string($_POST['order'])." ASC";
}
else {
$query = "SELECT bookname, bookauthor, bookpub, bookisbn
FROM booktable
ORDER BY bookname ASC";
}
$results = mysql_query($query)
or die (mysql_error());
$record_count = mysql_num_rows($results);
if (!$start)
$start = 0;
$get = mysql_query("SELECT * FROM booktable LIMIT $start, $per_page");
?>
<?php
if (isset($_GET['showerror']))
$errorcode = $_GET['showerror'];
else
$errorcode = 0;
?>
Then I will cut out all the unnecesary html
<div id="mid">
<?php
echo "<table border='2px'>";
echo "<tr>";
echo "<th>";
echo "</th>";
echo "<th>";
echo "Book Title";
echo "</th>";
echo "<th>";
echo "Book Author";
echo "</th>";
echo "<th>";
echo "Book Publisher";
echo "</th>";
echo "<th>";
echo "Book ISBN";
echo "</th>";
echo "<th>";
echo "</th>";
echo "</tr>";
while ($row = mysql_fetch_assoc($get))
{
// get data
$bookname = $row['bookname'];
$bookauthor = $row['bookauthor'];
$bookpub = $row['bookpub'];
$bookisbn = $row['bookisbn'];
echo "<tr>";
echo "<td>";
echo "<a href='addtolist.php?bookname=".$bookname."&bookauthor=".$bookauthor."&bookpub=".$bookpub."&bookisbn=".$bookisbn."'>Add to basket</a>";
echo "</td>";
echo "<td>";
echo $bookname;
echo "</td>";
echo "<td>";
echo $bookauthor;
echo "</td>";
echo "<td>";
echo $bookpub;
echo "</td>";
echo "<td>";
echo $bookisbn;
echo "</td>";
echo "</tr>";
echo "</table>";
}
$prev = $start - $per_page;
$next = $start + $per_page;
if (!($start<=0))
echo "<a href='products.php?start=$prev'>Prev</a> ";
//set variable for first page number
$i=1;
//show page numbers
for ($x = 0; $x < $record_count; $x = $x + $per_page)
{
if ($start != $x)
echo "<a href='products.php?start=$x'>$i</a>";
else
echo "<a href='products.php?start=$x'><b>$i</b></a>";
$i++;
}
//show next button
if (!($start >= $record_count - $per_page))
echo "<a href='products.php?start=$next'>Next</a>";
?>
<?php echo $record_count; ?>
This is how the page looks (image 1) (the table border shows the problem)
As I said before I also get the problem when the list first gets displayed and the page ends up looking like this: (image2)
You can see how they differ!
I hope that I have made sense!
For starters, you have your </table> tag in your while loop. Change that and see if everything else falls into place.

PHP Insert Multidimensional Array into mysql

i try to store the booking booths into database based on user selection, there are 10 check boxes for each booths and user can choose which day they want to reserve booths. For each check box has it own field in database, if user choose booth A01, D1 and D2, when he press reserve button, it will insert value into D1 and D2. But I dont know how to get the checked checkbox value to store in database
my booth interface
http://i.imgur.com/umYcI.gif
my table structure
http://i.imgur.com/vKh6R.gif
My coding
<?php
session_start();
if ( !isset($_SESSION['AUTHORIZED_USERNAME']) || empty($_SESSION['AUTHORIZED_USERNAME']) ) {
header("location:index.php");
}else{
$user=$_SESSION['AUTHORIZED_USERNAME'];
}
include('db.php');
if($_REQUEST){
$id = $_REQUEST['search_category_id'];
$query2 = mysql_query("SELECT filenameBig, filename, url FROM eventinfo where eventID ='$id'");
$row = mysql_fetch_array($query2, MYSQL_ASSOC);
if($id == -1)
{
echo "<style type='text/css'>#btn_submit{visibility:hidden}</style>";
}
else{
/*echo "<a href='{$row['url']}'>Click me!</a>";*/
echo "<p><br><img src='{$row['filename']}' alt='' /></p>";
echo "<p></p>";
echo "<p align='right'><a href='$row[filenameBig]' target='_blank'>Click to view large image</a></p>";
echo "<hr size='1'>";
echo "<div style='padding-left:4px;' align='left'><strong>Booths Listing</strong>";
echo "<p></p>";
$query = "select boothAlias, totalDay from booths, eventinfo where booths.eventID=eventinfo.eventID && booths.eventID = ".$id."";
$_SESSION['EVENT_ID']=$id;
$result = mysql_query($query);
$result2= mysql_query($query);
echo "<table border='0' style='width:400px;table-layout:fixed' >";
$rows2 = mysql_fetch_array($result);
$Day=$rows2['totalDay'];
echo "<table>";
for ($day = 0; $day <= $Day; ++$day) {
if($day==0){
echo "<th>Booth</th>";
}else{
echo "<th>D".$day."</th>";
}
}
while($rows = mysql_fetch_array($result2)){
$boothAlias=$rows['boothAlias'];
$totalDay=$rows['totalDay'];
echo "<tr><td>$boothAlias</td>";
for ($day2 = 1; $day2 <= $totalDay; ++$day2) {
echo "<td><input name='day2[]' type='checkbox' value='$day2' /></td>";
}
echo "</tr>";
}
echo "</table>";
}
}
?>
I think that SET type would be good solution for this.
http://dev.mysql.com/doc/refman/5.0/en/set.html

Categories