Another hurdle !

Hi all, couldn’t think of a title to go with this so thought the above was appropriate for this one.

I want to create another page to my system where it displays items there are needed to be re-ordered and only those items.
So in my table I have the quantity in stock and then I have another value which is the required stock level.
And then when the page is loaded it does the math.

$reqty = $qmax - $quantity;
if ($reqty < 0) $reqty =0;

And this shows on my page what I should be reordering.

Question. How do I create a page only showing items that are needed to be be reordered ? as at the moment it show ALL items and there positive or Zero value ? It would be easy it the $reqty (reorder quantity) was saved back in the database but as this is done in page then I cannot figure this out.

You should be able to sort your database table directly from the query statement, but you could do it in PHP just as well. However, I personally find it doing it in MySQL easier. If you show your code on how you read your database table here, I’m sure someone would be able to help you. Whatever you option you take, don’t save it back to the MySQL table, for that would just be silly. Let me clarify this a little, if you are just wanting to display the data in a certain way and not making changes that need to stay permanent. By that I mean actually changing the values permanently .

Thank you Strider for your reply. At the moment i am still using MySQL not MySQLi as it is and hate showing my code i always get someone telling me that i am doing it all wrong.

Here goes…
[php]

$result = mysql_query(“SELECT * FROM stockroom order by partno desc”);

echo "

";

While ($r = mysql_fetch_array($result)) {
$partno = $r[“partno”];
$type = $r[“type”];
$colour = $r[“colour”];
$quantity = $r[“quantity”];
$qmax = $r[“qmax”];
$value = $r[“value”];
$compat = $r[“compat”];
$indate = $r[“indate”];
$used = $r[“used”];

if($quantity <= 0)
{
$reorder = “<img src=”…/graphics/yellow.png">";
}
else if ($quantity <= 1)
{
$reorder = “<img src=”…/graphics/red.png">";
}
else
{
$reorder = “<img src=”…/graphics/green.png">";
}

include ‘…/graphics/colourrows.php’;

$reqty = $qmax - $quantity;
if ($reqty < 0) $reqty =0;

echo "

"; } [/php]

Lines 46 and 47 do the simple math. this is where i would only like to show line that have a positive value.

Part Number Type Colour Quantity Qmax Re-Qty Re-Order Value Printer Booked In Date Last Booked
$partno $type $colour $quantity $qmax $reqty $reorder $value $compat $indate $used

to only show the rows that have a zero value do this:

[php]$result = mysql_query(“SELECT * FROM stockroom WHERE quantity=0 ORDER BY partno DESC”);[/php]
Then just display the rows.

You can change the query to let’s say 3 or less.
[php]$result = mysql_query(“SELECT * FROM stockroom WHERE quantity <= 3 ORDER BY partno DESC”);[/php]

etc. etc.

…and you really should be using mysqli/pdo :wink:

HI Redscouse, Thank you for taking time to reply to my post.

Its not the quantity string its the $reqty further down on lines 46 and 47 where i don some basic math and then only want to show items that have a positive $reqty but i dont think i am going to be able to do this unless i have written that value back to the database which would be a pain.

I have only been coding for a year and picked up everything i know now from searches trial and error (mostly error) and what i have picked up along the way. So then to have to forget what i have learnt and have to start again would be an absolute kick in the balls. I have done well with have i have done and coded a few things up that i now use everyday for purely my own use. Not sure where to start with mysqli or pdo at all.

Thank again

Paul

I do understand your predicament but honestly, you’ll be better for it in the long term.
Also, you won’t need to forget everything - just modify your knowledge.

As an example, here’s how you connect using mysql.

$db = mysql_connect("host","user","pass") mysql_select_db('database', $db)

and here’s how you connect using mysqli:

$db = mysqli_connect("host","user","pass","database")

Most things are almost the same, just written a little different.

This i can’t help you with as it’s a matter of personal preference. Personally, I use mysqli.
On the other hand, there are plenty of folk in this forum that use PDO.
All I can say is try both and see which you prefer - I expect it will be mysqli as PDO is totally different from what you already know.
Red :wink:

PS: Almost forgot to answer your question…
Using this;

$reqty = $qmax - $quantity;

If you only wish to show rows with a positive value, do this:
[php]
$reqty = $qmax - $quantity;
if($regty <= 0) continue; // add this line here.
[/php]
This will skip any rows with a negative value. (0 or less)

HAH cannot believe it was that simple !!! you rock !!

This is a huge problem with the internet as searching for things like this as i guess if you know no better then you will indeed find older ways to do things.

I will press on for the time being but now looking at what i have done i can indeed do better and improve on many things.

Thank you all here and to redsouse for answering my post.

You guys are a valuable source.

Paul

You’re welcome, happy to help :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service