Hi,
I am very new to php so go easy on me!
I am trying to hack some pre-existing php code (see below)
What I have is a page that currently gets the newest item from a database.
On some pages this works. However, in this instance I need to show a specific item.
Since the page is not fully dynamic, it is named after the corresponding item in the database (eg blue.php)
I need to change the line that orders by itemDate.
I'm guessing that grabbing 'blue' from /blue.php and looking this up in the table might be the solution?
How could I achieve this?
Below is the code:
<?php
$url = $_SERVER ["PHP_SELF"];
print "<!-- URL [$url] -->\n\n";
$productCode = substr($url, 15, 5);
print "<!-- BC [$productCode] -->\n\n";
include('/include/ez_sql.php');
$product = $db->get_row("
SELECT
productName, productText
FROM
product
WHERE
productCode = '$productCode'
");
$item = $db->get_row("
SELECT
itemCode, itemCat, itemName, itemText, itemDate
FROM
item
WHERE
itemCode REGEXP '$productCode'
ORDER BY 'itemDate' DESC LIMIT 1
");
$format = $db->get_results("
SELECT
format
FROM
format
WHERE
itemCode = '$item->itemCode'
");
$categoryCode = substr($item->itemCode, 5, 3);
$itemCodex = substr($item->itemCode, -5);
$category = $db->get_row("
SELECT
categoryName
FROM
category
WHERE categoryCode = '$category'
");
$formats = $db->get_results("
SELECT lf.displayFormat FROM format f
LEFT JOIN lookupFormat lf ON lf.japFormat = f.format
WHERE f.itemCode = '$itemCodex'
");
?>