Jump to content

Style doesn't change - Simple if 1 or if 2 code


3raser

Recommended Posts

The code doesn't seem to do it's job. It basically doesn't echo $link or something, because the styles don't change.

 

<?php 

//connect to database
mysql_connect("$mysql_host","$mysql_user","$mysql_password");
mysql_select_db("$mysql_database");

$extract = mysql_query("SELECT theme FROM themes WHERE ip='$ip'");
$numrows = mysql_num_rows($extract);

while ($row = mysql_fetch_assoc($extract))
{
$theme = $row['theme'];
}

if ($theme=="1") {
$link = "style.css";
}

if ($theme=="2") {
$link = "style2.css";
}

?>
<link rel="stylesheet" type="text/css" href="<? echo $link; ?>" /> 

What does the actual HTML code look like? If the value of $theme doesn't EXACTLY equal '1' or '2' then it won't work. You should double check the values in the DB and the values returned from the query.

 

Although you could also make it a little more elegant to always get a value even if ther eis a problem form the query results:

 

<?php 

//connect to database
mysql_connect("$mysql_host","$mysql_user","$mysql_password");
mysql_select_db("$mysql_database");

$query = "SELECT theme FROM themes WHERE ip='$ip'";
$result = mysql_query($query);
$theme = result($result, 0);
$link = ($theme=='2') ? "style2.css" : ""style.css;

?>

<link rel="stylesheet" type="text/css" href="<?php echo $link; ?>" /> 

I already have something that allows people to make them 1 or 2 ONLY.

 

<?php 

$change_theme = $_GET['themeto'];

if (!$change_theme){
} elseif($change_theme=="1" || $change_theme=="2") {
$ip = $_SERVER['REMOTE_ADDR'];
$query = mysql_query("SELECT * FROM themes WHERE ip='$ip'");

$numrows = mysql_num_rows($query);

if ($numrows!=1) {
mysql_query("INSERT INTO themes VALUES ('$ip', '$change_theme')");
} else {
mysql_query("UPDATE themes SET theme='$change_theme' WHERE ip='$ip'");
}
} else {
}
?>

 

And the required HTML is already in the first code I posted.

I already told you what to look for. You need to verify the actual data in the database. Then validate the data that is returned from the query. And, you haven't verified what the HTML actually contains.

 

I found the problem. It didn't have $ip

 

Thank you for the help, VERY APPRECIATED! Thank you. :)

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.