Jump to content

uramagget

Members
  • Posts

    66
  • Joined

  • Last visited

    Never

Posts posted by uramagget

  1. Of course:

     

    Database: ndsg_brawl

     

    Table: tourneys_brackets

    -> userid

    -> userid2

    -> round

    -> winner

     

    I believe that it all though, unless, you need me to post the query for the user IDs (to grab usernames from the forum database). Anything else you need?

  2. $players = $mysql->select(
    					"ndsg_brawl.tourneys_brackets",
    					"*",
    					"WHERE tourney = '{$title}'"
    					);
    
    					if ($players)
    					{
    						while ($pairings = @mysql_fetch_assoc($players))
    						{
    							echo '
    								<h2>Round '.$pairings['round'].'</h2>
    							<table class="list">
    								<thead>
    									<tr>
    										<td>User #1</td>
    										<td>User #2</td>
    										<td>Round</td>
    									</tr>
    								</thead><tbody>';
    							$username1 = $mysql->select(
    							"ndsg_vbulletin.vb_user",
    							"username",
    							"WHERE userid = '{$pairings['userid']}'"
    							);
    							$username2 = $mysql->select(
    							"ndsg_vbulletin.vb_user",
    							"username",
    							"WHERE userid = '{$pairings['userid2']}'"
    							);
    
    							$username1 = @mysql_fetch_assoc($username1);
    							$username2 = @mysql_fetch_assoc($username2);
    
    							echo '<tr>
    							<td>'.$username1['username'].'</td>
    							<td>'.$username2['username'].'</td>
    							<td>'.$pairings['round'].'</td>
    							</tr>';
    							echo '</tbody></table>';
    						}
    					}
    					else
    					{
    						echo '<p>There are no standings up yet.</p>';
    					}
    

     

    I am not sure how to have it only display 1 table for each round. I tried using GROUP BY `round`, but it only displays 1 pairing instead of all. :/

  3. I've tried searching through the documentation of MySQL but the right words on how this is done exactly is just is not successful.. Basically here is my schema:

     

     

    Table:

    sprites

    --id

    --title

    --sheet_file

    --game

    --console

    --amount

    --author

     

    I want to do two things, though. For one, I want to have a MySQL query count the total amount in the Database. I have tried:

     

    SELECT amount FROM `sprites` AS COUNT
    

     

    Although I don't think that it displays the total 'amount' added...

     

     

    Next is the table displaying the submitters. I want to be able to display the submitters, though I want it to display the respectful amount of sprites that user has submitted, while ordering by the greatest amount first.

     

    Thanking in advance, and sorry if it sounded a bit..odd.

  4. Hi, I'm trying to set-up a tournament, though I want the system to be automated. I'm not sure how to approach this, since I thought the process would be confusing. I want to setup random pairing, but how can that be done and then stored in a row? Plus, I'm not sure how I would display the pairings correctly for [x] round. Can anybody help out this confused user?

     

     

    My basic layout for a bracket is: *removed by request of op*

     

    If that is required to help out..

  5. My auto_increment value is no longer incrementing after it reaches 127. I'm not sure what's happening exactly, and after Googling documentation or anything related to it, no results. =/; I don't know what to provide exactly, although when I attempt altering the auto_increment in 'Operations' to 128, it says it successfully incremented it although it does NOT as changes revert.

     

    In addition when I insert it returns a message regarding a truncated value in the field 'id'.

  6. I'm having so many headaches building a function for selecting data from a Database easier in mySQL, so I tried a simple function out:

     

    function select($table, $fields, $options = null, $loop = false)
    {
    	if (!defined('MYSQL_NOCONNECT'))
    	{
    		if (isset($table) && isset($fields))
    		{
    			$sql = "SELECT ".$this->escape($fields)." FROM ".$this->escape($table)." ".$options."";
    			$result = mysql_query($sql);
    			if ($result)
    			{
    				if (mysql_num_rows($result) > 0)
    				{
    					return $result;
    				}
    				else
    				{
    					return false;
    				}
    			}
    		}
    		else
    		{
    			echo "Wrong number of parameters supplied for select(). Try again, buddy boy.";
    			exit;
    		}
    	}
    	else
    	{
    		return null;
    	}
    }
    

     

     

    Usage

    	if (is_numeric($_GET['view']))
    {
    	$view = $_GET['view'];
    	$sub = $mysql->select("submissions", "*", "WHERE sub_id=".$mysql->escape($view)."");
    
    	if ($sub)
    	{
    		while ($subview = mysql_fetch_array($sub))
    		{
    			//Define Variables for template
    			$sub_id = $view;
    			$sub_name = $subview['sub_title'];
    			$sub_author = $subview['sub_author'];
    			$sub_description = $subview['sub_description'];
    			//Load Template
    			$tpl->load('submission/submission_view');
    		}
    	}
    	else
    	{
    		echo "The requested submission was not found. Are you sure it exists?";
    	}
    }
    else
    {
    	echo 'Numerical values only.';
    }
    

     

    But then, all it returns is:

     

    Resource id #15
    

     

    I'd really appreciate if anybody could help me out with this headache..

  7. Escape Function

    
    /*
    Escapes illegal characters within a variable
    */
    function escape($value,$allow_wildcards = true, $detect_numeric = true) 
    {
    		$return_value = $value;
    		if (get_magic_quotes_gpc()) 
    		{
    			if(ini_get('magic_quotes_sybase')) 
    			{
    				$return_value = str_replace("''", "'", $return_value);
    			} 
    			else 
    			{
    				$return_value = stripslashes($return_value);
    			}
    		}
    		//Escape wildcards for SQL injection protection on LIKE, GRANT, and REVOKE commands.
    		if (!$allow_wildcards) 
    		{
    			$return_value = str_replace('%','\%',$return_value);
    			$return_value = str_replace('_','\_',$return_value);
    		}
    		// Quote if $value is a string and detection enabled.
    		if ($detect_numeric) 
    		{
    			if (!is_numeric($return_value)) 
    			{
    				return "'" . mysql_real_escape_string($return_value) . "'";
    			}
    		}
    		//Finally, return the end result with the addition of mysql string escaping. 
    		return mysql_real_escape_string($return_value);
    }
    

     

    MySQL Query:

    if (empty($_POST['nick']) or $_POST['nick'] == " ") { $nick = "Anonymous"; } else { $nick = escape($_POST['nick']); }
    $msg = escape($_POST['msg']);
    $ip = $_SERVER['REMOTE_ADDR'];
    $date = date('M j, y');
    //SQL
    $sql = "INSERT INTO msgs (`nick`, `message`, `date`, `ip`) VALUES('$nick', '$msg', '$date', '$ip');";
    

     

    Error Returned:

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'nick'', ''nick'', 'Apr 5, 08', '66.98.84.184')' at line 1
    

     

     

    It seems like it's adding a single-quote to a single-quote, thus contradicting the escape function itself. =/; Can anybody help out?

  8. Well, I have run into a problem, but not with with the provided code. It works great, though the problem is, my comic has a built-in comics system. I would like to, for example, grab the comments that apply to the newest comic. How would I go to doing this?

  9. Well theres a few ways but to do it simply....

     

    Select COUNT(*) FROM database WHERE username_column = $username_variable
    

    In addition to that

     

    $sql = "SELECT COUNT(*) FROM database WHERE username_column = $username_variable";
    $result = mysql_query($sql);
    if (mysql_num_rows($result) > 0)
    {
    //username taken
    }
    else
    {
    //proceed
    }

  10. Hi, can anybody assist me on a mySQL based issue I have? I have a comics system that I wrote just now, and well, the only thing I need to complete it is to display the newest comic first. For example, the way I usually look for comments is by passing a mySQL query that locates the comic using $_GET. Though, I have seen many people first land without the $_GET being set. So, is there a mySQL query out there that selects the newest comic? I imagine it would select the comic with the highest ID, no?

  11. I want to make a top 5 for a little mods script I downloaded, but in order to be an overall part of the top 5, a mod has to be high in each:

     

    # of Downloadeds

    # of Installs Marked

    # of Views

    # of Comments

     

     

    Though the Math and performing the SQL query is just complicated. I do not know if there is further information to provide, but if there is, please tell me.

×
×
  • 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.