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
https://forums.phpfreaks.com/topic/99731-custom-select-function/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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