Jump to content

passing a php page's name to a variable


waterox

Recommended Posts

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'

");

 

?>

 

 

Link to comment
Share on other sites

  • 2 months later...
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.