Is there a problem with this query?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Dirkk
Forum Newbie
Posts: 3
Joined: Sun May 24, 2009 1:48 pm

Is there a problem with this query?

Post by Dirkk »

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.

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>
Last edited by califdon on Thu Oct 08, 2009 10:16 pm, edited 1 time in total.
Reason: Changed code=Text to code=PHP in BBcode tags, to display syntax highlighting. Please note and format future postings accordingly.
Dirkk
Forum Newbie
Posts: 3
Joined: Sun May 24, 2009 1:48 pm

How do I get help here?

Post by Dirkk »

I either have not followed the proper etiquette or I have asked the question in the wrong area because I cannot believe no one here has the experience or knowledge to even offer an opinion.

In an attempt to find help I searched out other sites using the vs.hive script and found them all to be having similar issues and broken in some way. I also used different pc's and laptops to ensure is is not a cookie or cache issue.

I am glad to know I did not cause the problem as I previously thought and I will now assume the script is broken.

I really need some help and I feel it's just something in the query but I don't have the knowledge to see the problem.

Please take a look and offer any help or ideas you can.
Post Reply