Jump to content

Custom select() function


uramagget

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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