Jump to content

[SOLVED] Getting the "IF" to stick


e1seix

Recommended Posts

I'm trying to do some sort of loop that lifts the variable 4 digit number ($code) from $cheapsmells3, and pregnates it into the "if" statement

 

$code = ($code>0)&&($code<9999);
$cheapsmells3=('http://www.cheapsmells.com/product_show_new.asp?id=".$code."/ref=webgains&siteid=20592');

if ($row['buy_link'] == $cheapsmells3 || $cheapsmells4) {
    // has remainder so add one page
    echo '<a href="http://www.awin1.com/awclick.php?awinmid=911&awinaffid=74040&p=http://www.cheapsmells.com/viewProduct.php?id='.$code.'" target="_new">';
    echo '<img alt="BUY" height="15" src="/BUY.gif" target="_new" width="50"
/></a>';
}

else { echo '<a href="'.$row['buy_link'].'" target="_new">';
    echo '<img alt="BUY" height="15" src="/BUY.gif" target="_new" width="50"
/></a>';
}

 

Can anyone help? I keep getting "1"

Link to comment
https://forums.phpfreaks.com/topic/72938-solved-getting-the-if-to-stick/
Share on other sites

This doesn't make much sense:

I'm trying to do some sort of loop that lifts the variable 4 digit number ($code) from $cheapsmells3, and pregnates it into the "if" statement

 

Neither does your code:

<?php
$code = ($code>0)&&($code<9999); // what do you think this line is supposed to do?
$cheapsmells3=('http://www.cheapsmells.com/product_show_new.asp?id=".$code."/ref=webgains&siteid=20592'); // why the parenthesis before and after the string. Also, the way you have it the literal string ".$code." will be in the string
if ($row['buy_link'] == $cheapsmells3 || $cheapsmells4) { // this will not do what I think you want
?>

 

Here's what I think you want:

<?php
if ($code > 0 && $code < 9999) {
    $cheapsmells3='http://www.cheapsmells.com/product_show_new.asp?id='.$code.'/ref=webgains&siteid=20592';
    if ($row['buy_link'] == $cheapsmells3 || $row['buy_link'] == $cheapsmells4) {
?>

 

Ken

i should of explained it better.

 

i have a lot of misdirected file paths (over 300) in mySQL. I can't just do a simple if statement because every file path has an individual 4 digit product code.

 

'http://www.cheapsmells.com/product_show_new.asp?[color=red]id=xxxx[/color]/ref=webgains&siteid=20592'

 

I need to lift this code and pregnate it into the correct file path:

 

http://www.awin1.com/awclick.php?awinmid=911&awinaffid=74040&p=http://www.cheapsmells.com/viewProduct.php?[color=green]id=xxxx[/color].

 

My thinking behind it was if I could somehow rename the code as a variable and then pass it through the correct file path in an IF statement, hence my use of "$code." The code can only ever be a 4 digit number ranging from 0000 to 9999.

 

How can I go about doing this guys? I'm so lost.

 

All help/advice welcomed

Is the value of the variable always of the form:

<?php
$code = 'http://www.cheapsmells.com/product_show_new.asp?id=xxxx/ref=webgains&siteid=20592';
?>

 

There are ways using regular expressions to extract the id from that string, but I'm not strong in regular expressions.

 

I would use a combination of the functions parse_url() and parse_str().

 

<?php
$code = 'http://www.cheapsmells.com/product_show_new.asp?id=9385/ref=webgains&siteid=20592';
$temp = parse_url($code);
$temp2 = parse_str($temp['query'],$parsed_code);
$new_id = explode('/',$parsed_code['id']);
$new_code = 'http://www.awin1.com/awclick.php?awinmid=911&awinaffid=74040&p=http://www.cheapsmells.com/viewProduct.php?id=' . $new_id[0];
?>

 

Ken

 

that code works brilliantly... except...

 

there's two possible scenarios that could be contained in the query:

 

1) http://www.cheapsmells.com/product_show_new.asp?id=7874&ref=webgains&siteid=20592 OR

2) http://track.webgains.com/click.html?wgcampaignid=20592&wgprogramid=222&wgtarget=http://www.cheapsmells.com/product_show_new.asp?id=5981

 

it works for the results that match #1, but it doesn't for #2.

 

Any ideas?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.