Jump to content

ArizonaJohn

Members
  • Posts

    168
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

ArizonaJohn's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. Yes, some of the records can have the came points. If the records have the same points, I would want to sort them by title descending.
  2. On my web page, there is a variable called $submission. I would like to display exactly 11 rows from the query below: the row where $submission equals $row["title"], 5 rows above it, and 5 rows below it. All ranked by points descending. How can I do this? $sqlStr = "SELECT title, points, submissionid FROM submission ORDER BY points DESC"; $result = mysql_query($sqlStr); $arr = array(); $count=1; echo "<table class=\"samplesrec\">"; while ($row = mysql_fetch_array($result)) { echo '<tr >'; echo '<td>'.$count++.'.</td>'; echo '<td class="sitename1">'.$row["title"].'</td>'; echo '<td class="sitename2"><div class="pointlink2">'.number_format($row["points"]).'</div></td>'; echo '</tr>'; } echo "</table>";
  3. I would like to run a MySQL query each time a Facebook Like button is clicked on a page. I already know that FB.Event.subscribe('edge.create', function(response) {} is used to execute something when a Like button is clicked. My problem is that I don't know Javascript / AJAX. What simple Javascript/AJAX code that I can but in the curly brackets of the FB.event that will just run the MySQL query below? My understanding is that I might need to get some sort of JQuery library, which is fine. Thanks in advance, John The relevant code on the page: <script src="http://connect.facebook.net/en_US/all.js"></script> <?php session_start(); $uid = $_SESSION['loginid']; $_SESSION['submissionid'] = $submissionid; echo '<div id="fb-root"></div>'; echo "<script> window.fbAsyncInit = function() { FB.init({appId: 'your app id', status: true, cookie: true, xfbml: true}); }; (function() { var e = document.createElement('script'); e.async = true; e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; document.getElementById('fb-root').appendChild(e); }()); echo '</script>"; echo '<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">'; echo '<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="" send="true" layout="button_count" width="450" show_faces="false" font="arial"></fb:like>'; The MySQL query that I would like to run each time a Like button is clicked: mysql_query("INSERT INTO fblikes VALUES (NULL, '$submissionid', '$uid', NULL)");
  4. Hello, The query below works well. It pulls information from 3 MySQL tables: login, submission, and comment. It creates a value called totalScore2 based on calculation of values pulled from these three tables. The MySQL tables "comment" and "submission" both have the following fields: loginid submissionid In the table "submission," each "submissionid" has only one entry/row, and thus only one "loginid" associated with it. In the table "comment," the field "submissionid" could have several entries/rows, and could be associated with multiple "loginid"s. Each time one of the "submissionid"s in "comment" is associated with the same "loginid" that it has in the table "submission," I would like to add this as a factor to the equation below. I would like to multiple instances like this times (-10). How could I do this? Thanks in advance, John $sqlStr2 = "SELECT l.loginid, l.username, l.created, DATEDIFF(NOW(), l.created) + COALESCE(s.total, 0) * 5 + COALESCE(scs.total, 0) * 10 + COALESCE(c.total, 0) AS totalScore2 FROM login l LEFT JOIN ( SELECT loginid, COUNT(1) AS total FROM submission GROUP BY loginid ) s ON l.loginid = s.loginid LEFT JOIN ( SELECT loginid, COUNT(1) AS total FROM comment GROUP BY loginid ) c ON l.loginid = c.loginid LEFT JOIN ( SELECT S2.loginid, COUNT(1) AS total FROM submission S2 INNER JOIN comment C2 ON C2.submissionid = S2.submissionid GROUP BY S2.loginid ) scs ON scs.loginid = l.loginid GROUP BY l.loginid ORDER BY totalScore2 DESC LIMIT 25";
  5. When I do that, the URL is http://www.domain.com/hmm.php?url=68 . This URL shows up when I put the .htaccess file in the comments subdirectory. Does that provide any clues? I think my problem may have to do with trying to do this re-write in a subdirectory.
  6. Oh, okay. The URL did not change. It's still: http://www.domain.com/sample/comments/68 So does that mean that the section below is wrong? ^comments/([0-9]+)?$
  7. I did that and it's still giving the same 404 error as before: PAGE NOT FOUND We cannot locate the page you're looking for. Please check the address and make sure all letters are lowercased with no spaces. You may also move to a different page by using the links in the menu bar above.
  8. Okay, thanks. I added the R=302 to .htaccess. How do I use it to diagnose the attempted display page?
  9. Hmm... I tried that but it didn't work. Thanks, though.
  10. Hello, I am trying to re-write this: Into this: Here is what the .htaccess file looks like in both the directory represented by "sample" above and the directory "comments": RewriteEngine on RewriteRule ^comments/([0-9]+)?$ index.php?submissionid=$1 [NC,L] The first URL (http://www.domain.com/sample/comments/68) goes to a 404 error. I have checked, and mod_rewrite appears to be enabled. Also, when I manually enter the second URL, the correct page pulls up. Any idea why my the URL re-write is not working? Thanks in advance, John
  11. Hello, I am using the code below for a user login. The first I try to login after cache / cookies, etc. have been cleared, the browser refreshes and the user name is not logged in. After that, logging in works fine. Any idea how I can make it work the first time? Thanks in advance, John index.php: <?php if($_SERVER['REQUEST_METHOD'] == "POST"){header('Location: http://www...com/.../index.php?username='.$username.'&password='.$password.'');} require_once "header.php"; include "login.php"; require_once "footer.php"; ?> eader.php includes this: session_start(); login.php: <?php if (!isLoggedIn()) { if (isset($_POST['cmdlogin'])) { if (checkLogin($_POST['username'], $_POST['password'])) { show_userbox(); } else { echo "Incorrect Login information !"; show_loginform(); } } else { show_loginform(); } } else { show_userbox(); } ?> show_loginform function: function show_loginform($disabled = false) { echo '<form name="login-form" id="login-form" method="post" action="./index.php?'.$_SERVER['QUERY_STRING'].'"> <div class="usernameformtext"><label title="Username">Username: </label></div> <div class="usernameformfield"><input tabindex="1" accesskey="u" name="username" type="text" maxlength="30" id="username" /></div> <div class="passwordformtext"><label title="Password">Password: </label></div> <div class="passwordformfield"><input tabindex="2" accesskey="p" name="password" type="password" maxlength="15" id="password" /></div> <div class="registertext"><a href="http://www...com/.../register.php" title="Register">Register</a></div> <div class="lostpasswordtext"><a href="http://www...com/.../lostpassword.php" title="Lost Password">Lost password?</a></div> <p class="loginbutton"><input tabindex="3" accesskey="l" type="submit" name="cmdlogin" value="Login" '; if ($disabled == true) { echo 'disabled="disabled"'; } echo ' /></p></form>'; } here are the login credential check functions I'm using: <?php #### Login Functions ##### function isLoggedIn() { if (session_is_registered('loginid') && session_is_registered('username')) { return true; // the user is loged in } else { return false; // not logged in } return false; } function checkLogin($u, $p) { global $seed; // global because $seed is declared in the header.php file if (!valid_username($u) || !valid_password($p) || !user_exists($u)) { return false; // the name was not valid, or the password, or the username did not exist } //Now let us look for the user in the database. $query = sprintf(" SELECT loginid FROM login WHERE username = '%s' AND password = '%s' AND disabled = 0 AND activated = 1 LIMIT 1;", mysql_real_escape_string($u), mysql_real_escape_string(sha1($p . $seed))); $result = mysql_query($query); // If the database returns a 0 as result we know the login information is incorrect. // If the database returns a 1 as result we know the login was correct and we proceed. // If the database returns a result > 1 there are multple users // with the same username and password, so the login will fail. if (mysql_num_rows($result) != 1) { return false; } else { // Login was successfull $row = mysql_fetch_array($result); // Save the user ID for use later $_SESSION['loginid'] = $row['loginid']; // Save the username for use later $_SESSION['username'] = $u; // Now we show the userbox return true; } return false; } ?>
  12. Hello, I'm trying to use the code below to make the <a href='http://www...com/.../footervote.php'>Vote</a> link appear if a user logs in and a user shows up in the function getEditorsList(). The vote link only appears if the browser is refreshed. Any idea how I could make the vote link appear without having to refresh the browser? Thanks in advance, John index.php: <?php require_once "header.php"; //content include "login.php"; // more content require_once "footer.php"; ?> In header.php: <?php error_reporting(0); session_start(); require_once ('db_connect.inc.php'); require_once ("function.inc.php"); $seed="0dAfghRqSTgx"; $domain = "...com"; $editors = getEditorsList(); foreach($editors as $editor) { $editorids[] = $editor['loginid']; } if(in_array($_SESSION['loginid'], $editorids)) { echo "<div class='footervote'><a href='http://www...com/.../footervote.php'>Vote</a></div>"; } ?> login.php: <?php if (!isLoggedIn()) { if (isset($_POST['cmdlogin'])) { if (checkLogin($_POST['username'], $_POST['password'])) { show_userbox(); } else { echo "Incorrect Login information !"; show_loginform(); } } else { show_loginform(); } } else { show_userbox(); } ?>
  13. Hello, For the function below, I would like the link <div class="footervote"><a href="http://www...com/.../footervote.php">Vote</a></div> to only appear if the logged in user currently appears on editorlist.php. (I. e. if the loginid in the function corresponds to any of the usernames that currently appear in editorlist.php.) Appearing on editorlist.php is something that is dynamic. How can I do this? Thanks in advance, John function show_userbox() { // retrieve the session information $u = $_SESSION['username']; $uid = $_SESSION['loginid']; // display the user box echo '<div id="userbox"> <div class="username">'.$u.'</div> <div class="submit"><a href="http://www...com/.../submit.php">Submit an item.</a></div> <div class="changepassword"><a href="http://www...com/.../changepassword.php">Change Password</a></div> <div class="logout"><a href="http://www...com/.../logout.php">Logout</a></div> <div class="footervote"><a href="http://www...com/.../footervote.php">Vote</a></div> </div>'; } On editorlist.php: $sqlStr = "SELECT l.loginid, l.username, l.created, DATEDIFF(NOW(), l.created) AS days, COALESCE(s.total, 0) AS countSubmissions, COALESCE(c.total, 0) AS countComments, COALESCE(s.total, 0) * 10 + COALESCE(c.total, 0) AS totalScore, DATEDIFF(NOW(), l.created) + COALESCE(s.total, 0) * 10 + COALESCE(c.total, 0) AS totalScore2 FROM login l LEFT JOIN ( SELECT loginid, COUNT(1) AS total FROM submission GROUP BY loginid ) s ON l.loginid = s.loginid LEFT JOIN ( SELECT loginid, COUNT(1) AS total FROM comment GROUP BY loginid ) c ON l.loginid = c.loginid GROUP BY l.loginid ORDER BY totalScore2 DESC LIMIT 10"; $result = mysql_query($sqlStr); $arr = array(); echo "<table class=\"samplesrec1edit\">"; while ($row = mysql_fetch_array($result)) { echo '<tr>'; echo '<td class="sitename1edit1"><a href="http://www...com/.../members/index.php?profile='.$row["username"].'">'.stripslashes($row["username"]).'</a></td>'; echo '<td class="sitename1edit2">'.($row["countSubmissions"]).'</td>'; echo '<td class="sitename1edit2">'.($row["countComments"]).'</td>'; echo '<td class="sitename1edit2">'.($row["days"]).'</td>'; echo '<td class="sitename1edit2">'.($row["totalScore2"]).'</td>'; echo '</tr>'; } echo "</table>";
  14. Hello, I am using a function that leads users to a file called "comments2.php": <form action="http://www...com/.../comments/comments2.php" method="post"> On comments2.php, data passed over from the form is inserted into MySQL: $query = sprintf("INSERT INTO comment VALUES (NULL, %d, %d, '%s', NULL)", $uid, $subid, $comment); mysql_query($query) or die(mysql_error()); Then, later in comments2.php, I am using a query that loops through entries meeting certain criteria. The loop contains a row with the following information: echo '<td rowspan="3" class="commentname1" id="comment-' . $row["commentid"] . '">'.stripslashes($row["comment"]).'</td>'; For the function above, I would like the URL to be anchored by the highest value of "commentid" for id="comment-' . $row["commentid"] . '" How can this be done? Thanks in advance, John
  15. Hello, I have a MySQL table with a structure similar to this: id1 id2 title url date I would like to print out a simple table in PHP that with the following structure sorted in reverse chronological order for the most recent 10 entries (date above = date submitted) from the MySQL table: title id2 How could I do this? Thanks in advance, John
×
×
  • 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.