Jump to content

MartynLearnsPHP

Members
  • Posts

    56
  • Joined

  • Last visited

Everything posted by MartynLearnsPHP

  1. Please ignore the previous post. It is incorrect but, for some reason, I can't edit or delete it. Sorry. Hi Jay, Thanks for your help. The jsfiddle example works a treat, so the coding is right, but I can't get it to pull in the recorded readings from the database. I'm making progress. I think my problem at the momentis trying to get a date on the bottom axis. If I use the database id, then it is working, it I use timestamp then it isn't. My working code using the table id is: google.load('visualization', '1.0', {'packages':['corechart']}); google.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.DataTable(); data.addColumn('number', ''); data.addColumn('number', 'Time of Reading'); data.addColumn('number', 'Blood Glucose Reading'); data.addRows([ <?php $level=DB::getInstance()->query("SELECT * FROM tabbyhealth WHERE reading!=0"); foreach ($level->results() as $levelresults) { echo "["; echo $levelresults->id; echo ","; echo date('H',strtotime($levelresults->timestamp) +18000); echo ","; echo $levelresults->reading; echo "],"; } ?> ]); var options = { title:'Blood Glucose Monitoring', curveType: 'function', legend: { position: 'bottom' }, width:600, height:300, hAxis: { title: 'Date' }, vAxis: { title: 'Reading and Time' } }; var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data, options); } My non-working table using timestamp is: google.load('visualization', '1.0', {'packages':['corechart']}); google.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.DataTable(); data.addColumn('number', ''); data.addColumn('number', 'Time of Reading'); data.addColumn('number', 'Blood Glucose Reading'); data.addRows([ <?php $level=DB::getInstance()->query("SELECT * FROM tabbyhealth WHERE reading!=0"); foreach ($level->results() as $levelresults) { echo "["; echo date('d M',strtotime($levelresults->timestamp) +18000); echo ","; echo date('H',strtotime($levelresults->timestamp) +18000); echo ","; echo $levelresults->reading; echo "],"; } ?> ]); var options = { title:'Blood Glucose Monitoring', curveType: 'function', legend: { position: 'bottom' }, width:600, height:300, hAxis: { title: 'Date' }, vAxis: { title: 'Reading and Time' } }; var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data, options); } Is there anyway to get the horizontal axis to show dates?
  2. Hi Jay, Thanks for your help. The jsfiddle example works a treat, so the coding is right, but I can't get it to pull in the recorded readings from the database. What I have currently got to is that I want a Line Chart which has the date along the bottom axis and the hour/readings along the vertical axis. Using your suggestions I have currently tried variations of the following, but without any success: Version 1: <script type="text/javascript"> google.load('visualization', '1.0', {'packages':['corechart']}); google.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.DataTable(); data.addColumn('number', ''); data.addColumn('number', 'Time of Reading'); data.addColumn('number', 'Blood Glucose Reading'); var rowData = [ <?php $level=DB::getInstance()->query("SELECT * FROM tabbyhealth WHERE reading!=0"); foreach ($level->results() as $levelresults) { $glucose = $levelresults->reading; $date = date('d M',strtotime($levelresults->timestamp) +18000); $timestamp = date('H',strtotime($levelresults->timestamp) +18000); echo "['".$timestamp."',".$glucose."],"; } ?> ]; var rowData = [ <?php $level=DB::getInstance()->query("SELECT * FROM tabbyhealth WHERE reading!=0"); foreach ($level->results() as $levelresults) { $date = date('d M',strtotime($levelresults->timestamp) +18000); $hour = date('H',strtotime($levelresults->timestamp) +18000); $glucose = $levelresults->reading; { echo "['".$date."','".$hour."',".$glucose."],"; } } ?> ]; data.addRows(rowData); var options = { title:'Blood Glucose Monitoring', curveType: 'function', legend: { position: 'bottom' }, width:600, height:300, hAxis: { title: 'Date' }, vAxis: { title: 'Reading and Time' } }; var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data, options); } </script> Version 2: google.load('visualization', '1.0', {'packages':['corechart']}); google.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.DataTable(); data.addColumn('number', ''); data.addColumn('number', 'Time of Reading'); data.addColumn('number', 'Blood Glucose Reading'); var rowData = [ <?php $level=DB::getInstance()->query("SELECT * FROM tabbyhealth WHERE reading!=0"); foreach ($level->results() as $levelresults) { $glucose = $levelresults->reading; $date = date('d M',strtotime($levelresults->timestamp) +18000); $timestamp = date('H',strtotime($levelresults->timestamp) +18000); echo "['".$timestamp."',".$glucose."],"; } ?> ]; var rowData = [ ]; data.addRows([ <?php $level=DB::getInstance()->query("SELECT * FROM tabbyhealth WHERE reading!=0"); foreach ($level->results() as $levelresults) { $date = date('d M',strtotime($levelresults->timestamp) +18000); $hour = date('H',strtotime($levelresults->timestamp) +18000); $glucose = $levelresults->reading; { echo "['".$date."','".$hour."',".$glucose."],"; } } ?> ]); var options = { title:'Blood Glucose Monitoring', curveType: 'function', legend: { position: 'bottom' }, width:600, height:300, hAxis: { title: 'Date' }, vAxis: { title: 'Reading and Time' } }; var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data, options); }
  3. My wife is a Type 1 diabetic and I am trying to put a site together where she can record her blood/glucose readings and analyse the readings. I am trying to use Google Charts to create a line graph so that she can see if their is a trend during the day when her blood sugar levels peak and trough. But my coding isn't providing any results. Can anyone see what I am doing wrong? <?php $level=DB::getInstance()->query("SELECT * FROM tabbyhealth WHERE reading!=0"); foreach ($level->results() as $levelresults) $glucose = $levelresults->reading; $timestamp = date('d M Y h.i A',strtotime($levelresults->timestamp) +18000); ?> <head> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> google.load('visualization', '1.0', {'packages':['corechart']}); google.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.DataTable(); data.addColumn('string', 'Time of Reading'); data.addColumn('number', 'Blood Glucose Reading'); data.addRows([ ['<?php echo $timestamp; ?>', '<?php echo $glucose; ?>'] ]); var options = { title:'Blood Glucose Monitoring', curveType: 'function', legend: { position: 'bottom' } width:600, height:300 hAxis: { title: 'Date/Time' }, vAxis: { title: 'Reading' } }; var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data, options); } </script> </head> <body> <div id="chart_div"></div> </body> I have even tried replacing data.addRows([ ['<?php echo $timestamp; ?>', '<?php echo $glucose; ?>'] ]); with data.addRows([ [0, 0, 0], [1, 10, 5], [2, 23, 15], [3, 17, 9], [4, 18, 10], [5, 9, 5], [6, 11, 3], [7, 27, 19], [8, 33, 25] ]); to see if it is just a problem with reading from my database, but I am still getting nothing - by nothing I mean that no chart is appearing.
  4. Aha! I've figured it out. Another of my table updates simply had... <input type="hidden" name="token" value="<?php echo Token::generate(); ?>" > whereas when there are more than form they all need to have... <input type="hidden" name="token" value="<?php if(isset($token)) { echo $token; } else { echo $token = Token::generate(); } ?>" > Thanks everyone for taking the time to look and help me out here.
  5. Right. The problem seems to be with my Check Token, which is coming up with a FALSE reading. Thanks for the help. At least I know where to look now, although I'm not sure why I have this problem because it is the exact code that I have been using on numerous scripts throughout my site.
  6. I'm using phpMyAdmin databases. My DB methods work - this is about the 30th different page that I have used them on and about the 100th different input form. Likewise, the inpu::exists() code is exactly the same as is used elsewhere on the page. The only thing I can imagine wrong is a typo, but like you say I just can't see where it could be. And I've been staring at this small bit of coding for 2 days now... EDIT: Sorry ch0cu3r - I posted before refreshing the page and seeing your post. I'll check that out now.
  7. I'm getting no errors. It's supposed to insert a new record into the progress table with the following columns being populated: admin, adminid, member, project, status and timestamp. At present? Nothing is happening. Nothing at all.
  8. I am trying to update task based progress updates. I've got a very simple database that needs to be updated with: Database name: progress 1. ID (auto increment) 2. admin (name of the project manager) 3. adminid (ID of the project manager in the project manager db) 4. member (name of the member of the project in the members db) 4. project (particular project being updated) 5. status (progress of the project as a number between 10 and 90) 6. timestamp I have the following php script update insert a new line into my progress table: if (!empty($_POST['progress'])) { if(Input::exists()) { if(Token::check(Input::get('token'))) { $adminprogress = Input::get('admin'); $adminidprogress = Input::get('adminid'); $memberprogress = Input::get('member'); $projectprogress = Input::get('project'); $statusprogress = Input::get('status'); $timestamp = date('Y-m-d H:i:s'); $progressupdate = DB::getInstance()->insert(progress, array( 'admin' => $adminprogress, 'adminid' => $adminidprogress, 'member' => $memberprogress, 'project' => $projectprogress, 'status' => $statusprogress, 'timestamp' => $timestamp )); Redirect::to('memberattire1.php'); } } } And I have the following code in the body of my page: <form method="post" action=""> <label> <select name="status"> <option value=choose>---Please Select---</option> <option value = "0">(10%) Bunker Registered</option> <option value = "10">(20%) First discussions held</option> <option value = "20">(30%) Initial research undertaken</option> <option value = "30">(40%) Ideas shared</option> <option value = "40">(50%) Enquiries made</option> <option value = "50">(60%) Results of enquiries shared</option> <option value = "60">(70%) Preferences shared</option> <option value = "70">(80%) Decisions made</option> <option value = "80">(90%) Decisions being executed</option> <option value = "90">(100%) Project Completed</option> </select> </label> <br><br> <input type="hidden" name="member" value="<?php echo $membername; ?>"> <input type="hidden" name="admin" value="<?php echo $admin; ?>"> <input type="hidden" name="adminid" value="<?php echo $adminid; ?>"> <input type="hidden" name="project" value="attire1"> <input type="hidden" name="token" value="<?php if(isset($token)) { echo $token; } else { echo $token = Token::generate(); } ?>" > <input type="submit" value="Submit Update" name="progress"> </form> I know my $membername, $admin and $adminid are ok because I can simply echo them out to confirm them, so there is something silly in my coding that I've overlooked. Can someone with a fresh pair of eyes see a typo or missed semi-colon or whatnot? Many thanks for any help.
  9. Fantastic. Amending my ORDER BY has resolved my problem. Thanks you guys. Your help is very much appreciated!
  10. Hi, I am trying to make a list of all countries listed in a database and the number of times they appear. But I am clearly doing something wrong as I am not able to list out the number of times that they appear. This is what I have got so far: <h4>Countries</h4> <table><col width='150px'><col width='150px'> <tr> <th> Country </th> <th> Number of Occurences </th> </tr> <?php $location = DB::getInstance()->query("SELECT country, COUNT(country) as countCountry FROM users GROUP BY country ORDER BY count DESC"); foreach ($location->results() as $locations) { echo "<tr><td>"; echo $locations->country; echo "</td><td>"; echo $locations->countCountry; echo "</td></tr>"; } ?> </table> Can anyone point me in the right direction?
  11. Yeah. I see that now. Two days lost trying to spot a missing comma.
  12. Please ignore the syntax error. I'm working on two computers and I mistyped when copying from one screen to the other. From what I can tell, these are the only changes that I made to the original script, but it is now working beautifully. That said, as I type this, I can see one other amendment that I've made - an inadvertent one - I missed out a comma after "SELECT c.id" on my initial coding.
  13. Well, I've managed to get it working. I don't know if it affected things, but putting `` marks round the table names and swaaping the JOIN 'ON' options around seems to have been the core to it. In case it helps anyone else in a similar position, my final working script was: $query = DB::getInstance()->query ("SELECT c.id, c.originalid, c.title, c.message, c.member1, c.member2, c.time, m1.id as id1, m1.member_first_name as firstname1, m1.member_last_name as lastname1, m1.iusername as username1, m2.id as id1, m2.member_first_name as firstname2, m2.member_last_name as lastname2, m2.iusername as username2 FROM `conversation` as c LEFT JOIN `members` as m1 ON m1.id=c.member1 LEFT JOIN `members` as m2 ON m2.id=c.member2 WHERE (c.cid=$q orc.originalid=$q) AND ((c.member1=$memberid AND c.removed1='NO') OR ((c.member2=$memberid AND c.removed2='NO'))) ORDER BY c.id");
  14. Sorry. I misunderstood what you were looking for. If I use the following query: $query = DB::getInstance()->query("SELECT id, originalid, message, member1, member2, removed1, removed2 FROM conversation WHERE (id=1 OR originalid=1)"); foreach ($query->results() as $result) { echo $result->id; echo $result->originalid; echo $result->member1; echo $result->member2; echo $result->removed1; echo $result->member2; echo $result->message; } I get the following result: 107669NoNoAre we on for curry night this week? Where: ID is "1" original ID is "0" member1 is "76" member 2 is "69" removed1 is "No" removed2 is "No" and message is "Are we on for curry night this week?"
  15. That is working. And if I swap 1 for $q, it brings in the respective information from my conversation table. So the problem is clearly with my select and joins. It even works with adding in the message and time columns. But I need the joins in order to get the user information from my members table.
  16. OK. I've been playing around with lots of different amendments, but without much luck, but it seems like nothing is being read from conversation table, and I just can't fathom out why. Even if I just echo out 'message' I get a blank result. Does anybody have any suggestions or point me to a resource that might be able to help me? Any help very gratefully received.
  17. $q and $memberid are working ok. $q is the conversation id value carried forward using Ajax and $memberid is the logged on user, I've echoed the string and everything seems to be working correctly. With the example that I am currently working on, I am getting the following result: SELECT c.id c.time as time, c.message as message, c.removed1, c.removed2, m1.member_first_name as firstname1, m1.member_last_name as lastname1, m1.username as username1, m2.member_first_name as firstname2, m2.member_last_name as lastname2, m2.username as username2 FROM conversation c LEFT JOIN members m1 ON c.member1=m1.id LEFT JOIN members m2 ON c.member2=m2.id WHERE (c.id=1 OR c.originalid=1) AND ((c.member1=76 AND c.removed1='No') OR (c.member2=76 AND c.removed2='No')) ORDER BY c.id Where $q is correctly showing as '1' which is the correct id of the message in my 'conversation' table that I have selected and '76' is the correct user id in my 'members' table.
  18. I am trying to join two tables but I am producing no results. I'm convinced that I have entered everything correctly, but clearly I haven't? Can anyone spot my mistake? <?php require 'core/memberinit.php'; $member = new Member(); include 'timeago.php'; $memberid = $member->data() ->id; if(isset($_GET['q'])) { $q = html_entity_decode($_GET['q']); $query2 = DB::getInstance()->query("SELECT c.id c.time as time, c.message as message, c.removed1, c.removed2, m1.member_first_name as firstname1, m1.member_last_name as lastname1, m1.username as username1, m2.member_first_name as firstname2, m2.member_last_name as lastname2, m2.username as username2 FROM conversation c LEFT JOIN members m1 ON c.member1=m1.id LEFT JOIN members m2 ON c.member2=m2.id WHERE (c.id=$q OR c.originalid=$q) AND ((c.member1=$memberid AND c.removed1='No') OR (c.member2=$memberid AND c.removed2='No')) ORDER BY c.id"); foreach ($query2->results() as $result2) { echo $result2->firstname1; echo $result2->lastname1; echo $result2->username1; echo timeAgo(strtotime($result2->time)); echo $result2->message; echo $result2->firstname2; echo $result2->lastname2; echo $result2->username2; } ?>
  19. CroNiX - I understand why you're frustrated with me. But you should understand what my learning curve has been. I've always loved the functionality of excel and writing great programmes for it. So, last Christmas my wife bought me a book called 'PHP & MySQL in easy steps' because she thought I would find the problem solving of writing a website fun. And I have. As a hobby I have been trying to write a website by coding from the ground up - no dreamweaver or such like, just self teaching of coding and css. This has progressed to using PHP and MySQL and I am only now venturing into using JQuery. So my intention is to learn this and implement it's powerful functions, but it is all a very steep learning curve and I am mostly relying on Google to find resources. But I will get there and, hopefully, one day it would be nice to be one of the people on here helping other people who are in the position that I am in today. With another Christmas fast approaching, can you recommend a good book to help me learn the intricacies of JQuery? Ch0cu3r - Awesome. Thank you. That works a treat.
  20. Thanks for that. It's definitely making a difference - namely I'm not getting a '0' or undefined value. However, the debug value is showing the id of the last message in the loop, rather than the ID for each individual message. I've amended my coding as follows: privatemessage.php <?php $query2 = DB::getInstance()->query("SELECT c.id as cid, c.title, c.time, 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 m.id ORDER BY m.id DESC"); ?> <table> <tr> <td align="left"> <?php echo htmlentities($result2->member_first_name); ?> <?php echo htmlentities($result2->member_last_name); ?> <?php echo "("; echo htmlentities($result2->username); echo ")"; ?> </td> <td align="right"> <?php echo timeAgo(strtotime($result2->time)); ?> </td> </tr> <tr> <td colspan="2" align="left"> <form action="" method="post"> <?php echo "Subject: "; ?> <?php echo "<input type='hidden' name='id' id='id' value='{$result2->cid}'>"; ?> <a href="#$result2->cid" onClick="showMessages()"><?php echo htmlentities($result2->title); ?> </form> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="js/readmessage.js"></script> </td> </tr> readmessage.js function showMessages() { // get the value of the value of id input var theId = document.getElementById('id').value; 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("txtMessage").innerHTML=xmlhttp.responseText; } } // for debug purposes only. Display the id being sent to readmessage.php alert("The ID pass to readmessage.php is: " + theId); xmlhttp.open("GET","readmessage.php?q="+theId,true); xmlhttp.send(); }
  21. Sorry, I initially posted this in the Ajax Help Thread, but thinking about it, I suspect this is a php query. I am trying to write a basic Private Messaging script. I have my main page which lists all messages that have been received. I then want to click on an href link to run an ajax query to bring information in from another .php file which shows the content of the selected message. But I can't fathom out how to do this with an href. First off, is it possible? If so, can anyone tell me what I am doing wrong? The relevant script is: privatemessage.php: <?php $query2 = DB::getInstance()->query("SELECT c.id as cid, c.title, c.time, 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 m.id ORDER BY m.id DESC"); ?> <table> <tr> <td align="left"> <?php echo htmlentities($result2->member_first_name); ?> <?php echo htmlentities($result2->member_last_name); ?> <?php echo "("; echo htmlentities($result2->username); echo ")"; ?> </td> <td align="right"> <?php echo timeAgo(strtotime($result2->time)); ?> </td> </tr> <tr> <td colspan="2" align="left"> <form action="" method="post"> <?php echo "Subject: "; ?> <?php echo "<input type='hidden' name='id' id='id' value='{$result2->cid}'>"; ?> <a href="#$result2->cid" onClick="showMessages(this.value)"><?php echo htmlentities($result2->title); ?> </form> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="js/readmessage.js"></script> </td> </tr> </table> <div id="txtMessage"></div> My readmessage.js code is: function showMessages(str) { if (str=="") { document.getElementById("txtMessage").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("txtMessage").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","readmessage.php?q="+str,true); xmlhttp.send(); } And my readmessage.php code is: ?php require 'core/memberinit.php'; $member = new Member(); include 'timeago.php'; $memberid = $member->data() ->id; if(isset($_GET['q'])) { $q = html_entity_decode($_GET['q']); $req1 = DB::getInstance()->query("SELECT title, member1, member2 FROM conversation WHERE id='{$q}' AND id2='1'"); foreach ($req1->results() as $dn1) if($req1->count()==1) { if(($dn1->member1=='{$memberid}') or ($dn->member2=='{$memberid}')) { if($dn1->member1=='{$memberid}') { DB::getInstance()->query("UPDATE conversation SET read1='Yes' where id='{$q}' and id2='1'"); $user_partic = 2; } else { DB::getInstance()->query("UPDATE conversation SET read2='Yes' where id='{$q}' and id2='1'"); $user_partic = "1"; } $req2 = DB::getInstance()->query("SELECT conversation.time, conversation.message, members.id as userid, members.username, members.member_first_name, members.member_last_name FROM conversation, members WHERE conversation.id='{$id}' AND members.id=conversation.member1 ORDER BY conversation.id2"); if(isset($_POST['message']) and $_POST['message']!='') { $message = $_POST['message']; if(get_magic_quotes_gpc()) { $message = stripslashes($message); } $message = $string(nl2br(htmlentities($message, ENT_QUOTES, 'UTF-8'))); if( DB::getInstance()->query("INSERT into conversation (id, id2, title, member1, member2, message, time, read1, read2) VALUES('{$q}', '{(intval($req2->id2)+1)}', '', '{$memberid}', '', '{$message}', '.time().', '', '')") and DB::getInstance()->query("UPDATE conversation SET read'{$user_partic}'='Yes' WHERE id='{$q}' AND id2='1'")); } echo "<h4>"; echo $dn1->title; echo "</h4><br><br>"; echo "<table><col width='150px'><col width='50px'><col width='150px'>"; echo "<tr><th>Member</th><th>&nbsp</th><th>Message</th></tr>"; foreach ($req2->results() as $dn2) { echo "<tr><td>"; echo $dn2->members.member_first_name; echo $dn2->members.member_last_name; echo " ("; echo $dn2->members.username; echo ") </td><td></td><td>"; echo timeAgo(strtotime($dn2->time)); echo "<br>"; echo $dn2->message; echo "</td></tr>"; } echo "</table>"; } } } ?> However, just to try and find where the error lies, I have tried the following code for my readmessage.php file: <?php require 'core/memberinit.php'; $member = new Member(); include 'timeago.php'; $memberid = $member->data() ->id; if(isset($_GET['q'])) { $q = intval($_GET['q']); echo $q; } ?> Which always returns a "0" reply - which says to me that my files are talking, but that the id isn't being carried across. Anybody got any suggestions? Many thanks for any help offered.
  22. I am trying to write a basic Private Messaging script. I have my main page which lists all messages that have been received. I then want to click on an href link to run an ajax query to bring information in from another .php file which shows the content of the selected message. But I can't fathom out how to do this with an href. First off, is it possible? If so, can anyone tell me what I am doing wrong? The relevant script is: privatemessage.php: <?php $query2 = DB::getInstance()->query("SELECT c.id as cid, c.title, c.time, 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 m.id ORDER BY m.id DESC"); ?> <table> <tr> <td align="left"> <?php echo htmlentities($result2->member_first_name); ?> <?php echo htmlentities($result2->member_last_name); ?> <?php echo "("; echo htmlentities($result2->username); echo ")"; ?> </td> <td align="right"> <?php echo timeAgo(strtotime($result2->time)); ?> </td> </tr> <tr> <td colspan="2" align="left"> <form action="" method="post"> <?php echo "Subject: "; ?> <?php echo "<input type='hidden' name='id' id='id' value='{$result2->cid}'>"; ?> <a href="#$result2->cid" onClick="showMessages(this.value)"><?php echo htmlentities($result2->title); ?> </form> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="js/readmessage.js"></script> </td> </tr> My readmessage.js code is: function showMessages(str) { if (str=="") { document.getElementById("txtMessage").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("txtMessage").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","readmessage.php?q="+str,true); xmlhttp.send(); } And my readmessage.php code is: <?php require 'core/memberinit.php'; $member = new Member(); include 'timeago.php'; $memberid = $member->data() ->id; if(isset($_GET['q'])) { $q = html_entity_decode($_GET['q']); $req1 = DB::getInstance()->query("SELECT title, member1, member2 FROM conversation WHERE id='{$q}' AND id2='1'"); foreach ($req1->results() as $dn1) if($req1->count()==1) { if(($dn1->member1=='{$memberid}') or ($dn->member2=='{$memberid}')) { if($dn1->member1=='{$memberid}') { DB::getInstance()->query("UPDATE conversation SET read1='Yes' where id='{$q}' and id2='1'"); $user_partic = 2; } else { DB::getInstance()->query("UPDATE conversation SET read2='Yes' where id='{$q}' and id2='1'"); $user_partic = "1"; } $req2 = DB::getInstance()->query("SELECT conversation.time, conversation.message, members.id as userid, members.username, members.member_first_name, members.member_last_name FROM conversation, members WHERE conversation.id='{$id}' AND members.id=conversation.member1 ORDER BY conversation.id2"); if(isset($_POST['message']) and $_POST['message']!='') { $message = $_POST['message']; if(get_magic_quotes_gpc()) { $message = stripslashes($message); } $message = $string(nl2br(htmlentities($message, ENT_QUOTES, 'UTF-8'))); if( DB::getInstance()->query("INSERT into conversation (id, id2, title, member1, member2, message, time, read1, read2) VALUES('{$q}', '{(intval($req2->id2)+1)}', '', '{$memberid}', '', '{$message}', '.time().', '', '')") and DB::getInstance()->query("UPDATE conversation SET read'{$user_partic}'='Yes' WHERE id='{$q}' AND id2='1'")); } echo "<h4>"; echo $dn1->title; echo "</h4><br><br>"; echo "<table><col width='150px'><col width='50px'><col width='150px'>"; echo "<tr><th>Member</th><th>&nbsp</th><th>Message</th></tr>"; foreach ($req2->results() as $dn2) { echo "<tr><td>"; echo $dn2->members.member_first_name; echo $dn2->members.member_last_name; echo " ("; echo $dn2->members.username; echo ") </td><td></td><td>"; echo timeAgo(strtotime($dn2->time)); echo "<br>"; echo $dn2->message; echo "</td></tr>"; } echo "</table>"; } } } ?> However, just to try and find where the error lies, I have tried the following code for my readmessage.php file: <?php require 'core/memberinit.php'; $member = new Member(); include 'timeago.php'; $memberid = $member->data() ->id; if(isset($_GET['q'])) { $q = intval($_GET['q']); echo $q; } ?> Which always returns a "0" reply - which says to me that my files are talking, but that the id isn't being carried across. Anybody got any suggestions? Many thanks for any help offered.
  23. I've cracked it! Thank you so much for your help, Barand. It seems like my problem was that I was so over complicating things. I realised that I don't need the count option (people prefer a facebook style private message style now rather than a subject discussion). The following code is working for me: $query1 = DB::getInstance()->query("select c.id, c.title, c.time, m.id as memberid, m.username, m.member_first_name, m.member_last_name from conversation as c, members as m where ((c.member1='{$logid}' and c.read1='No' and c.removed1='No' and m.id=c.member2) or (c.member2='{$logid}' and c.read2='No' and c.removed2='No' and m.id=c.member1)) group by m.id order by m.id desc"); $query2 = DB::getInstance()->query("select c.id, c.title, c.time, m.id as memberid, m.username, m.member_first_name, m.member_last_name from conversation as c, members as m where ((c.member1='{$logid}' and c.read1='Yes' and c.removed1='No' and m.id=c.member2) or (c.member2='{$logid}' and c.read2='Yes' and c.removed2='No' and m.id=c.member1)) group by m.id order by m.id desc");
  24. Sorry - I just realised that you were replying to my "45 years ago" comment from last night.
  25. Isn't that to be expected? If the date is a timestamp, there shouldn't be any zero or invalid dates.
×
×
  • 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.