Is there a problem with this query?
Posted: Thu Oct 08, 2009 3:39 pm
I have setup a webring using vs.hive. It seems to have a problem after I add sites to the ring. It will ignore some sites, not necessarily the one you just added, and if you try to use the "next" link on a site that's being ignored it just refreshes to the same page. It only uses 1 BD with 1 table and a "memberID" field indexing the sites. I don't get any errors, it just skips sites in the ring.
The links to advance from site to site are structured like:
http://www.mydomain.com/home/ring.php/next/1, http://www.mydomain.com/home/ring.php/next/2, etc.
It was working fine and I added a new site, now it's only going between the first and last sites.
My question is can there be something in the queries in ring.php that is causing the problem. Here it is.
The links to advance from site to site are structured like:
http://www.mydomain.com/home/ring.php/next/1, http://www.mydomain.com/home/ring.php/next/2, etc.
It was working fine and I added a new site, now it's only going between the first and last sites.
My question is can there be something in the queries in ring.php that is causing the problem. Here it is.
Code: Select all
<?php
/***********************************************************************
FILE: ring.php
PROJECT: vs.hive
VERSION: 1.0
BEGUN: 19th September, 2007
AUTHOR: Alis Dee
NOTES: Adapted from go.php, originally written for sk.ring.
URL Example: ring.php/next/1
***********************************************************************/
require( 'config.inc.php' );
// get location information
// [1] is the action, [2] is the memberID
$_LOCATION = explode( '/', $_SERVER['PATH_INFO'] );
if( empty( $_LOCATION[1] ) || empty( $_LOCATION[2] ) )
header( "Location: $_HIVEID[hiveurl]" );
// get ID of first person in the ring
$f = mysql_fetch_array( mysql_query( "SELECT memberID, memberURL FROM `". $_HIVEID['table'] ."` WHERE siteKey = '$_HIVEID[id]' AND memberApproved != '0000-00-00' ORDER BY memberID ASC LIMIT 0, 1" ) );
// get ID of last person in the ring
$l = mysql_fetch_array( mysql_query( "SELECT memberID, memberURL FROM `". $_HIVEID['table'] ."` WHERE siteKey = '$_HIVEID[id]' AND memberApproved != '0000-00-00' ORDER BY memberID DESC LIMIT 0, 1" ) );
if( $_LOCATION[1] == 'next' ) {
$str = "SELECT memberURL, memberID FROM `". $_HIVEID['table'] ."` WHERE siteKey = '$_HIVEID[id]' AND memberID >= $_LOCATION[2] AND memberApproved != '0000-00-00' LIMIT 1, 1";
} elseif( $_LOCATION[1] == 'prev' ){
// get the number of people with lower IDs than the current guy
$n = mysql_num_rows( mysql_query( "SELECT memberURL, memberID FROM `". $_HIVEID['table'] ."` WHERE memberID <= $_LOCATION[2] AND memberApproved != '0000-00-00'" ) );
$lim = $n - 2;
$str = "SELECT memberURL, memberID FROM `". $_HIVEID['table'] ."` WHERE siteKey = '$_HIVEID[id]' AND memberID <= $_LOCATION[2] AND memberApproved != '0000-00-00' LIMIT $lim, 1";
} elseif( $_LOCATION[1] == 'random' ){
$str = "SELECT memberURL, memberID FROM `". $_HIVEID['table'] ."` WHERE siteKey = '$_HIVEID[id]' AND memberApproved != '0000-00-00' ORDER BY RAND() LIMIT 1";
}
$c = @mysql_fetch_array( @mysql_query( $str ) );
if( empty( $c ) ){
$c['memberID'] = ( $_LOCATION[2] >= $l['memberID'] ) ? $f['memberID'] : $l['memberID'];
$c['memberURL'] = ( $_LOCATION[2] >= $l['memberID'] ) ? $f['memberURL'] : $l['memberURL'];
}
//print "<b>current:</b> $_LOCATION[2]<br>";
//print "<b>$_REQUEST[w]:</b> <a href=\"go.php?w=$_REQUEST[w]&id=$c[memberID]\">$c[memberID]</a><br>";
header( "Location: $c[memberURL]" );
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="refresh" content="0;URL=<?=$c['memberURL']?>">
</head>
<body>
</body>
</html>