php if statements

The following page code is working for me but I need to introduce a variable into the If statement below :
$postcodes = $_GET[txtPCDet];

This will then select only the records that match this variable. Please can someone help with this
I KNOW that the code is still old school mysql but this is an older project so I have not changed to PDO yet

----------------------------------
<?php
include('../connections/example_connect.php');

include('../connections/example_functions.php');

$postcodes = $_GET[txtPCDet];

record_set('orders',"SELECT * FROM orders");

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

</head>

<body>

<?php do {

       ?>

<?php
$orderid = "ID";
  $break = "<br />";

for($i=0; $i <= 21; $i++) {

if(!empty($row_orders['pc'.$i]))
echo $orderid.$row_orders['pc'.$i].$break;

}
?>
<?php } while ($row_orders = mysql_fetch_assoc($orders)); ?>
 
</body>
</html>
doctorbillTechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
It might be easier if you explain what you are trying to do rather that how you are trying to do it. Don't really see how the variable has any bearing on the if statement! Am I right in thinking that your table has 21 columns - pc* and you are only want to output the value is it's not empty. You do this for each record in your table?

If you are wanting to check the value against empty() and your GET variable, then something like this might get you going in the right direction:

<?php
$postcodes = $_GET['txtPCDet'];
while ($row_orders = mysql_fetch_assoc($orders)):
    for($i=0; $i <= 21; $i++):
        $orderID = $row_orders['pc'.$i]
        if (!empty($orderID) && $orderID != $postcodes): //it's not empty and doesn't match $postcodes!
            printf("ID: %s</br>", $orderID) : '');
        endif;
    endfor;
endwhile; ?>
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
If we have the CREATE TABLE statement we might be able to help with the WHERE clause.

I am guessing a bit here, but I think you would want something like this.

$postcodes = mysql_real_escape_string($_GET['txtPCDet']);
record_set('orders',"SELECT * FROM orders WHERE thing = $postcodes");

Open in new window

You probably also want to set error_reporting(E_ALL) so that PHP will remind you not to leave something like $_GET[txtPCDet] in the code.
0
doctorbillTechAuthor Commented:
If I use this code I get the following error message:

PHP Parse error: syntax error, unexpected T_IF in I:\CommercialWebsites\1callorders\site\postalcodes.php on line 28
-------------------
<?php
$postcodes = $_GET['txtPCDet'];
while ($row_orders = mysql_fetch_assoc($orders)):
    for($i=0; $i <= 21; $i++):
        $orderID = $row_orders['pc'.$i]
        if (!empty($orderID) && $orderID != $postcodes): //it's not empty and doesn't match $postcodes!
            printf("ID: %s</br>", $orderID) : '');
        endif;
    endfor;
endwhile; ?>
?>

-------------------

If I use this code then it works well BUT I need the result set to return just the postcode values which are EQUAL to the $postcodes variable
If I take the ! away, then all I get is a list of repeated $postcodes down the page
<?php do {
       ?>

<?php
$orderid = "ID";
  $break = "<br />";

for($i=0; $i <= 21; $i++) {

if(!empty($row_orders['pc'.$i]) && ($row_orders['pc'.$i] != $postcodes))
echo $orderid.$row_orders['pc'.$i].$break;

}
?>
<?php } while ($row_orders = mysql_fetch_assoc($orders)); ?>
0
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Chris StanyonWebDevCommented:
The T_IF error is because you don't end the previous line correctly (with a semi-colon)

$orderID = $row_orders['pc'.$i];

To show the results that match the post codes you need to replace the != with ==

if(!empty($row_orders['pc'.$i]) && ($row_orders['pc'.$i] == $postcodes))
0
doctorbillTechAuthor Commented:
PERFECT - thanks so much
0
doctorbillTechAuthor Commented:
solution
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.