0

I have a few php pages designed to search the database for promotion codes I created in the admin panel

I am struggling to echo these codes out to the promotional pages

my advert is simple

advert.php

<body>
    <div>
        <!-- Start SPECIAL OFFER/PROMO -->
        <div id="specialPromo" class="specialPromo">
            <p class="promoTitle">promotion title!</p>
            <p class="promoText">here is our promotion code</p>
        <div class="promoCodeBox">
            <!-- PROMO CODE -->
            <p class="promoCode"><?echo $showcode?></p>
            <!-- PROMO CODE -->
        </div>
        <div class="promoBtn"><a class="cupid-green" href="index.php?action=signup">JOIN NOW</div></a></div>
        <!-- End SPECIAL OFFER/PROMO -->
    </div>

</body>
</html> 

this then links to another page

getcode.php

<? 
include ("include/universal.php");


//execute the SQL query and return records
$result = mysql_query("SELECT  discount_code FROM discount_codes WHERE discount_name='".$code."'"); 
 //fetch tha data from the database
while ($row = mysql_fetch_array($result)) 
{
$showcode = ($row{'discount_code'});
}

//close the connection
mysql_close($condb);

?>

the problem lies with this bit of code

$code = $code["code1"];

works fine and gets results if I place it in the getcodes.php

but I want to place it in the advert.php

ultimately the plan would be to create a single admin page where I can select an advert and input the codename and it will auto-populate the code to be used with in that advert

but I cant even get it to work with a single advert, unti I figure that out I have no chance of administrating multiple adds from a single page

any advice please as to where I am going wrong, bear in mind I have only been using php for 2 weeks now

thank you all for your advice in advance

Gergo Erdosi
  • 40,904
  • 21
  • 118
  • 94
  • So you showed us all of this code, but not the code that "the problem lies with?" Where is `$code` being set? Nowhere in what you showed us. That could explain why it's not available in `advert.php` – Colin M Mar 05 '13 at 11:35
  • I dont know how to add code in to replies so please forgive me for this the $code is retrived from codes.php 'code' 'code' bear in mind this is only a temp solution eventually I will be attempting to retrieve the information from my database – SugaComa - Lead Idiot Mar 05 '13 at 11:55

1 Answers1

0

after a lot of reading I figured it out, it was simple so not sure why no one managed to help, maybe it elitism, I have found that among other websites

any way here is how I solved it

I changed my getcodes.php to:

<? 

include ("universal.php");

//CREATE AN ARRAY FOR OUT PUT
$showcode = array();
$showname = array();

//execute the SQL query and return records
$result = mysql_query("SELECT discount_name, discount_code FROM discount_codes"); 
//fetch tha data from the database
while ($row = mysql_fetch_array($result)) 
{
// create rusults for posting
$showcode[] = $row{'discount_code'};
$showname[] = $row{'discount_name'};

/* post results*/
//echo $showcode[]; //(copy to destination)
//echo $showname[];  //(copy to destination) 
}

//close the connection
mysql_close($condb);

?>

the important bit was

//CREATE AN ARRAY FOR OUT PUT
$showcode = array();
$showname = array();

and

// create rusults for posting
$showcode[] = $row{'discount_code'};
$showname[] = $row{'discount_name'};

which allowed me to then use

/* post results*/
//echo $showcode[?]; //(copy to destination)
//echo $showname[?];  //(copy to destination)

by simply using the following where I want to out put the results

echo $showcode[?];
echo $showname[?];

obviously ? whoud be changed to a number representative of the current discount code being offered

using this option allowed me to remove the need to post anything from the advert page into the search to pull the desired code, this just pull them all and then allows me to select which one to echo out