Jump to content

Viewing only certain type of Inventory from inventory.php


gamerzfuse

Recommended Posts

Back again, sorry to bother you folks but you've been my saving grace here.

 

I need to build a menu on my inventory page (I can do this easily) but I need it to link to things like:

Cars, SUVs, Trucks, Vans, As Is from the inventory.php file.

I'm sure I can edit the file to display only one type, rename it to cars.php, etc but I would rather not if possible.

 

As far as I can gather, the values are loaded:

// Load recordset
function LoadRecordset($offset = -1, $rowcnt = -1) {
	global $conn, $vehicles;

	// Call Recordset Selecting event
	$vehicles->Recordset_Selecting($vehicles->CurrentFilter);

	// Load list page SQL
	$sSql = $vehicles->SelectSQL();
	if ($offset > -1 && $rowcnt > -1) $sSql .= " LIMIT $offset, $rowcnt";

	// Load recordset
	$conn->raiseErrorFn = 'ew_ErrorFn';	
	$rs = $conn->Execute($sSql);
	$conn->raiseErrorFn = '';

	// Call Recordset Selected event
	$vehicles->Recordset_Selected($rs);
	return $rs;
}

In there.

 

Any ideas as to how I might make a variable or somehow come up with a working URL like URL/inventory.php?type=car

 

Any help would be just awesome :)

Link to comment
Share on other sites

And I could find this?

Wherever that is defined, or am I SOL as far as that goes?

 

Would it be elsewhere in inventory.php or in one of the declared files or do I have to create it?

 

This?

<?php
// Load sql based on filter
	$vehicles->CurrentFilter = $sFilter;
	$sSql = $vehicles->SQL();
	if ($rs = $conn->Execute($sSql)) {
		if ($rs->EOF) {
			$LoadRow = FALSE;
		} else {
			$LoadRow = TRUE;
			$rs->MoveFirst();
			$this->LoadRowValues($rs); // Load row values

			// Call Row Selected event
			$vehicles->Row_Selected($rs);
		}
		$rs->Close();
	} else {
		$LoadRow = FALSE;
	}
	return $LoadRow;
}
?>

Link to comment
Share on other sites

Yeah.. ok.

The only problem there is that I have no idea how to do that.

I'm still very much in the learning phase here.

 

I wouldn't know how to use SQL to do this?

I know that I can search for Car and it will show all the cars and technically I could just use the Search URL except that Caravans would show up under car and van.

Any hints, tutorials or guidance would be great.. I'm trying to find my way through this but haven't the slightest clue really..

 

Link to comment
Share on other sites

This is just basic SQL...

 

SELECT * FROM something WHERE type = 'Car'

 

You can pass a value through the URL like you said and collect it with $_GET:

 

inventory.php?type=car

 

$type = $_GET['type'];

 

You just need to look through the code and find where the SQL is currently and edit that.

 

Perhaps be best off reading a couple of tutorials first to be honest!

Link to comment
Share on other sites

This is just basic SQL...

 

SELECT * FROM something WHERE type = 'Car'

 

You can pass a value through the URL like you said and collect it with $_GET:

 

inventory.php?type=car

 

$type = $_GET['type'];

 

You just need to look through the code and find where the SQL is currently and edit that.

 

Perhaps be best off reading a couple of tutorials first to be honest!

 

This is good. I know how to use the very basic SQL and I used it on my item viewing pages.. I just don't know how the other Select things work.

