Jump to content

jacko_162

Members
  • Content Count

    405
  • Joined

  • Last visited

Community Reputation

0 Neutral

About jacko_162

  • Rank
    Advanced Member
  • Birthday 03/30/1984

Contact Methods

  • Website URL
    http://www.real-creative.co.uk

Profile Information

  • Gender
    Male
  • Location
    Staffordshire, United Kingdom

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. ok now i have the array as you said above using; <?php if ($result = $con->query("SELECT dateStart, dateEnd, name FROM eventsTest")) { $array = array(); while($row=mysqli_fetch_assoc($result)) { $array[$row['dateStart']][] = $row; } // DEBUG--- show all array data print "<pre>"; print_r($array); print "</pre>"; } ?> its now grouped my array by the dateStart Index, now im completely lost as to figuring out how to go about building out what day to show them on the calendar code.
  2. ok i have made my query and added it to an array and get the following array; Array ( [0] => Array ( [id] => 1 [dateStart] => 2018-12-26 [dateEnd] => 2018-12-26 [name] => Test Event 1 ) [1] => Array ( [id] => 2 [dateStart] => 2018-12-27 [dateEnd] => 2018-12-27 [name] => Test Event 2 ) [2] => Array ( [id] => 3 [dateStart] => 2018-12-28 [dateEnd] => 2018-12-28 [name] => Test Event 3 ) [3] => Array ( [id] => 4 [dateStart] => 2018-12-29 [dateEnd] => 2018-12-29 [name] => Test Event 4 ) ) but im struggling to figure out where and how in the calendar code to find the current day being displayed and to add in the event(s) matching that day in the array. here is my code so far; <?php if ($result = $con->query("SELECT * FROM eventsTest")) { $array = array(); while($row=mysqli_fetch_assoc($result)) { $array[]=$row; } print "<pre>"; print_r($array); print "</pre>"; // DEBUG--- show all array data } /* Set the default timezone */ date_default_timezone_set("Europe/London"); /* Set the date */ $date = strtotime(date("Y-m-d")); $day = date('d', $date); $month = date('m', $date); $year = date('Y', $date); $firstDay = mktime(0,0,0,$month, 1, $year); $title = strftime('%B', $firstDay); $dayOfWeek = date('D', $firstDay); $daysInMonth = cal_days_in_month(0, $month, $year); /* Get the name of the week days */ $timestamp = strtotime('next Sunday'); $weekDays = array(); for ($i = 0; $i < 7; $i++) { $weekDays[] = strftime('%a', $timestamp); $timestamp = strtotime('+1 day', $timestamp); } $blank = date('w', strtotime("{$year}-{$month}-01")); ?> <table class='table table-bordered' border=1 style="table-layout: fixed;"> <tr> <th colspan="7" class="text-center"> <?php echo $title ?> <?php echo $year ?> </th> </tr> <tr> <?php foreach($weekDays as $key => $weekDay) : ?> <td class="text-center"><?php echo $weekDay ?></td> <?php endforeach ?> </tr> <tr> <?php for($i = 0; $i < $blank; $i++): ?> <td></td> <?php endfor; ?> <?php for($i = 1; $i <= $daysInMonth; $i++): ?> <?php if($day == $i): ?> <td class='cal-today'><strong><?php echo $i ?></strong></td> <?php else: ?> <td><?php echo $i ?></td> <?php endif; ?> <?php if(($i + $blank) % 7 == 0): ?> </tr><tr> <?php endif; ?> <?php endfor; ?> <?php for($i = 0; ($i + $blank + $daysInMonth) % 7 != 0; $i++): ?> <td></td> <?php endfor; ?> </tr> </table>
  3. so its not completely impossible to use this code, thats good news. will start getting data now and report back if i have any problems.
  4. Has anyone done this before? i have the following VERY basic looking calendar to display the current month and <strong> on the current date; <?php /* Set the default timezone */ date_default_timezone_set("Europe/London"); /* Set the date */ $date = strtotime(date("Y-m-d")); $day = date('d', $date); $month = date('m', $date); $year = date('Y', $date); $firstDay = mktime(0,0,0,$month, 1, $year); $title = strftime('%B', $firstDay); $dayOfWeek = date('D', $firstDay); $daysInMonth = cal_days_in_month(0, $month, $year); /* Get the name of the week days */ $timestamp = strtotime('next Sunday'); $weekDays = array(); for ($i = 0; $i < 7; $i++) { $weekDays[] = strftime('%a', $timestamp); $timestamp = strtotime('+1 day', $timestamp); } $blank = date('w', strtotime("{$year}-{$month}-01")); ?> <table class='cal-table cal-table-bordered' border=1 style='table-layout: fixed;'> <tr> <th colspan='7' class='cal-text-center'> <?php echo $title ?> <?php echo $year ?> </th> </tr> <tr> <?php foreach($weekDays as $key => $weekDay) : ?> <td class='cal-text-center"'><?php echo $weekDay ?></td> <?php endforeach ?> </tr> <tr class='cal-row'> <?php for($i = 0; $i < $blank; $i++): ?> <td></td> <?php endfor; ?> <?php for($i = 1; $i <= $daysInMonth; $i++): ?> <?php if($day == $i): ?> <?php //database code here ?> <td><strong><?php echo $i ?></strong></td> <?php else: ?> <td><?php echo $i ?></td> <?php endif; ?> <?php if(($i + $blank) % 7 == 0): ?> </tr><tr class='cal-row'> <?php endif; ?> <?php endfor; ?> <?php for($i = 0; ($i + $blank + $daysInMonth) % 7 != 0; $i++): ?> <td></td> <?php endfor; ?> </tr> </table> how can i get data into this calendar from my 'events' table, to perhaps highlight the date of the event and show a hidden <DIV> when rollover. i have columns: 'eventStart' and 'eventEnd' and 'eventName' in the 'events' table. or shall i look for something else? this has to be super simple with no backend or multiple files being used etc.. thanks
  5. ok i figured it out, my INSERT query was in the LOOP!!!! so it ran the insert 3 times, hence the data being inserted for each submit. problem is now solved
  6. you are correct, it will keep getting the id from the query till the loop finishes. yeah i need the form to send the ID of each table so i can collect a list of who is attending the event, im storing this in another table so i can correlate the data between the 2x tabels. but if the user clicks attend on the top table i dont want the data being sent for the 2nd OR 3rd table. here is a visual representation of what i wanted to achieve:
  7. on the contrary i am answering the question..... unless you're attempting to be cryptic then i have no clue but as i said above, its looping the results and pulls the id from events table, and i assigned it to the $event_id variable, it then adds that into the eventssignup table, which is exactly as i want it to do.. but i only want the form to process the single table insert, not for all the looped results.
  8. $event_id = $row->id; its the ID of the event from the events table query at the top of the code.
  9. ok so $event_id is being set just under the While () loop $event_id = $row->id; and $userid is set in the session; $userid = $_SESSION['user_id']; (this isnt actually on the code i posted, apologies its in the header just under the include for the connection.php file
  10. there coming from the $_POST and are set variables, these arnt the problem as there being posted into the table correctly. but i did notice the event_id variable wasnt closed of correctly after you mentioned it. <?php if ($result = $con->query("SELECT * FROM events ORDER BY id ASC LIMIT 3")) { if ($result->num_rows > 0) { while ($row = $result->fetch_object()) { $event_id = $row->id; // set up table and echo data! echo "<table border='1' cellpadding='2' width='50%'>"; echo "<tr><td>"; echo "<p><img src='images/raid_banners/" . $row->bannerimg . "'>" . $row->name . " (iLvl: " . $row->itemlevel . ")</p>"; echo "<p>Event Starts: " . $row->datestart . " - " . $row->timestart . "</p>"; echo "<p>Event Ends: " . $row->dateend . " - " . $row->timeend . "</p>"; echo "<p>Raid Lead: " . $row->raidlead . "</p>"; echo "<form action='' name='$event_id' method='post'>"; // Process and populate SELECT form element echo "<select name=\"charname\">"; $sql = mysqli_query($con, "SELECT * FROM characters WHERE userid = $userid"); while ($row = $sql->fetch_assoc()){ echo "<option value=\"{$row['id']}\">{$row['charname']}</option>"; } echo "</select>"; echo "<input type='hidden' name='raidid' value ='$event_id'>"; echo "<input type='hidden' name='action' value='submit' />"; echo "<input type=\"submit\" name=\"submit\" value=\"going\">"; echo "<input type=\"submit\" name=\"submit\" value=\"notgoing\">"; echo "</form></td></tr></table><br><br>"; if(isset($_POST['action'])){ $charid = $_POST['charname']; $submit = $_POST['submit']; // Submit the data from dropdown in the form mysqli_query($con,"INSERT INTO eventsignup (eventid, charid, userid, status) VALUES ('$event_id', '$charid', '$userid', '$submit')"); } } } else { echo "No results to display!"; } } else { echo "Error: " . $con->error; } $con->close(); ?> this is where i am at now, but when i click on any button in each event table i get the following in table; let me know if this makes no sense as im not very good at explaining.
  11. So i have an event page where it will show the next 3 events, then i need logged in users to click either of two buttons to say there attending or not attending. i have the below code showing events, and the <form> and the submit and both buttons, but if i submit 1 button on event ID: 1 it inserts data into the database but for event ID: 2, and if i click the button on event ID :2 it also puts it into database with eventid:2 so no matter which event i click it seems to submit data with the latest event ID shown on page, and not for "each" event seperatly. i have moved the submit query everywhere around and still same results or duplicate results if its in the loop. i assume its looping the submit and only submitting the latests event ID. <?php if ($result = $con->query("SELECT * FROM events ORDER BY id ASC LIMIT 3")) { if ($result->num_rows > 0) { while ($row = $result->fetch_object()) { $event_id = $row->id; // set up table and echo data! echo "<table border='1' cellpadding='2' width='50%'>"; echo "<tr><td>"; echo "<p><img src='images/raid_banners/" . $row->bannerimg . "'>" . $row->name . " (iLvl: " . $row->itemlevel . ")</p>"; echo "<p>Event Starts: " . $row->datestart . " - " . $row->timestart . "</p>"; echo "<p>Event Ends: " . $row->dateend . " - " . $row->timeend . "</p>"; echo "<p>Raid Lead: " . $row->raidlead . "</p>"; echo "<form action='' name='$event_id' method='post'>"; // Process and populate SELECT form element echo "<select name=\"charname\">"; $sql = mysqli_query($con, "SELECT * FROM characters WHERE userid = $userid"); while ($row = $sql->fetch_assoc()){ echo "<option value=\"{$row['id']}\">{$row['charname']}</option>"; } echo "</select>"; echo "<input type='hidden' name='raidid' value ='$event_id'>"; echo "<input type='hidden' name='action' value='submit' />"; echo "<input type=\"submit\" name=\"submit\" value=\"going\">"; echo "<input type=\"submit\" name=\"submit\" value=\"notgoing\">"; echo "</form></td></tr></table><br><br>"; } if(isset($_POST['action'])){ $charid = $_POST['charname']; $submit = $_POST['submit']; // Submit the data from dropdown in the form mysqli_query($con,"INSERT INTO eventsignup (eventid, charid, userid, status) VALUES ('$event_id', '$charid', '$userid', '$submit')"); } } else { echo "No results to display!"; } } else { echo "Error: " . $con->error; } $con->close(); ?> any help would be awesome. im tearing my hair out here.
  12. i have the below code; // start of image upload $insert_id = mysql_insert_id() or die("Unable to get insert id for image name.<br>" . mysql_error()); extract($_POST); $fileArray = array(); $error=array(); $extension=array("jpeg","jpg","png","gif"); foreach($_FILES["files"]["tmp_name"] as $key=>$tmp_name) { $file_name=$_FILES["files"]["name"][$key]; $file_tmp=$_FILES["files"]["tmp_name"][$key]; $ext=pathinfo($file_name,PATHINFO_EXTENSION); if(in_array($ext,$extension)) { if(!file_exists("../images/listings/".$file_name)) { $filename=basename($file_name,$ext); $newFileName=$insert_id."_".mt_rand(1, 99999).".".$ext; move_uploaded_file($file_tmp=$_FILES["files"]["tmp_name"][$key],"../images/listings/".$newFileName); // NOW ADD NAME TO DATABASE $insertimg = "insert into $table3 (name,insert_id) values ('".$newFileName."','".$insert_id."')"; mysql_query($insertimg); array_push($fileArray, "$newFileName"); } else { $filename=basename($file_name,$ext); $newFileName=$filename.mt_rand(1, 99999).".".$ext; move_uploaded_file($file_tmp=$_FILES["files"]["tmp_name"][$key],"../images/listings/".$newFileName); // NOW ADD NAME TO DATABASE $insertimg = "insert into $table3 (name,insert_id) values ('".$newFileName."','".$insert_id."')"; mysql_query($insertimg); array_push($fileArray, "$newFileName"); } } else { $insertimg = "insert into $table3 (name,insert_id) values (' ','".$insert_id."')"; mysql_query($insertimg); array_push($error,"$file_name, "); } } // end of image upload I have managed to get this working fine, and it uploads the files and inserts data into a table. now i'm working on the edit page code and struggling to figure out how i can get this data down and display it, should i pull the data, echo the images and have some sort of IF statement to say if image exists then show a delete checkbox and if no image exists then show another file input? I'm also not sure if the add images code is the right way of doing it by adding the images to a separate line in the table or adding the array into the table for ease of use. i am not great at PHP and any help, or links to code would be great. Thanks
  13. ok so i worked out a JOIN query; SELECT c1.id AS parent, c1.view, c2.filename, c2.name, c2.id FROM category c1 INNER JOIN category c2 ON c1.id = c2.parent GROUP BY c2.name ORDER BY c1.id on my code on the page its indexing the category by subcategory but i cant get it to display the parent category name // pre-process the data and index it by category, creating an array of arrays with the main index being the category$data = array(); while($row = mysql_fetch_assoc($result)) { $data[$row['parent']][] = $row; } // produce the output from the data foreach($data as $category => $arr) { // Create a table with an id name of the category echo "<table width='100%' id='$category'>\n"; // Write the first row of the table - Category Title echo "<tr class='product-details'><td><span class='catTitle'>$category</span></td></tr></table><table width='100%' id='$category'>\n"; see image;
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.