Jump to content

MartynLearnsPHP

Members
  • Posts

    56
  • Joined

  • Last visited

Everything posted by MartynLearnsPHP

  1. I don't get what's hard to follow. All there is here is a form and the code to process the form.
  2. Thanks, ginerjm. I've shared too much unnecessary code. I hope this simplifies things. $q has been acquired from a previous form to determine which project we are updating permissions for (ie. budgets, epenses, invites, transport, etc). So I GET $q to determine which project we are updating. With this project selected, the user gets a list of the Members within the project in order to update whether they have permission to view this project. If I am just looking at the budget project, the relevant part of this form is below: <?php require 'core/init.php'; $adminid = $user->data() ->id; if(isset($_GET['q'])) { $q = html_entity_decode($_GET['q']); echo "<form action='permissionupdate.php' method='post'>"; if ($q==="budget") { <h6>Managing Budgets</h6> $query = DB::getInstance()->query("SELECT * FROM members WHERE adminid=$adminid"); foreach($query->results() as $row){ echo "<input type='checkbox' id='" . $row->id . "' name='budget[]' value='1'"; if($row->$q==="1") {echo "checked";} else {echo "";} echo "> <input type='hidden' name='id[]' value='" .$row->id . "'> <input type='hidden' name='token' value='"; if(isset($token)) {echo $token; } else {echo $token = Token::generate();} echo "'>" . $row->member_first_name . " " . $row->member_last_name . ""; } } echo "<input type='submit' value='Update' name='project-update'> </form>"; } This form is then processed with the following php code: if (is_array($_POST['project-update'])){ if(is_array($_POST['id'])) { foreach ($_POST['id'] as $index => $id){ if(Token::check(Input::get('token'))) { $db = DB::getInstance(); if(is_array($_POST['budget'])) { $sql = "UPDATE `members` SET `" . $_POST['budget'][$index] . " WHERE `id`='" . $id . "'"; $memberUpdate = $db->query($sql); } ////Similar code for expense, invites, etc would be here in case Get_$ had been those values//// } } Redirect::to('permissionupdate.php'); } } } I hope I've made things a bit clearer.
  3. Hi. Whilst I keep ploughing through the internet in search of tutorials/examples, can anyone see an obvious flaw in my coding because this is the first time that I have tried to do this and it's doing my noggin' in. In essence, I am trying to create a form where an Admin User, once logged in, will get a list of all the projects associated to the event that they are organising (ie. budgets, expenses, table plan, food, drink, etc.). Once they have selected the project they will get a list of all their attendees/members with a view of which members have been granted permission to contribute to this project and, with checkboxes, edit the list of members by authorising or withdrawing project permissions. My current coding is: The Form to Select the Project (which works just fine) is:: <h3>Update Project Permissions</h3> <form action="" method="post" class="form-horizontal wb-form wb-new-reg"> <fieldset> <h6>Please select a Project</h6> <select name="projectmembers" onChange="showGlobalProject(this.value)"> <option value="">Select a Project</option> <option value="budget">Managing Budgets</option> <option value="expense">Managing Expenses</option> <option value="invites">Guest Invites</option> <option value="transport">Transport</option> <option value="food">Food</option> <option value="drink">Drink</option> <option value="tableplan">Table Plan</option> <option value="entertainment">Entertainment</option> <option value="other">Any Other Items</option> </select> </form> <script src="js/globalprojects.js"></script> <div id="txtGlobalProjects"></div> The Form which is then displayed (based on the above Project Selection Form and where $q represents the selected project is: <?php require 'core/init.php'; $adminid = $user->data() ->id; if(isset($_GET['q'])) { $q = html_entity_decode($_GET['q']); echo "<form action='permissionupdate.php' method='post'>"; if ($q==="budget") { <h6>Managing Budgets</h6> $query = DB::getInstance()->query("SELECT * FROM members WHERE adminid=$adminid"); foreach($query->results() as $row){ echo "<input type='checkbox' id='" . $row->id . "' name='budget[]' value='1'"; if($row->$q==="1") {echo "checked";} else {echo "";} echo "> <input type='hidden' name='id[]' value='" .$row->id . "'> <input type='hidden' name='token' value='"; if(isset($token)) {echo $token; } else {echo $token = Token::generate();} echo "'>" . $row->member_first_name . " " . $row->member_last_name . ""; } } if ($q==="expense") { <h6>Managing Expenses</h6> $query = DB::getInstance()->query("SELECT * FROM members WHERE adminid=$adminid"); foreach($query->results() as $row){ echo "<input type='checkbox' id='" . $row->id . "' name='expense[]' value='1'"; if($row->$q==="1") {echo "checked";} else {echo "";} echo "> <input type='hidden' name='id[]' value='" .$row->id . "'> <input type='hidden' name='token' value='"; if(isset($token)) {echo $token; } else {echo $token = Token::generate();} echo "'>" . $row->member_first_name . " " . $row->member_last_name . ""; } } if ($q==="invites") { <h6>Managing Budgets</h6> $query = DB::getInstance()->query("SELECT * FROM members WHERE adminid=$adminid"); foreach($query->results() as $row){ echo "<input type='checkbox' id='" . $row->id . "' name='invites[]' value='1'"; if($row->$q==="1") {echo "checked";} else {echo "";} echo "> <input type='hidden' name='id[]' value='" .$row->id . "'> <input type='hidden' name='token' value='"; if(isset($token)) {echo $token; } else {echo $token = Token::generate();} echo "'>" . $row->member_first_name . " " . $row->member_last_name . ""; } } if ($q==="transport") { <h6>Transport</h6> $query = DB::getInstance()->query("SELECT * FROM members WHERE adminid=$adminid"); foreach($query->results() as $row){ echo "<input type='checkbox' id='" . $row->id . "' name='transport[]' value='1'"; if($row->$q==="1") {echo "checked";} else {echo "";} echo "> <input type='hidden' name='id[]' value='" .$row->id . "'> <input type='hidden' name='token' value='"; if(isset($token)) {echo $token; } else {echo $token = Token::generate();} echo "'>" . $row->member_first_name . " " . $row->member_last_name . ""; } } if ($q==="food") { <h6>Food</h6> $query = DB::getInstance()->query("SELECT * FROM members WHERE adminid=$adminid"); foreach($query->results() as $row){ echo "<input type='checkbox' id='" . $row->id . "' name='food[]' value='1'"; if($row->$q==="1") {echo "checked";} else {echo "";} echo "> <input type='hidden' name='id[]' value='" .$row->id . "'> <input type='hidden' name='token' value='"; if(isset($token)) {echo $token; } else {echo $token = Token::generate();} echo "'>" . $row->member_first_name . " " . $row->member_last_name . ""; } } if ($q==="drink") { <h6>Drink</h6> $query = DB::getInstance()->query("SELECT * FROM members WHERE adminid=$adminid"); foreach($query->results() as $row){ echo "<input type='checkbox' id='" . $row->id . "' name='drink[]' value='1'"; if($row->$q==="1") {echo "checked";} else {echo "";} echo "> <input type='hidden' name='id[]' value='" .$row->id . "'> <input type='hidden' name='token' value='"; if(isset($token)) {echo $token; } else {echo $token = Token::generate();} echo "'>" . $row->member_first_name . " " . $row->member_last_name . ""; } } if ($q==="tableplan") { <h6>Table Plan</h6> $query = DB::getInstance()->query("SELECT * FROM members WHERE adminid=$adminid"); foreach($query->results() as $row){ echo "<input type='checkbox' id='" . $row->id . "' name='tableplan[]' value='1'"; if($row->$q==="1") {echo "checked";} else {echo "";} echo "> <input type='hidden' name='id[]' value='" .$row->id . "'> <input type='hidden' name='token' value='"; if(isset($token)) {echo $token; } else {echo $token = Token::generate();} echo "'>" . $row->member_first_name . " " . $row->member_last_name . ""; } } if ($q==="entertainment") { <h6>Entertainment</h6> $query = DB::getInstance()->query("SELECT * FROM members WHERE adminid=$adminid"); foreach($query->results() as $row){ echo "<input type='checkbox' id='" . $row->id . "' name='entertainment[]' value='1'"; if($row->$q==="1") {echo "checked";} else {echo "";} echo "> <input type='hidden' name='id[]' value='" .$row->id . "'> <input type='hidden' name='token' value='"; if(isset($token)) {echo $token; } else {echo $token = Token::generate();} echo "'>" . $row->member_first_name . " " . $row->member_last_name . ""; } } if ($q==="other") { <h6>Any Other Items</h6> $query = DB::getInstance()->query("SELECT * FROM members WHERE adminid=$adminid"); foreach($query->results() as $row){ echo "<input type='checkbox' id='" . $row->id . "' name='other[]' value='1'"; if($row->$q==="1") {echo "checked";} else {echo "";} echo "> <input type='hidden' name='id[]' value='" .$row->id . "'> <input type='hidden' name='token' value='"; if(isset($token)) {echo $token; } else {echo $token = Token::generate();} echo "'>" . $row->member_first_name . " " . $row->member_last_name . ""; } } echo "<input type='submit' value='Update' name='project-update'> </form>"; } And my php to process the form (which I guess is where my issue is, is: if (is_array($_POST['project-update'])){ if(is_array($_POST['id'])) { foreach ($_POST['id'] as $index => $id){ if(Token::check(Input::get('token'))) { $db = DB::getInstance(); if(is_array($_POST['budget'])) { $sql = "UPDATE `members` SET `" . $_POST['budget'][$index] . " WHERE `id`='" . $id . "'"; $memberUpdate = $db->query($sql); } if(is_array($_POST['expense'])) { $sql = "UPDATE `members` SET `expense`=? WHERE `id` = ?"; $memberUpdate = $db->query($sql, array($_POST['expense'][$index],$id)); } if(is_array($_POST['invites'])) { $sql = "UPDATE `members` SET `invites`=? WHERE `id` = ?"; $memberUpdate = $db->query($sql, array($_POST['invites'][$index],$id)); } if(is_array($_POST['transport'])) { $sql = "UPDATE `members` SET `transport`=? WHERE `id` = ?"; $memberUpdate = $db->query($sql, array($_POST['transport'][$index],$id)); } if(is_array($_POST['food'])) { $sql = "UPDATE `members` SET `food`=? WHERE `id` = ?"; $memberUpdate = $db->query($sql, array($_POST['food'][$index],$id)); } if(is_array($_POST['drink'])) { $sql = "UPDATE `members` SET `drink`=? WHERE `id` = ?"; $memberUpdate = $db->query($sql, array($_POST['drink'][$index],$id)); } if(is_array($_POST['tableplan'])) { $sql = "UPDATE `members` SET `tableplan`=? WHERE `id` = ?"; $memberUpdate = $db->query($sql, array($_POST['tableplan'][$index],$id)); } if(is_array($_POST['entertainment'])) { $sql = "UPDATE `members` SET `entertainment`=? WHERE `id` = ?"; $memberUpdate = $db->query($sql, array($_POST['entertainment'][$index],$id)); } if(is_array($_POST['other'])) { $sql = "UPDATE `members` SET `other`=? WHERE `id` = ?"; $memberUpdate = $db->query($sql, array($_POST['other'][$index],$id)); } } Redirect::to('permissionupdate.php'); } } } I appreciate that I can cut down a lot of code on the 2nd bit above, but I thought I'd focus on trying to get it to work before doing that. Any help on spotting an obvious mistake or drawing my attention to the bit of code that I should be focusing on would be very much appreciated.
  4. Aha! I've found it! I knew it was going to be a schoolboy error but it's taken me about 3 weeks to find it! I've used normal apostrophes for the SET adminid instead of using the backward tick.
  5. Sorry. The html/php flipping is just cutting the form down to the relevant elements to post here. Using Psycho's debugging code (sligthty adapted to suit my form as follows: if (!empty($_POST['position-guests'])) { if(!Input::exists()) { echo "Error: Input does not exist."; } else { if(!Token::check(Input::get('token'))) { echo "Error: Token check failed."; } else { $db = DB::getInstance(); $sql = "UPDATE `guests` SET `admin` = ?, 'adminid' = ?, `tableposition` = ?, `seat` = ? WHERE `id` = ?"; $guestUpdate = $db->query($sql, array( $_POST['admin'], $_POST['adminid'], $_POST['tableposition1'], $_POST['seat1'], $_POST['id1'] )); if(!$guestUpdate) { echo "Error: Guest update failed."; } else { Redirect::to('membertableguests.php'); } } } } else { echo "Error: No POST data provided"; } It appears that my form just isn't submitting because I am getting the following: "Error: No POST data provided validate" I'm completely at a loss as to why the form isn't submitting the information. If I echo out $_POST['admin'], $_POST['adminid'], $_POST['tableposition1'], $_POST['seat1'], $_POST['id1'] it does give me the right information that was submitted in the form.
  6. Hi. I am trying to write an "update" form and I'm sure that I have done it correctly, but it's just not working. I've spent days staring at the code and trying to tweak it. Can anyone else see what I have missed? The form is: <form action='membertableguests.php' method='post'> <input type='hidden' name='admin' value='{$admin}'> <input type='hidden' name='adminid' value='{$adminid}'> <input type='hidden' name='tableposition1' value='{$q}'> <input type='hidden' name='seat1' value='1'> <input type='hidden' name='token' value='" .Token::generate(). "'> <input type='submit' value='Submit Seating Update' name='position-guests'> <select name='id1'> <option value=''>-Please Select a Guest-</option>"; $guest = "SELECT id, firstname, lastname FROM guests WHERE adminid='{$adminid}' && invite='Yes' && attend!='No' ORDER BY lastname, firstname"; $guestquery = DB::getInstance()->query($guest); foreach ($guestquery->results() as $guestresults) { echo "<option value='" . $guestresults->id . "'>" . $guestresults->firstname . " " . $guestresults->lastname . "</option>"; } </select> </form> And the Update php code is: if (!empty($_POST['position-guests'])) { if(Input::exists()) { if(Token::check(Input::get('token'))) { $db = DB::getInstance(); $sql = "UPDATE `guests` SET `admin` = ?, 'adminid' = ?, `tableposition` = ?, `seat` = ? WHERE `id` = ? "; $guestUpdate = $db->query($sql, array( $_POST['admin'], $_POST['adminid'], $_POST['tableposition1'], $_POST['seat1'], $_POST['id1'] )); Redirect::to('membertableguests.php'); } } } I've tried echoing out $admin, $adminid and $q and they are all correct. I'm simply asking here if anyone can spot an obvious mistake or typo that I have made in my code.
  7. Thanks, Ch0cu3r. That's opened my eyes. When I was previously echoing $q it was showing the table position, which is what I wanted, but but dumping the results it is showing results from my table database rather than my guests database so I can see that the problem is coming from the AJAX GET transfer of data which means that I now know where to start looking to try and resolve my issue. An analogy that I once heard and quite liked. "I now have a torch and know where to shine it rather than trying to fumble around in the dark."
  8. Sorry. I misunderstood your post. I thought you were suggesting an alternative line. I'll come back to that later then and first try to work out why $q isn't being recognised in my select query.
  9. OK. I'm just trying to break this all down so that I can rebuild from the bottom up. But one quick question. What reason could there be for... $seatnumbers = DB::getInstance()->query("SELECT * FROM guesttables WHERE adminid = '{$adminid}'"); foreach ($seatnumbers->results()as $seatresults) { if ($q=="positiontop1") { $seats=$seatresults->seattop1; } else { if ($q=="positiontop2") { $seats=$seatresults->seattop2; } else { if ($q=="positiontop3") { $seats=$seatresults->seattop3; } else { if ($q=="positiontop4") { $seats=$seatresults->seattop4; } else { if ($q=="position1") { $seats=$seatresults->seat1; } else { if ($q=="position2") { $seats=$seatresults->seat2; } else { if ($q=="position3") { $seats=$seatresults->seat3; } else { if ($q=="position4") { $seats=$seatresults->seat4; } else { if ($q=="position5") { $seats=$seatresults->seat5; } else { if ($q=="position6") { $seats=$seatresults->seat6; } else { if ($q=="position7") { $seats=$seatresults->seat7; } else { if ($q=="position8") { $seats=$seatresults->seat8; } else { if ($q=="position9") { $seats=$seatresults->seat9; } else { if ($q=="position10") { $seats=$seatresults->seat10; }}}}}}}}}}}}}}}}} outputing an answer whereas $seatnumbers = DB::getInstance()->query("SELECT * FROM guesttables WHERE adminid = '{$adminid}'"); foreach ($seatnumbers->results()as $seatresults) { $seats=$seatresults->seat[$q]; } does not?
  10. There is only ever one row per adminid. I think my database is fairly simple in it's design. In the guests database which I am trying to select from the columns are simply: id firstname lastname admin adminid table seat So I am just trying to select from the table where the adminid = that one row and the table = the selected table. My previous query was on a much more complicated private messaging system which is why that got over complicated - but as far as I can see this one should be quite straight forward - if only I could understand why $q isn't being recognised as a search option.
  11. Thanks for the input Ch0cu3r and Barand. You've unearthed a problem that I hadn't yet encountered with the '==' issue. And I can see the benefit of using an array and that is something that I will definitely come back to and address, although I will need to go back and amend my database first because I have tried to simplify my code above by reducing it so that it is not unnecessrily long. Not all tables are called position1, position2, position3, etc (ie. there are 4 top table options and some side tables which I will need to rename for database purposes before I can use the array). EDIT: It occurred to me that I could implement Barand's suggestion as top tables are just positiontop1, positiontop2, etc and so the option codes could be top1, top2, etc so it would still apply. However after implementing that it is no longer working and giving me the number of seats allocated to a table. However, my primary issue at the moment is using $q to select from my guests database. That code just isn't recognising the table='$q' in: $seatedguests = DB::getInstance()->query("SELECT * FROM guests WHERE adminid='{$adminid}' && table='$q'");
  12. I am currently trying to write a page for people to log on and allocate guests to seats for their event. I am working on 3 files. The main page whereby they select the table that they want to allocate guests to, a js file and a php file which takes the selected table and allows the information to be managed. My main select a table page is set up so that the user only views the tables that they have chosen to use for their event and shows the name or number that they have allocated to that table. <form action="" method="post"> <label>Select Table</label> <select name="table guest" onChange="showUser(this.value)"> <option value="">-Please Select-</option> <?php $selectguest = DB::getInstance()->query("SELECT * FROM guesttables WHERE adminid='{$adminid}' && admin='{$admin}'"); foreach ($selectguest->results() as $selectguestresults) if ($selectguestresults->position1=="1") {echo "<option value ='position1'>" . $selectguestresults->name1 . "</option>";} if ($selectguestresults->position2=="1") {echo "<option value ='position2'>" . $selectguestresults->name2 . "</option>";} if ($selectguestresults->position3=="1") {echo "<option value ='position3'>" . $selectguestresults->name3 . "</option>";} if ($selectguestresults->position4=="1") {echo "<option value ='position4'>" . $selectguestresults->name4 . "</option>";} if ($selectguestresults->position5=="1") {echo "<option value ='position5'>" . $selectguestresults->name5 . "</option>";} if ($selectguestresults->position6=="1") {echo "<option value ='position6'>" . $selectguestresults->name6 . "</option>";} if ($selectguestresults->position7=="1") {echo "<option value ='position7'>" . $selectguestresults->name7 . "</option>";} if ($selectguestresults->position8=="1") {echo "<option value ='position8'>" . $selectguestresults->name8 . "</option>";} if ($selectguestresults->position9=="1") {echo "<option value ='position9'>" . $selectguestresults->name9 . "</option>";} if ($selectguestresults->position10=="1") {echo "<option value ='position10'>" . $selectguestresults->name10 . "</option>";} if ($selectguestresults->position11=="1") {echo "<option value ='position11'>" . $selectguestresults->name11 . "</option>";} if ($selectguestresults->position12=="1") {echo "<option value ='position12'>" . $selectguestresults->name12 . "</option>";} ?> </SELECT> </form> <script src="js/allocatetables.js"></script> <div id="txtALLOCATE"></div> My js file is: function showUser(str) { if (str=="") { document.getElementById("txtALLOCATE").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtALLOCATE").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","allocatetables.php?q="+str,true); xmlhttp.send(); } And my referenced php file is: <?php require 'core/memberinit.php'; $member = new Member(); $admin = $member->data() ->admin_username; $adminid = $member->data() ->adminid; if(isset($_GET['q'])) { $q = html_entity_decode($_GET['q']); $seatnumbers = DB::getInstance()->query("SELECT * FROM guesttables WHERE adminid = '{$adminid}'"); foreach ($seatnumbers->results()as $seatresults) { if ($q="position1") {$seats=$seatresults->seat1; } else { if ($q="position2") {$seats=$seatresults->seat2; } else { if ($q="position3") {$seats=$seatresults->seat3; } else { if ($q="position4") {$seats=$seatresults->seat4; } else { if ($q="position5") {$seats=$seatresults->seat5; } else { if ($q="position6") {$seats=$seatresults->seat6; } else { if ($q="position7") {$seats=$seatresults->seat7; } else { if ($q="position8") {$seats=$seatresults->seat8; } else { if ($q="position9") {$seats=$seatresults->seat9; } else { if ($q="position10") $seats=$seatresults->seat10; } else { if ($q="position11") {$seats=$seatresults->seat11; } else { if ($q="position12") {$seats=$seatresults->seat12; }}}}}}}}}}}}} $seatedguests = DB::getInstance()->query("SELECT * FROM guests WHERE adminid='{$adminid}' && table='$q'"); foreach ($seatedguests->results() as $seatedguestsresults) { echo "Guest: " . $seatedguestsresults->firstname . " " . $seatedguestsresults->lastname . " (Seat Number: " . $seatedguestsresults->seat . ")<br>"; } echo $q; echo "<br>"; echo $seats; } Obviously I have a lot more to write on my last page, but I am coming unstuck at the first hurdle. My echoed out $q is showing the correct reference (ie. position1, position2, etc) and $seats is showing the correct number of seats allocated to a table. However, my request to view guests seated at the table ($seatedguests) isn't recognising $q in the search option. I am sure this is a basic flaw in my knowledge, but I've spent nearly 2 weeks trying to get past this and I am at my wits end, so any help, prompting or suggestions on how I should be using $q to select the appropriate table would be very, very gratefully appreciated.
  13. Thanks, mac_gyver. That information is a huge help because it points me in the direction I should be going (or rather puts a big 'Road Closed' sign in the route that I was trying to follow). It's bedtime for me now, but tomorrow I will look at implementing a seperate "Select Search" where I don't group them and then cross reference originalid with the group search. If they match? Then that is the unique link that I am looking for and will hopefully give me the result that I need.
  14. Aha! I've made another small step forward. Not so much in resolving the problem, but in identifying the cause. I've tried echoing out all the results, and my code is identifying the first line in my database as the one to reference, whereas it will always be the last line that has not been read. So I need my "if" statement to select the last line in the search option. Anyone know how I can do this>
  15. OK. This is really starting to blow my mind. I have this lovely group of data that Groups all of the data into a nice column of discussions. As so: $query2 = DB::getInstance()->query("select c.id as cid, c.originalid, c.title, max(c.time) as timestamp, c.read1, c.read2, c.member1, c.member2, m.id as membersid, m.username, m.member_first_name, m.member_last_name from conversation as c, members as m where ((c.member1='{$memberid}' and c.removed1='No' and m.id=c.member2) or (c.member2='{$memberid}' and c.removed2='No' and m.id=c.member1)) group by c.originalid order by MAX(c.id) DESC"); foreach ($query2->results() as $result2) I then want that list to be echoed out so that a user can view the lists. And again, that is working fine. However, I want to have one argument that puts a "NEW" message next to any items on the list where the list contains one item that has ($results2->member1==$memberid && read1=='No') OR ($results2->member2 && read2=='No') within the group. But I just can't seem to get that argument working. Any suggestions?
  16. Aha! I think I've had a kind of breakthrough. I just need to figure out how to get around it. My code is currently producing a grouped result of messages within one subject matter. What I need to do is find out whether there is a single item within that group where either the condition if (($result2->member1=='$memberid' && $result2->read1=='No') || ($result2->member2=='$memberid' && $result2->read2=='No')) {echo "&nbsp<font color = #920505><b>NEW</b></font>";} is being met.
  17. $memberid is definitely correct. It is the id of the logged-in user and is used endlessly throughout the site. It is also used in the main $query2 select to identify all the messages for that member which is working correctly.
  18. Doublle == still isn't solving it. My latest effort, which still isn't working, is: if (($result2->member1==$memberid && $result2->read1=='No') || ($result2->member2==$memberid && $result2->read2=='No')) { echo "&nbsp<font color = #920505><b>NEW</b></font>"; } Just for a point of reference, if I replace the == with = throughout this whole bit of code, it puts the "NEW" message next to every discussion in the list.
  19. I'm afraid that wasn't the solution. Sorry, I had already done that but copied old text. That part of the equation should be: $query2 = DB::getInstance()->query("select c.id as cid, c.originalid, c.title, max(c.time) as timestamp, c.read1, c.read2, c.member1, c.member2, m.id as membersid, m.username, m.member_first_name, m.member_last_name from conversation as c, members as m where ((c.member1='{$memberid}' and c.removed1='No' and m.id=c.member2) or (c.member2='{$memberid}' and c.removed2='No' and m.id=c.member1)) group by c.originalid order by MAX(c.id) DESC"); foreach ($query2->results() as $result2) I am convinced that the error is in the line of code that reads: if ($result2->member1=$memberid and $result2->read1=='No') { echo "&nbsp<font color = #920505><b>NEW</b></font>"; } else { if ($result2->member2=$memberid and $result2->read2=='No') { echo "&nbsp<font color = #920505><b>NEW</b></font>"; } } But I can't figure out why that is.
  20. I have been working on a private message board, but have become unstuck with one small cosmetic detail. When someone receives a new message I can identify this on their page, but when they go to their message page I want them to be able to see which message is the new one (they might have 3 or 4 messages and so they will need to see which ones they have read as they go along. I am currently working with 2 databases to manage this. A 'members' which holds all the member information and 'conversation' which holds all the conversation dialogue. The conversation dialogue has the following columns: id: auto increment originalid: which holds the id reference from when the conversation was started so that all discussion in that conversation can be stringed together. The conversations need to be separated out because two members might have different discussion going on regarding different projects member1: who is the sender of the message member2: who is the message recipient title: which is the discussion subject matter read1: which shows whether member1 has read the message read2: which shows whether member2 has read the message message: which is obviously the body of the message sent removed1: if member1 deletes the message from the inbox removed2: if member2 deletes the message from their inbox timestamp: when posted I have a page whereby the member views their list of private discussion. From here they can click on the subject title to open the discussion thread in a side bar. It all works perfectly, except I want discussions with an unread message to state that they are new. My code is as follows, but the "NEW" tag isn't appearing beside discussions with unread messages in them. Can anyone see what I have done wrong? (for reference $memberid is the id of the logged in member). <div id="collapseInbox" class="inbox-cont panel-collapse collapse in"> <div class="panel-body"> <div class="inbox-main"> <?php $query2 = DB::getInstance()->query("select c.id as cid, c.originalid, c.title, max(c.time) as timestamp, m.id as membersid, m.username, m.member_first_name, m.member_last_name from conversation as c, members as m where ((c.member1='{$memberid}' and c.read1='Yes' and c.removed1='No' and m.id=c.member2) or (c.member2='{$memberid}' and c.read2='Yes' and c.removed2='No' and m.id=c.member1)) group by c.originalid order by MAX(c.id) DESC"); foreach ($query2->results() as $result2) { echo "<div class='inbox-message'> <span class='inbox-from'>" . htmlentities($result2->member_first_name) . " " . htmlentities($result2->member_last_name) . " (" . htmlentities($result2->username) . ") </span> <span class='inbox-title'> <form action='' method='post'> <input type='hidden' name='id' id='id' value='" . $result2->cid . "'> <a href='#$result2->cid' onClick='showMessages(" . $result2->cid . ")' data-toggle='tooltip' data-original-title='View message'>" . htmlentities($result2->title) . "</a>"; if ($result2->member1=='$memberid' && $result2->read1=='No') {echo "&nbsp<font color = #920505><b>NEW</b></font>"; } else { if ($result2->member2=='$memberid' && $result2->read2=='No') {echo "&nbsp<font color = #920505><b>NEW</b></font>";} } echo "</form> </span> <span class='inbox-date'>"; echo timeAgo(strtotime($result2->timestamp)); echo "</span> </div>"; } if ((intval($query1->count()==0)) && (intval($query2->count()==0))) { echo "<div class='inbox-message'> <span class='inbox-from'> You have no messages. </span> </div>"; } ?> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="js/messages.js"></script> </div> </div> </div>
  21. I need to embed 61 forms on a page which only become visible when a certain image is clicked on. Having these all one one page means that the page is very cumbersome, so I thought that the best way to move forward would be to have javascript against each of the images and, if clicked on, would call up a form from a different page in a pop-up window. I have historically used the following javascript to call up a form which is hidden in the page until required: Javascript: $(document).ready(function(){ $(function() { $("#dialog1").dialog({ autoOpen: false }); $("#button1").on("click", function() { $("#dialog1").dialog("open"); }); }); //validating Form Fields..... $("#submit1").click(function(e){ var seat1 = $("#seat1").val(); var name1 = $("#name1").val(); if( seat1 ==='' || name1 ==='') { alert("Please complete both fields"); e.preventDefault(); } else { alert("Table formatted successfully"); } }); }); HTML Script: <div id="dialog1" title="Table Format"> <form action="" method="post"> <label>Table Name:</label><br/> <input type="text" id="name1" name="name1"><br/> <label>Number of Seats:</label><br/> <select id="seat1" name='seat1'> <option value=''>---Please Select---</option> <option value='0'>0</option> <option value='1'>1</option> <option value='2'>2</option> <option value='3'>3</option> <option value='4'>4</option> <option value='5'>5</option> <option value='6'>6</option> <option value='7'>7</option> <option value='8'>8</option> <option value='9'>9</option> <option value='10'>10</option> <option value='11'>11</option> <option value='12'>12</option> <option value='13'>13</option> <option value='14'>14</option> <option value='15'>15</option> <option value='16'>16</option> <option value='17'>17</option> <option value='18'>18</option> <option value='19'>19</option> <option value='20'>20</option> <option value='21'>21</option> <option value='22'>22</option> <option value='23'>23</option> <option value='24'>24</option> </select><br/><br> <input type="hidden" name="id" value="<?php echo $tableid; ?>" > <input type="hidden" name="token" value="<?php if(isset($token)) {echo $token; else {echo $token = Token::generate(); } ?>" > <input type="submit" id="submit1" value="Submit" name="assign1" /> </form> I want to use this a similar script on a new page, but because it works with 61 different form instructions, I want to have the forms in seperate .php pages. So I have been trying to amend the Javascript to accomodate this. I have tried the following: Javascript: $(document).ready(function(){ $(function() { $("table1allocate.php").assign({ autoOpen: false }); $("#button1").on("click", function() { $("table1allocate.php").assign("open"); }); }); }); where table1allocate.php is a page with the following form: HTML: <?php require 'core/memberinit.php'; $member = new Member(); $admin = $member->data() ->admin_username; $adminid = $member->data() ->adminid; if(isset($_GET['x'])) { $x= html_entity_decode($_GET['x']); echo "<form action='allocatetables.php' method='post' title='Table Format'>"; $table = DB::GetInstance()->query("SELECT * FROM guesttables WHERE adminid = '{$adminid}' && position1 != '0'"); foreach ($table->results() as $tableresults); if ($tableresults->seat1 == '0') { echo "No guest numbers have been allocated to this table."; } else { if ($tableresults->seat1 >= '1') { echo "<label>Seat 1: &nbsp</label> <select name='guest1'> <option value='" . $tableresults->guest1 . "'>Please Select</option> <option value=''>Leave Seat Empty</option> "; $seat1query = DB::getInstance()->query("SELECT firstname, lastname, id FROM guests WHERE NOT EXISTS (SELECT guest1, guest2, guest3, guest4, guest5, guest6, guest7, guest8, guest9, guest10, guest11, guest12, guest13, guest14, guest15, guest16, guest17, guest18, guest19, guest20, guest21, guest22, guest23, guest24 FROM tableplan WHERE guests.id = guest1 || guests.id = guest2 || guests.id = guest3 || guests.id = guest4 || guests.id = guest5 || guests.id = guest6 || guests.id = guest7 || guests.id = guest8 || guests.id = guest9 || guests.id = guest10 || guests.id = guest11 || guests.id = guest12 || guests.id = guest13 || guests.id = guest14 || guests.id = guest15 || guests.id = guest16 || guests.id = guest17 || guests.id = guest18 || guests.id = guest19 || guests.id = guest20 || guests.id = guest21 || guests.id = guest22 || guests.id = guest23 || guests.id = guest24) && adminid = '{$adminid}' ORDER BY lastname, firstname"); foreach ($seat1query->results() as $seat1row) { echo "<option value=" . $seat1row->id . ">" . $seat1row->firstname . " " . $seat1row->lastname . "</option>"; } echo "</select><br><br>"; } else { echo "<input type='hidden' name='guest1' value=''>"; } if ($tableresults->seat2 >= '2') { echo " <label>Seat 2:</label> <select name='guest2'> <option value='" . $tableresults->guest2 . "'>Please Select</option> <option value=''>Leave Seat Empty</option> "; $seat2query = DB::getInstance()->query("SELECT firstname, lastname, id FROM guests WHERE NOT EXISTS (SELECT guest1, guest2, guest3, guest4, guest5, guest6, guest7, guest8, guest9, guest10, guest11, guest12, guest13, guest14, guest15, guest16, guest17, guest18, guest19, guest20, guest21, guest22, guest23, guest24 FROM tableplan WHERE guests.id = guest1 || guests.id = guest2 || guests.id = guest3 || guests.id = guest4 || guests.id = guest5 || guests.id = guest6 || guests.id = guest7 || guests.id = guest8 || guests.id = guest9 || guests.id = guest10 || guests.id = guest11 || guests.id = guest12 || guests.id = guest13 || guests.id = guest14 || guests.id = guest15 || guests.id = guest16 || guests.id = guest17 || guests.id = guest18 || guests.id = guest19 || guests.id = guest20 || guests.id = guest21 || guests.id = guest22 || guests.id = guest23 || guests.id = guest24) && adminid = '{$adminid}' ORDER BY lastname, firstname"); foreach ($seat2query->results() as $seat2row) { echo "<option value=" . $seat2row->id . ">" . $seat2row->firstname . " " . $seat2row->lastname . "</option>"; } echo "</select><br><br>"; } else { echo "<input type='hidden' name='guest2' value=''>"; } if ($tableresults->seat3 >= '3') { echo " <label>Seat 3: &nbsp</label> <select name='guest3'> <option value='" . $tableresults->guest3 . "'>Please Select</option> <option value=''>Leave Seat Empty</option> "; $seat3query = DB::getInstance()->query("SELECT firstname, lastname, id FROM guests WHERE NOT EXISTS (SELECT guest1, guest2, guest3, guest4, guest5, guest6, guest7, guest8, guest9, guest10, guest11, guest12, guest13, guest14, guest15, guest16, guest17, guest18, guest19, guest20, guest21, guest22, guest23, guest24 FROM tableplan WHERE guests.id = guest1 || guests.id = guest2 || guests.id = guest3 || guests.id = guest4 || guests.id = guest5 || guests.id = guest6 || guests.id = guest7 || guests.id = guest8 || guests.id = guest9 || guests.id = guest10 || guests.id = guest11 || guests.id = guest12 || guests.id = guest13 || guests.id = guest14 || guests.id = guest15 || guests.id = guest16 || guests.id = guest17 || guests.id = guest18 || guests.id = guest19 || guests.id = guest20 || guests.id = guest21 || guests.id = guest22 || guests.id = guest23 || guests.id = guest24) && adminid = '{$adminid}' ORDER BY lastname, firstname"); foreach ($seat3query->results() as $seat3row) { echo "<option value="; echo $seat3row->id; echo ">"; echo $seat3row->firstname; echo "&nbsp"; echo $seat3row->lastname; echo "</option>"; } echo "</select><br><br>"; } else { echo "<input type='hidden' name='guest3' value=''>"; } if ($tableresults->seat4 >= '4') { echo " <label>Seat 4: &nbsp</label> <select name='guest4'> <option value='" . $tableresults->guest4 . "'>Please Select</option> <option value=''>Leave Seat Empty</option> "; $seat4query = DB::getInstance()->query("SELECT firstname, lastname, id FROM guests WHERE NOT EXISTS (SELECT guest1, guest2, guest3, guest4, guest5, guest6, guest7, guest8, guest9, guest10, guest11, guest12, guest13, guest14, guest15, guest16, guest17, guest18, guest19, guest20, guest21, guest22, guest23, guest24 FROM tableplan WHERE guests.id = guest1 || guests.id = guest2 || guests.id = guest3 || guests.id = guest4 || guests.id = guest5 || guests.id = guest6 || guests.id = guest7 || guests.id = guest8 || guests.id = guest9 || guests.id = guest10 || guests.id = guest11 || guests.id = guest12 || guests.id = guest13 || guests.id = guest14 || guests.id = guest15 || guests.id = guest16 || guests.id = guest17 || guests.id = guest18 || guests.id = guest19 || guests.id = guest20 || guests.id = guest21 || guests.id = guest22 || guests.id = guest23 || guests.id = guest24) && adminid = '{$adminid}' ORDER BY lastname, firstname"); foreach ($seat4query->results() as $seat4row) { echo "<option value="; echo $seat4row->id; echo ">"; echo $seat4row->firstname; echo "&nbsp"; echo $seat4row->lastname; echo "</option>"; } echo "</select><br><br>"; } else { echo "<input type='hidden' name='guest4' value=''>"; } if ($tableresults->seat5 >= '5') { echo " <label>Seat 5: &nbsp</label> <select name='guest5'> <option value='" . $tableresults->guest5 . "'>Please Select</option> <option value=''>Leave Seat Empty</option> "; $seat5query = DB::getInstance()->query("SELECT firstname, lastname, id FROM guests WHERE NOT EXISTS (SELECT guest1, guest2, guest3, guest4, guest5, guest6, guest7, guest8, guest9, guest10, guest11, guest12, guest13, guest14, guest15, guest16, guest17, guest18, guest19, guest20, guest21, guest22, guest23, guest24 FROM tableplan WHERE guests.id = guest1 || guests.id = guest2 || guests.id = guest3 || guests.id = guest4 || guests.id = guest5 || guests.id = guest6 || guests.id = guest7 || guests.id = guest8 || guests.id = guest9 || guests.id = guest10 || guests.id = guest11 || guests.id = guest12 || guests.id = guest13 || guests.id = guest14 || guests.id = guest15 || guests.id = guest16 || guests.id = guest17 || guests.id = guest18 || guests.id = guest19 || guests.id = guest20 || guests.id = guest21 || guests.id = guest22 || guests.id = guest23 || guests.id = guest24) && adminid = '{$adminid}' ORDER BY lastname, firstname"); foreach ($seat5query->results() as $seat5row) { echo "<option value="; echo $seat5row->id; echo ">"; echo $seat5row->firstname; echo "&nbsp"; echo $seat5row->lastname; echo "</option>"; } echo "</select><br><br>"; } else { echo "<input type='hidden' name='guest5' value=''>"; } if ($tableresults->seat6 >= '6') { echo " <label>Seat 6: &nbsp</label> <select name='guest6'> <option value='" . $tableresults->guest6 . "'>Please Select</option> <option value=''>Leave Seat Empty</option> "; $seat6query = DB::getInstance()->query("SELECT firstname, lastname, id FROM guests WHERE NOT EXISTS (SELECT guest1, guest2, guest3, guest4, guest5, guest6, guest7, guest8, guest9, guest10, guest11, guest12, guest13, guest14, guest15, guest16, guest17, guest18, guest19, guest20, guest21, guest22, guest23, guest24 FROM tableplan WHERE guests.id = guest1 || guests.id = guest2 || guests.id = guest3 || guests.id = guest4 || guests.id = guest5 || guests.id = guest6 || guests.id = guest7 || guests.id = guest8 || guests.id = guest9 || guests.id = guest10 || guests.id = guest11 || guests.id = guest12 || guests.id = guest13 || guests.id = guest14 || guests.id = guest15 || guests.id = guest16 || guests.id = guest17 || guests.id = guest18 || guests.id = guest19 || guests.id = guest20 || guests.id = guest21 || guests.id = guest22 || guests.id = guest23 || guests.id = guest24) && adminid = '{$adminid}' ORDER BY lastname, firstname"); foreach ($seat6query->results() as $seat6row) { echo "<option value="; echo $seat6row->id; echo ">"; echo $seat6row->firstname; echo "&nbsp"; echo $seat6row->lastname; echo "</option>"; } echo "</select><br><br>"; } else { echo "<input type='hidden' name='guest6' value=''>"; } if ($tableresults->seat7 >= '7') { echo " <label>Seat 7: &nbsp</label> <select name='guest7'> <option value='" . $tableresults->guest7 . "'>Please Select</option> <option value=''>Leave Seat Empty</option> "; $seat7query = DB::getInstance()->query("SELECT firstname, lastname, id FROM guests WHERE NOT EXISTS (SELECT guest1, guest2, guest3, guest4, guest5, guest6, guest7, guest8, guest9, guest10, guest11, guest12, guest13, guest14, guest15, guest16, guest17, guest18, guest19, guest20, guest21, guest22, guest23, guest24 FROM tableplan WHERE guests.id = guest1 || guests.id = guest2 || guests.id = guest3 || guests.id = guest4 || guests.id = guest5 || guests.id = guest6 || guests.id = guest7 || guests.id = guest8 || guests.id = guest9 || guests.id = guest10 || guests.id = guest11 || guests.id = guest12 || guests.id = guest13 || guests.id = guest14 || guests.id = guest15 || guests.id = guest16 || guests.id = guest17 || guests.id = guest18 || guests.id = guest19 || guests.id = guest20 || guests.id = guest21 || guests.id = guest22 || guests.id = guest23 || guests.id = guest24) && adminid = '{$adminid}' ORDER BY lastname, firstname"); foreach ($seat7query->results() as $seat7row) { echo "<option value="; echo $seat7row->id; echo ">"; echo $seat7row->firstname; echo "&nbsp"; echo $seat7row->lastname; echo "</option>"; } echo "</select><br><br>"; } else { echo "<input type='hidden' name='guest7' value=''>"; } if ($tableresults->seat8 >= '8') { echo " <label>Seat 8: &nbsp</label> <select name='guest8'> <option value='" . $tableresults->guest8 . "'>Please Select</option> <option value=''>Leave Seat Empty</option> "; $seat8query = DB::getInstance()->query("SELECT firstname, lastname, id FROM guests WHERE NOT EXISTS (SELECT guest1, guest2, guest3, guest4, guest5, guest6, guest7, guest8, guest9, guest10, guest11, guest12, guest13, guest14, guest15, guest16, guest17, guest18, guest19, guest20, guest21, guest22, guest23, guest24 FROM tableplan WHERE guests.id = guest1 || guests.id = guest2 || guests.id = guest3 || guests.id = guest4 || guests.id = guest5 || guests.id = guest6 || guests.id = guest7 || guests.id = guest8 || guests.id = guest9 || guests.id = guest10 || guests.id = guest11 || guests.id = guest12 || guests.id = guest13 || guests.id = guest14 || guests.id = guest15 || guests.id = guest16 || guests.id = guest17 || guests.id = guest18 || guests.id = guest19 || guests.id = guest20 || guests.id = guest21 || guests.id = guest22 || guests.id = guest23 || guests.id = guest24) && adminid = '{$adminid}' ORDER BY lastname, firstname"); foreach ($seat8query->results() as $seat8row) { echo "<option value="; echo $seat8row->id; echo ">"; echo $seat8row->firstname; echo "&nbsp"; echo $seat8row->lastname; echo "</option>"; } echo "</select><br><br>"; } else { echo "<input type='hidden' name='guest8' value=''>"; } ?> But the pop up window isn't working and isn't bringing in the form from the other page. Any suggestions on what javascript I should be looking at to make the form on the other page appear in a pop-up window?
  22. Sorry. It won't let me edit my original post. For ease of viewing (ie. all as code rather than just half of it), the current code should read as: <script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['annotationchart']}]}"></script> <script type='text/javascript'> google.load('visualization', '1', {'packages':['annotationchart']}); google.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.DataTable(); data.addColumn('datetime', 'Date'); data.addColumn('number', 'Readings'); data.addColumn('string', 'Notes'); data.addRows([ <?php $annotate=DB::getInstance()->query("SELECT * FROM tabbyhealth WHERE reading!=0"); foreach ($annotate->results() as $annotateresults) { $date=date("Y, m, d",strtotime($annotateresults->timestamp)+18000); $reading=$annotateresults->reading; if($annotateresults->notes==""){ $notes="undefined"; } else { $notes=$annotateresults->notes; } echo "[new Date(".$date."), ".$reading.", ".$notes."],"; } ?> ]); var chart = new google.visualization.AnnotationChart(document.getElementById('chart_div_annotate')); var options = { displayAnnotations: true }; chart.draw(data, options); } </script>
  23. Following on from my problem with another Google Chart which jay0316 kindly helped with, I have another issue which I am hoping that someone might be able to help me with. I am trying to put together a site for my wife to manage her diabetes and insulin intake. We want to monitor her blood/sugar glucose over periods of time (but with notes that she includes that can help monitor reasons for outlying results such as illness), so I am trying to include a Google Annotation Chart to do this, drawing on blood/glucose readings stored in a Database. Where I am struggling at the moment is converting timestamps into information that I can include in the chart. What I currently have at the moment (which obviously isn't working) is: <script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['annotationchart']}]}"></script> <script type='text/javascript'> google.load('visualization', '1', {'packages':['annotationchart']}); google.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.DataTable(); data.addColumn('datetime', 'Date'); data.addColumn('number', 'Readings'); data.addColumn('string', 'Notes'); data.addRows([ <?php $annotate=DB::getInstance()->query("SELECT * FROM tabbyhealth WHERE reading!=0"); foreach ($annotate->results() as $annotateresults) { $date=date("Y, m, d",strtotime($annotateresults->timestamp)+18000); $reading=$annotateresults->reading; if($annotateresults->notes==""){ $notes="undefined"; } else { $notes=$annotateresults->notes; } echo "[new Date(".$date."), ".$reading.", ".$notes."],"; } ?> ]); var chart = new google.visualization.AnnotationChart(document.getElementById('chart_div_annotate')); var options = { displayAnnotations: true }; chart.draw(data, options); } </script> Any help is very gratefully received.
  24. Oh that works a treat. Thank you so much, Jay.
×
×
  • 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.