// Load sql based on filter
	$vehicles->CurrentFilter = $sFilter;
	$sSql = $vehicles->SQL();
	if ($rs = $conn->Execute($sSql)) {
		if ($rs->EOF) {
			$LoadRow = FALSE;
		} else {
			$LoadRow = TRUE;
			$rs->MoveFirst();
			$this->LoadRowValues($rs); // Load row values

 

I don't know if this is the related code or not?

I am more than willing to read tutorials, I just don't know what to Google even?

Everything I try comes up with unrelated information or the basic syntax I've been using.

 

Link to comment
Share on other sites

Well how many types of vehicles do you have? If you only have car, suv, truck and vans, then you don't need the WHERE conditional.

 

Otherwise, if you have more than those and you just want to select those specifically, you can do this:

SELECT * FROM something WHERE type IN ('Car', 'SUV', 'Truck', 'Van');

Link to comment
Share on other sites

SELECT * FROM something WHERE type IN ('Car', 'SUV', 'Truck', 'Van');

 

I understand this perfectly.

The only problem is that there is not SELECT action like this in the file as of now, so I don't even know where to find the current reference for the table.

I only have Cars, SUVs, Trucks, Vans and As Is in the type options.

I can use the SELECT * FROM etc to make a new file called cars.php etc, but I don't know how to do this within the one inventory.php file.

 

Example search URL for Cars:

http://craighooghiem.com/goodwills/final/inventory.php?t=vehicles&psearch=Car&Submit=Search+&psearchtype=

Link to comment
Share on other sites

You'll probs struggle to find it as your code appears OO. If you can, search the code base for the '$vehicles->SQL()' method (try searching for function SQL) - that will contain the SQL you need to alter.

Link to comment
Share on other sites

You'll probs struggle to find it as your code appears OO. If you can, search the code base for the '$vehicles->SQL()' method (try searching for function SQL) - that will contain the SQL you need to alter.

 

Windows Grep found:

00258: function SqlSelect() { // Select
00262: function SqlWhere() { // Where
00266: function SqlGroupBy() { // Group By
00270: function SqlHaving() { // Having
00274: function SqlOrderBy() { // Order By
00291: function SQL() {
00374: function SqlKeyFilter() {

 

Which relates to the block of code:

// Table level SQL
function SqlSelect() { // Select
	return "SELECT * FROM `vehicles`";
}

function SqlWhere() { // Where
	return "";
}

function SqlGroupBy() { // Group By
	return "";
}

function SqlHaving() { // Having
	return "";
}

function SqlOrderBy() { // Order By
	return "";
}

// SQL variables
var $CurrentFilter; // Current filter
var $CurrentOrder; // Current order
var $CurrentOrderType; // Current order type

// Get SQL
function GetSQL($where, $orderby) {
	return ew_BuildSelectSql($this->SqlSelect(), $this->SqlWhere(),
		$this->SqlGroupBy(), $this->SqlHaving(), $this->SqlOrderBy(),
		$where, $orderby);
}

// Table SQL
function SQL() {
	$sFilter = $this->CurrentFilter;
	$sSort = $this->getSessionOrderBy();
	return ew_BuildSelectSql($this->SqlSelect(), $this->SqlWhere(),
		$this->SqlGroupBy(), $this->SqlHaving(), $this->SqlOrderBy(),
		$sFilter, $sSort);
}

// Return table sql with list page filter
function SelectSQL() {
	$sFilter = $this->getSessionWhere();
	if ($this->CurrentFilter <> "") {
		if ($sFilter <> "") $sFilter = "($sFilter) AND ";
		$sFilter .= "(" . $this->CurrentFilter . ")";
	}
	$sSort = $this->getSessionOrderBy();
	return ew_BuildSelectSql($this->SqlSelect(), $this->SqlWhere(),
		$this->SqlGroupBy(), $this->SqlHaving(), $this->SqlOrderBy(),
		$sFilter, $sSort);
}

Link to comment
Share on other sites

Urf.. ugly.

 

Here's the SQL though:

 

  // Table level SQL
   function SqlSelect() { // Select
      return "SELECT * FROM `vehicles`";
   }

 

You could check if the 'type=' var has been passed through the URL, if it has, amend the SQL with 'WHERE type = ...'

 

Make sense?

Link to comment
Share on other sites

 

You could check if the 'type=' var has been passed through the URL, if it has, amend the SQL with 'WHERE type = ...'

 

Make sense?

 

Like I said, still a beginner, but thanks for bearing (baring?) with me so far!

I don't know how to check if it has been passed through the URL.. and I don't necessarily know what amending the SQL means.

I understand the WHERE type= and it works when I use that, I just don't know where exactly I would put that.

 

Ideally I would have a button that performs:

Change SELECT * FROM `vehicles` to SELECT * FROM `vehicles`WHERE type="car"

 

If this is going to be too much work, then I will just try and change the function to select only cars and make it cars.php, but I'm trying to cut down on the amount of files.

 

Link to comment
Share on other sites

Is there ack for Windows? :D I wouldn't know because I don't use Windows.

 

Anyways, I think you would call the GetSQL method with params '' for both $where and $orderby. I guess you can order by type.

 

Edit - pass whatever WHERE clause you want to $where param. Like " WHERE type='car'"

Link to comment
Share on other sites

Is there ack for Windows? :D I wouldn't know because I don't use Windows.

 

Anyways, I think you would call the GetSQL method with params '' for both $where and $orderby. I guess you can order by type.

 

Edit - pass whatever WHERE clause you want to $where param. Like " WHERE type='car'"

 

Can't say whether we have ack or not. I also run openSUSE but I'm doing this project in Windows as I've been using Photoshop for various things and GIMP rubs me the wrong way.

 

Regardless, I can sort by type in my inventory, so does this help?

I'm sorry for my incompetence.. I'm so far behind the ball here.

Link to comment
Share on other sites

To keep things simple you could try changing this:

 

$sSql = $vehicles->SQL();

 

To this:

 

$sSql = ($_GET['type']) ? $vehicles->SQL() . " WHERE type = '" . mysql_real_escape_string($_GET['type']) . "'" : $vehicles->SQL();

 

(Not tested obviously!)

 

There's a few ways you can do it though...

Link to comment
Share on other sites

Ok.. but I don't know how to do this?

http://craighooghiem.com/goodwills/final/inventory.php?order=type&ordertype=DESC

That is how the site is currently sorting by type.

I don't want to sort the table though, I want to.. only show one type?

 

Like I said, if it's too difficult just say the word and I'll give up.

 

To keep things simple you could try changing this:

 

$sSql = $vehicles->SQL();

 

To this:

 

$sSql = ($_GET['type']) ? $vehicles->SQL() . " WHERE type = '" . mysql_real_escape_string($_GET['type']) . "'" : $vehicles->SQL();

 

(Not tested obviously!)

 

There's a few ways you can do it though...

Just got this reply mid my reply.

Does the mysql_real_escape_string get the type from somewhere?

I'll plug it in and see what happens!

Link to comment
Share on other sites

?order=type&ordertype=DESC <<<< makes no scenes?.

What? It doesn't make scenes, but it makes sense.

 

You'd pass the type var through the URL:

 

http://craighooghiem.com/goodwills/final/inventory.php?order=type&ordertype=DESC&type=Cars

 

(Or something) .. Then you retrieve the value in the PHP with $_GET['type'].

 

 

 

Awesome!

If this works I will be so relieved!

brb.

also make sure to use isset($_GET['type'])

..ok!?

 

EDIT:

<?php
// Load list page SQL
	isset($_GET['type']);
	$sSql = ($_GET['type']) ? $vehicles->SQL() . " WHERE type = '" . mysql_real_escape_string($_GET['type']) . "'" : $vehicles->SQL();
	if ($offset > -1 && $rowcnt > -1) $sSql .= " LIMIT $offset, $rowcnt";
?>

Am I doing this right? (site says: Failed to execute SQL. Error: 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 'WHERE type = 'car' LIMIT 0, 46' at line 1)

Link to comment
Share on other sites

Redarrow means here:

 

$sSql = ($_GET['type']) ? ....

 

You can safely just use the above code, but I guess for coding standards it's better to use isset():

 

$sSql = (isset($_GET['type'])) ? ....

 

I'm not really sure what the general opinion on this is?

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.