php - showing promotion codes on pages

568

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" >
      <p >promotion title!</p>
      <p >here is our promotion code</p>
    <div >
      <!-- PROMO CODE -->
      <p ><?echo $showcode?></p>
      <!-- PROMO CODE -->
    </div>
    <div ><a 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

696

Answer

Solution:

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

People are also looking for solutions to the problem: php - Janrain server side response to Android app

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.