Jump to content

JordanSmith1111

Members
  • Posts

    10
  • Joined

  • Last visited

JordanSmith1111's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. nevermind, i got what you meant.. i had to find that formula and add it to whatever i had before. i just thought i had the entire deal but i didnt... now its all good. thanks for clearing the road ahead
  2. i saw all those google scripts and this is the one that works the best for me, i just dont know how i can echo the actual distance. the script sorts the results from closer to farther but i want to be able to echo the miles between starting point and each result dropped
  3. Hello guys I came acrross with some information to display my database results given latitude and longitude values and sort it by distance so far it works good but I was wondering how could i echo the actual distance between starting point and my results? my database is pretty straight forward: id, username, lat (latitude), lng (longitude) and a couple more things that will not be used right now.... the sql request code: $find = mysql_query("SELECT username, lat, lng, SQRT( POW(69.1 * (lat - '".$latitude."'), 2) + POW(69.1 * ('".$longitude."' - lng) * COS(lat / 57.3), 2)) AS distance FROM users WHERE username != '".$usern."' HAVING distance >= 0 ORDER BY distance ASC"); while($row = mysql_fetch_array($find)) { echo "<br />".$row['username']; } $latitude and $longitude is the current logged in member's location information so, I would like to know how to echo the actual distance in miles??? so i could do something like : echo $username."" is ".$distance." mile(s) from you..."; Thanks in advance!
  4. Ok guys after messing around with it, realized i wasnt including the "session.php" where it collects user name among other stuff... Now i got it working 90%.. Ijust need help with one more thing, it is not showing me the page #2, or #3... etc etc, it only displays X amount of messages depending on what I specify on the value for $rowsperpage. In this case is 5, so it only shows up 5 messages and only [1] page, eventhough there are like 20 messages... should have 2, 3 and 4 below them.... please help me out realizing whats going on.. THANKS! <?php include("include/session.php"); // database connection info $conn = mysql_connect('XXXXX','databasename','PASS') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('databasename',$conn) or trigger_error("SQL", E_USER_ERROR); // find out how many rows are in the table $sql = 'select COUNT(*) from pm as m1, pm as m2,users where ((m1.user1="'.$_SESSION['userid'].'" and m1.user1read="yes" and users.id=m1.user2 and m1.erasemsga!=m1.user1) or (m1.user2="'.$_SESSION['userid'].'" and m1.user2read="yes" and users.id=m1.user1 and m1.erasemsgb!=m1.user2)) and m1.id2="1" and m2.id=m1.id group by m1.id'; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 5; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // get the info from the db $sql = 'select m1.id, m1.title, m1.timestamp, count(m2.id) as reps, users.id as userid, users.username, users.avatar from pm as m1, pm as m2,users where ((m1.user1="'.$_SESSION['userid'].'" and m1.user1read="yes" and users.id=m1.user2 and m1.erasemsga!=m1.user1) or (m1.user2="'.$_SESSION['userid'].'" and m1.user2read="yes" and users.id=m1.user1 and m1.erasemsgb!=m1.user2)) and m1.id2="1" and m2.id=m1.id group by m1.id order by m1.id desc' . " LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { // echo data ?> <table width="600" cellpadding="6" cellspacing="6" class="blackfont"> <?php //We display the list of unread messages { ?> <tr> <td class="left"><a href="read_pm.php?id=<?php echo $list['id']; ?>"><?php echo htmlentities($list['title'], ENT_QUOTES, 'UTF-8'); ?></a></td> <td><?php echo $list['reps']-1; ?></td> <td align="center"><a href="profile.php?id=<?php echo $list['userid']; ?>"> <?php //display avatar if($list['avatar']!='') { echo '<img src="'.htmlentities($list['avatar']).'" alt="Image Perso" style="max-width:50px;max-height:50px;" />';}?> <div class="tinyblackfont"><?php echo htmlentities($list['username'], ENT_QUOTES, 'UTF-8'); ?></div></a></td> <td><?php echo date('Y/m/d H:i:s' ,$list['timestamp']); ?></td> <td align="center"><form action="" method="post" name="form1" id="form1" onsubmit="return confirm('Are you sure you want to DELETE this message?')"> <p> <label> <input type="hidden" name="id3" value="<?php echo $list['id']; ?>" /> <input type="hidden" name="eraser2" value="<?php echo $_SESSION['userid']; ?>" /> </label> <br /> <label> <input type="submit" name="submit2" id="submit2" value="Delete message" /> </label> </p> </form></td> </tr> <?php } //If there is no unread message we notice it ?> </table> <? } // end while /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // 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 " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // 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 " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ ?>
  5. $sql = mysql_query('select m1.id, m1.title, m1.timestamp, count(m2.id) as reps, users.id as userid, users.username, users.avatar from pm as m1, pm as m2,users where( (m1.user1="'.$_SESSION['userid'].'" and m1.user1read="yes" and users.id=m1.user2 and m1.erasemsga!=m1.user1) or (m1.user2="'.$_SESSION['userid'].'" and m1.user2read="yes" and users.id=m1.user1 and m1.erasemsgb!=m1.user2)) and m1.id2="1" and m2.id=m1.id group by m1.id order by m1.id desc'); ?>
  6. Thanks for the reply... i replaced those and now the error is gone but all i get as result is: > >>
  7. I tried to adjust the script to the phpfreaks pagination tutorial and still no success I am getting a Fatal error: SQL in /home/content/13/8078813/html/datespal/test2.php on line 51, (LINE 51 is: $result = mysql_query($sql, $conn) or trigger_error...................) I think the problem might be the SQL query/request because its joining two tables.. but I've no idea... im not too expert. Without the pagination it works like a charm, I just dont want to load a bunch of messages in only one page. <?php $conn = mysql_connect('host_here','my_db_name','PASSWORD!') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('my_db_name',$conn) or trigger_error("SQL", E_USER_ERROR); // database connection info // find out how many rows are in the table $sql = "SELECT COUNT(*) FROM pm"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 10; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // get the info from the db $sql = mysql_query('select m1.id, m1.title, m1.timestamp, count(m2.id) as reps, users.id as userid, users.username, users.avatar from pm as m1, pm as m2,users where( (m1.user1="'.$_SESSION['userid'].'" and m1.user1read="yes" and users.id=m1.user2 and m1.erasemsga!=m1.user1) or (m1.user2="'.$_SESSION['userid'].'" and m1.user2read="yes" and users.id=m1.user1 and m1.erasemsgb!=m1.user2)) and m1.id2="1" and m2.id=m1.id group by m1.id order by m1.id desc LIMIT "$offset", "$rowsperpage"'); $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { // echo data ?> <table width="600" cellpadding="6" cellspacing="6" class="blackfont"> <tr align="center" bgcolor="#0066FF" class="whitefont"> <td class="title_cell">Subject</td> <td># of Replies</td> <td>From</td> <td>Date / Time</td> <td>Delete Message?</td> </tr> <?php //We display the list of read messages ?> <tr> <td class="left"><a href="read_pm.php?id=<?php echo $sql['id']; ?>"><?php echo htmlentities($sql['title'], ENT_QUOTES, 'UTF-8'); ?></a></td> <td><?php echo $sql['reps']-1; ?></td> <td align="center"><?php //display avatar if($sql['avatar']!='') { echo '<img src="'.$sql['avatar'].'" style="max-width:50px;max-height:50px;" />';}?> <a href="profile.php?id=<?php echo $dn1['userid']; ?>"> </a><a href="profile.php?id=<?php echo $sql['userid']; ?>"> <div class="tinyblackfont"> <?php echo ucfirst(htmlentities($sql['username'], ENT_QUOTES, 'UTF-8')); ?></div> </a></td> <td><?php echo date('Y/m/d H:i:s' ,$sql['timestamp']); ?></td> <td align="center" valign="middle"><form action="" method="post" name="form1" id="form2" onsubmit="return confirm('Are you sure you want to DELETE this message?')"> <p> <label> <input type="submit" name="submit" id="submit" value="Delete message" /> <input type="hidden" name="id2" value="<?php echo $sql['id']; ?>" /> <input type="hidden" name="eraser" value="<?php echo $_SESSION['userid']; ?>" /> </label> <br /> </p> </form></td> </tr> </table> <? } // end while /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // 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 " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // 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 " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ ?>
  8. if(isset($_SESSION['username'])) { //We list his messages in a table //Two queries are executes, one for the unread messages and another for read messages $req1 = mysql_query('select m1.id, m1.title, m1.timestamp, count(m2.id) as reps, users.id as userid, users.username from pm as m1, pm as m2,users where ((m1.user1="'.$_SESSION['userid'].'" and m1.user1read="no" and users.id=m1.user2) or (m1.user2="'.$_SESSION['userid'].'" and m1.user2read="no" and users.id=m1.user1)) and m1.id2="1" and m2.id=m1.id group by m1.id order by m1.id desc'); $req2 = mysql_query('select m1.id, m1.title, m1.timestamp, count(m2.id) as reps, users.id as userid, users.username from pm as m1, pm as m2,users where ((m1.user1="'.$_SESSION['userid'].'" and m1.user1read="yes" and users.id=m1.user2) or (m1.user2="'.$_SESSION['userid'].'" and m1.user2read="yes" and users.id=m1.user1)) and m1.id2="1" and m2.id=m1.id group by m1.id order by m1.id desc'); ?> This is the list of your messages:<br /> <a href="new_pm.php" class="link_new_pm">New PM</a><br /> <h3>Unread Messages(<?php echo intval(mysql_num_rows($req1)); ?>):</h3> <table> <tr> <th class="title_cell">Title</th> <th>Nb. Replies</th> <th>Participant</th> <th>Date of creation</th> </tr> <?php //We display the list of unread messages while($dn1 = mysql_fetch_array($req1)) { ?> <tr> <td class="left"><a href="read_pm.php?id=<?php echo $dn1['id']; ?>"><?php echo htmlentities($dn1['title'], ENT_QUOTES, 'UTF-8'); ?></a></td> <td><?php echo $dn1['reps']-1; ?></td> <td><a href="profile.php?id=<?php echo $dn1['userid']; ?>"><?php echo htmlentities($dn1['username'], ENT_QUOTES, 'UTF-8'); ?></a></td> <td><?php echo date('Y/m/d H:i:s' ,$dn1['timestamp']); ?></td> </tr> <?php } //If there is no unread message we notice it if(intval(mysql_num_rows($req1))==0) { ?> <tr> <td colspan="4" class="center">You have no unread message.</td> </tr> <?php } ?> </table> <br /> <h3>Read Messages(<?php echo intval(mysql_num_rows($req2)); ?>):</h3> <table> <tr> <th class="title_cell">Title</th> <th>Nb. Replies</th> <th>Participant</th> <th>Date or creation</th> </tr> <?php //We display the list of read messages while($dn2 = mysql_fetch_array($req2)) { ?> <tr> <td class="left"><a href="read_pm.php?id=<?php echo $dn2['id']; ?>"><?php echo htmlentities($dn2['title'], ENT_QUOTES, 'UTF-8'); ?></a></td> <td><?php echo $dn2['reps']-1; ?></td> <td><a href="profile.php?id=<?php echo $dn2['userid']; ?>"><?php echo htmlentities($dn2['username'], ENT_QUOTES, 'UTF-8'); ?></a></td> <td><?php echo date('Y/m/d H:i:s' ,$dn2['timestamp']); ?></td> </tr> <?php } //If there is no read message we notice it if(intval(mysql_num_rows($req2))==0) { ?> <tr> <td colspan="4" class="center">You have no read message.</td> </tr> <?php } ?> </table> <?php } else { echo 'You must be logged to access this page.'; } ?> thats the code guys.... that mysql query is too complex for me to understand or incorporate to any pagination script i found online
  9. Hello, I recently downloaded the following private message script which really suits my needs http://www.webestools.com/scripts_tutorials-code-source-15-personal-message-system-in-php-mysql-pm-system-private-message-discussion.html The only problem I am having is trying to incorporate a pagination script to it, I tried several scripts I found online with no luck because they use very simple MYSQL request such as SELECT * from TABLENAME.... as you can see in the script from that private message php script, it uses a "complex" request and I am having a hard time trying to make it work due to my little experience programming Can anybody help me out incorporation a simple pagination script that loads the content of the next or previos page without reloading /refreshing the current page? Thanks a lot!
×
×
  • 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.