...

View Full Version : PHP Help



Skippy
03-09-2010, 05:34 PM
Hey,

My code is below:


<?php
$cat = $_GET['offers'];
if($cat == ""){
$SearchResult = mysql_query("SELECT * from offers ORDER BY `title` ASC LIMIT " . ($page-1)*$Limit . ",$Limit") or die(mysql_error());
}else{
$SearchResult = mysql_query("SELECT * FROM offers WHERE categoryID = '$cat' LIMIT " . ($page-1)*$Limit . ",$Limit") or die(mysql_error());
}
while($list = mysql_fetch_array( $SearchResult )){
$textotemplate = new TextOfferReplace;
$textotemplate->load("template/includes/offershtml.php");
$textotemplate->replace("oid", $list['id']);
$textotemplate->replace("uid", file_get_contents ("template/includes/userid.php"));
$textotemplate->replace("title", $list['title']);
$textotemplate->replace("link", $list['link']);
$textotemplate->replace("offercredit", $list['amount']);
$textotemplate->replace("image", $list['image']);
$textotemplate->replace("credittime", $list['credittime']);
$textotemplate->replace("description", $list['description']);
$textotemplate->replace("requirements", $list['requirements']);
$textotemplate->publish();
}
?>
I would it so that when offercredit is called it uses the code below instead of $list['amount'].



<?php
$data = mysql_fetch_array($SearchResult);
$amount = $data['amount'];
switch ($amount) {
case "1.00":
echo "1";
break;
case "0.50":
echo "1/2";
break;
case "0.30":
echo "1/3";
break;
case "0.25":
echo "1/4";
break;
case "0.20":
echo "1/5";
break;
case "0.16":
echo "1/6";
break;
case "0.14":
echo "1/7";
break;
case "0.12":
echo "1/8";
break;
case "0.10":
echo "1/9";
break;

}
?>
How could I do this?

I've tried using
$textotemplate->replace("offercredit", include('offerweights.php')); with the code above in offerweights.php. It works however it includes it on the actual file rather than replacing #offercredit#

Thanks.

tomws
03-09-2010, 06:01 PM
Start with #2 from the forum guidelines (http://www.codingforums.com/postguide.htm):

2) Type in a subject that summarizes your question- A great way to turn off other members wanting to help you is to type an incomplete or silly subject for your post. Examples of poor subject titles include:

- "Help!"
- "I'm a newbie...be gentle"
- "How can I..."
- "Urgent...deadline tomorrow!"

The above subjects either have absolutely nothing to do with the question itself, or are grossly incomplete (ie: "How can I..."). When asking for help, enter a subject that summarizes your question, period! Don't use silly, incomplete, or "bait" subjects. Some examples of good titles are:

- "How do I round a number to 2 decimal places using JavaScript?"
- "What's the difference between require() and include() in PHP?"
- "Can someone suggest a good, free HTML editor?"

Then, consider using a function's return value as your repalcement.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum