gamerzfuse Posted May 11, 2009 Share Posted May 11, 2009 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 Quote Link to comment Share on other sites More sharing options...
trq Posted May 11, 2009 Share Posted May 11, 2009 You would need to implement this within your sql query which is not created within the code you have provided. Quote Link to comment Share on other sites More sharing options...
gamerzfuse Posted May 11, 2009 Author Share Posted May 11, 2009 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; } ?> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 11, 2009 Share Posted May 11, 2009 What thorpe meant was - you can just SELECT the vehicles you want with SQL rather than creating separate pages. Quote Link to comment Share on other sites More sharing options...
gamerzfuse Posted May 11, 2009 Author Share Posted May 11, 2009 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.. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 11, 2009 Share Posted May 11, 2009 Well, how did you use SQL to select Car? Quote Link to comment Share on other sites More sharing options...
Adam Posted May 11, 2009 Share Posted May 11, 2009 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! Quote Link to comment Share on other sites More sharing options...
gamerzfuse Posted May 11, 2009 Author Share Posted May 11, 2009 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. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 11, 2009 Share Posted May 11, 2009 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'); Quote Link to comment Share on other sites More sharing options...
gamerzfuse Posted May 11, 2009 Author Share Posted May 11, 2009 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= Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 11, 2009 Share Posted May 11, 2009 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. It's not like we would know. Quote Link to comment Share on other sites More sharing options...
Adam Posted May 11, 2009 Share Posted May 11, 2009 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. Quote Link to comment Share on other sites More sharing options...
gamerzfuse Posted May 11, 2009 Author Share Posted May 11, 2009 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); } Quote Link to comment Share on other sites More sharing options...
Adam Posted May 11, 2009 Share Posted May 11, 2009 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? Quote Link to comment Share on other sites More sharing options...
gamerzfuse Posted May 11, 2009 Author Share Posted May 11, 2009 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. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 11, 2009 Share Posted May 11, 2009 Is there ack for Windows? 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'" Quote Link to comment Share on other sites More sharing options...
gamerzfuse Posted May 11, 2009 Author Share Posted May 11, 2009 Is there ack for Windows? 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. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 11, 2009 Share Posted May 11, 2009 Well it's easier to sort by SQL. Faster performance. Quote Link to comment Share on other sites More sharing options...
Adam Posted May 11, 2009 Share Posted May 11, 2009 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... Quote Link to comment Share on other sites More sharing options...
gamerzfuse Posted May 11, 2009 Author Share Posted May 11, 2009 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! Quote Link to comment Share on other sites More sharing options...
redarrow Posted May 11, 2009 Share Posted May 11, 2009 ?order=type&ordertype=DESC <<<< makes no scenes?. Quote Link to comment Share on other sites More sharing options...
Adam Posted May 11, 2009 Share Posted May 11, 2009 mysql_real_escape_string() is just preventing someone from injecting their own SQL - more about XSS. 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']. Quote Link to comment Share on other sites More sharing options...
redarrow Posted May 11, 2009 Share Posted May 11, 2009 also make sure to use isset($_GET['type']) Quote Link to comment Share on other sites More sharing options...
gamerzfuse Posted May 11, 2009 Author Share Posted May 11, 2009 ?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) Quote Link to comment Share on other sites More sharing options...
Adam Posted May 11, 2009 Share Posted May 11, 2009 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.