Jump to content

ArizonaJohn

Members
  • Posts

    168
  • Joined

  • Last visited

    Never

Everything posted by ArizonaJohn

  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
  16. Hello, Below is the generated HTML for some pagination links, and also the CSS that is applied to it. For Page 1, the links appear to be 940 px from the top of the screen, which is what I want. However, when I click on a page besides page 1, the links appear to be 1880 px below the top of the screen. I would like the links to always be 940 px from the top of the screen regardless of which pagination link the user is on. What should the CSS be to accomplish this? Thanks in advance, John The generated HTML: <div class='pages'>[<b>1</b>] </div> <div class='pages'><a href='/booksearch.php?currentpage=2&find=best book ever&searching=yes&search=search' class='linksp'>2</a></div> <div class='pages'><a href='/booksearch.php?currentpage=3&find=best book ever&searching=yes&search=search' class='linksp'>3</a></div> <div class='pages'><a href='/booksearch.php?currentpage=4&find=best book ever&searching=yes&search=search' class='linksp'>4</a></div> <div class='pages'><a href='/booksearch.php?currentpage=2&find=best book ever&searching=yes&search=search' class='linksp'>></a></div> <div class='pages'><a href='/booksearch.php?currentpage=7&find=best book ever&searching=yes&search=search' class='linksp'>>></a></div> The CSS: .pages { overflow: hidden; display: block; float: left; margin: 4px; margin-top: 940px; margin-left: 10px; font-family: Arial, Helvetica, sans-serif ; } a.linksp:link { color: #000000; text-decoration: none; text-align:center; margin-left:10px; margin-right:10px; margin-bottom:0px; padding:2px; font-family:Arial, Helvetica, sans-serif; font-size: 16px; } a.linksp:visited { color: #000000; text-decoration: none; text-align:center; margin-left:10px; margin-right:10px; margin-bottom:0px; padding:2px; font-family:Arial, Helvetica, sans-serif; font-size: 16px; } a.linksp:active { color: #000000; text-decoration: none; text-align:center; margin-left:10px; margin-right:10px; margin-bottom:0px; padding:2px; font-family:Arial, Helvetica, sans-serif; font-size: 16px; } a.linksp:hover { color: #000000; text-decoration: none; background-color: #FFFF00; text-align:center; margin-left:10px; margin-right:10px; margin-bottom:0px; padding:2px; font-family:Arial, Helvetica, sans-serif; font-size: 16px; }
  17. Hello, I am having problems with the CSS for the pagination page number links below. What CSS would make the links have the following properties below? Start at an absolute position of 940 px from the top of the screen and 100 px from the right. Be 10 px apart from each other. Thanks in advance, John /****** build the pagination links ******/ // range of num links to show // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <div class='pages'><div class='pages'><a href='{$_SERVER['PHP_SELF']}?currentpage=1&find={$_SESSION['find']}&searching=yes&search=search' class='linksp'><<</a></div> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <div class='pages'><a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage&find={$_SESSION['find']}&searching=yes&search=search' class='linksp'><</a></div> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " <div class='pages'>[<b>$x</b>] </div>"; // if not current page... } else { // make it a link echo " <div class='pages'><a href='{$_SERVER['PHP_SELF']}?currentpage=$x&find={$_SESSION['find']}&searching=yes&search=search' class='linksp'>$x</a></div> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <div class='pages'><a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage&find={$_SESSION['find']}&searching=yes&search=search' class='linksp'>></a></div> "; // echo forward link for lastpage echo " <div class='pages'><a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages&find={$_SESSION['find']}&searching=yes&search=search' class='linksp'>>></a></div> "; } // end if /****** end build pagination links ******/
  18. Maybe try taking off the extra "php" from your pagination links: echo "<a href=\"results.php?resultsPage=$prev&subject=Subject&location=Location&search2=Search\">Previous</a>\n "; That extra php might have been why you were getting the broken link actually. If so, maybe you could leave the form as the "Post" method rather than changing it to the "Get" method as I suggest.
  19. Try this: $subject = $_GET['subject']; $location = $_GET['location']; and <form action="results.php" method="get"> then make each pagination link like this: echo "<a href=\"results.php.php?resultsPage=$prev&subject=Subject&location=Location&search2=Search\">Previous</a>\n ";
  20. When you use that form to do a search and it works correctly, do you have this at the end of the URL: &subject=Subject&location=Location&search2=Search ?
  21. Hi, I had the same problem, and the solution was easy. I needed to add this to the URL of each link: &searching=yes&search=search This is because my search results are generated by an HTML form that has this: <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="search" /> So each URL needed &searching=yes&search=search at the end of it to retrieve results from my database. If you are using a similar HTML form to search for your results, maybe you need to make sure something similar is at the end of each page's URL. -John
  22. Hello, The code below works great. It creates a table that shows the 25 most recently added tables to a MySQL database called "sitefeather." Each one of these tables has the following structure: id INT(11) NOT NULL auto_increment, site VARCHAR(1000) NOT NULL, action1 BIGINT(9) NOT NULL, action2 BIGINT(9) NOT NULL, createddatetime TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(id), UNIQUE (site) I would like to echo a list of "site" and "CURRENT_TIMESTAMP" for the 25 most recently added rows, regardless of which table they are in. This may be tricky since the number of tables is variable. Someone advised me that I would have to use a query involving INFORMATION_SCHEMA.TABLES. How can I do this? Thanks in advance, John echo "<table class=\"samples\">"; $index = mysql_query("select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='sitefeather' order by CREATE_TIME desc limit 25"); while ($row = mysql_fetch_array($index)) { echo '<tr><td><a href="sitesearch.php?find='.urlencode($row['TABLE_NAME']).'&searching=yes&search=search">'.$row['TABLE_NAME'].'</a></td></tr>'; } echo "</table>";
  23. Hello, Twitter and Facebook invite new users to send an invitation to everyone in their Gmail, Hotmail, or Yahoo Mail accounts. Is it easy to add this functionality to a website? Thanks, John
  24. Hello, I am trying to print out the result of the code below as a table, but the line with "while ($row2 = mysql_fetch_array($result))" gives the error statement: "mysql_fetch_array(): supplied argument is not a valid MySQL result resource". Any idea how I can get it to work? Thanks in advance, John mysql_connect("mysqlv10", "username", "password") or die(mysql_error()); mysql_select_db("bookfeather") or die(mysql_error()); $result = mysql_query("SHOW TABLES"); $tables = array(); while ($row1 = mysql_fetch_assoc($result)) { $tables[] = $row1["Tables_in_bookfeather"]; } $subQuery = implode(" UNION ALL SELECT site, votes_up FROM ",$tables); // Create one query that gets the data you need $sqlStr = "SELECT site, sum(votes_up) FROM ( ".$subQuery." ) subQuery GROUP BY site ORDER BY sum(votes_up) DESC LIMIT 25"; $result = mysql_query($sqlStr); echo "<table>"; while ($row2 = mysql_fetch_array($result)) { echo '<tr><td>'.$row2['site'].'</td></tr>'; } echo "</table>";
  25. Hello, I have a MySQL database called "bookfeather." It contains 56 tables. Each table has the following structure: id site votes_up votes_down The value for "site" is a book title. The value for "votes_up" is an integer. Sometimes a unique value for "site" appears in more than one table. For each unique value "site" in the entire database, I would like to sum "votes_up" from all 56 tables. Then I would like to print the top 25 values for "site" ranked by total "votes_up". How can I do this in PHP? 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.