Hi Guys,

Another puzzle for someone to try and crack...

I have two divs inside the <body> that basically act as two versions of the same page.

I need PHP to call one based on a variable retrieved from a database.

As it stands, this is what I have...

<?php
session_start();
require("config.php");
if(!isset($_SESSION['username']))
{
header('location:denied.php?msg=LOGIN REQUIRED');
}
else
{

}

$curruser = $_SESSION['username'];

$con = mysql_connect("***","***","***");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("***", $con);
$result = mysql_query("SELECT * FROM users WHERE username='" . $_SESSION['username']) . "'";

while($row = mysql_fetch_array($result))
  {
    $version = $row['version'];
    $username = $row['username'];
  }

mysql_close($con);
$version = "pharmacy";
$msg = "";
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-19042201-7']);
  _gaq.push(['_trackPageview']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);})();
</script>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<title>***</title>
<meta content="***" name="keywords"/>
<meta content="***" name="description"/>
<link href="../sitewide_stylesheet.css" rel="stylesheet" type="text/css"/>
<style type="text/css">
.auto-style1 {
	text-align: center;
	margin-top: 0px;
	margin-bottom: 0px;
}
.auto-style8 {
	text-align: center;
	font-size: xx-small;
	color: #336699;
}
.auto-style12 {
	text-align: center;
}
.auto-style13 {
	font-size: x-large;
}
</style>
</head>

<body>
<?php if($version == "pharmacy"){ ?>
<div id="dsh_body_wrapper">
	<div id="dsh_wrapper" style="height: 564px;">
		<div id="dsh_header">
			<div id="site_title">
				<h1><a href="../admint/index.html">DS Healthcare</a></h1>
			</div>
		</div>
		<!-- end of  dsh header -->
		<div id="dsh_menu">
			<ul>
				<li><a href="index.php" style="width: 60px;">Home</a></li>
				<li><a href="index.php" style="width: 70px;">Pricing</a></li>
				<li><a href="logout.php" style="width: 318px;">Return to main site 
				(This will log you out)</a></li>
			</ul>
		</div>
		<!-- end of  dsh_menu -->
		<div id="dsh_main" style="height: 182px">
			<div class="col_w620 float_l" style="height: 358px">
				<h2><span class="auto-style13">Pharmacy Traders area</span></h2>
				<p class="auto-style12" style="color: white; background-color: #336699;">
				<?php //$st = $_GET['msg']; echo $st; ?></p>
				<p class="auto-style1">&nbsp;</p>
				<p class="auto-style1">&nbsp;</p>
				<p class="auto-style8" style="font-size: 10px;">Built on xPress 
				Technology</p>
			</div>
			<div class="cleaner">
			</div>
		</div>
		<!-- end of main -->
		<div id="dsh_main_bottom">
		</div>
	</div>
	<!-- end of  dsh wrapper --></div>
<!-- end of  dsh body wrapper -->
<div id="dsh_footer_wrapper">
	<div id="dsh_footer" style="width: 940px">
		Copyright ©2011 DS Healthcare Ltd<br >
		DS Healthcare LTD | 94-96 Pegholme, Wharfebank Business Centre | Ilkley 
		Road | Otley | West Yorkshire | LS21 3JP | UK <br />
		Company No 7677069 |<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;"><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px;">VAT 
		No: 116 3241 51</span></span><br/>
		<a href="../admint/Website%20Privacy%20Policy.pdf" target="_blank">Privacy 
		Policy</a> |
		<a href="../admint/Terms%20and%20Conditions%20of%20Sale%20Issue%201.pdf" target="_blank">
		Terms &amp; Conditions</a><div class="cleaner">
		</div>
	</div>
</div>

<?
} elseif ($version == "health"){
?>
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-19042201-7']);
  _gaq.push(['_trackPageview']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);})();
</script>
<div id="dsh_body_wrapper">
	<div id="dsh_wrapper" style="height: 564px;">
		<div id="dsh_header">
			<div id="site_title">
				<h1><a href="../admint/index.html">DS Healthcare</a></h1>
			</div>
		</div>
		<!-- end of  dsh header -->
		<div id="dsh_menu">
			<ul>
				<li><a href="index.php" style="width: 60px;">Home</a></li>
				<li><a href="index.php" style="width: 70px;">Pricing</a></li>
				<li><a href="logout.php" style="width: 318px;">Return to main site 
				(This will log you out)</a></li>
			</ul>
		</div>
		<!-- end of  dsh_menu -->
		<div id="dsh_main" style="height: 182px">
			<div class="col_w620 float_l" style="height: 358px">
				<h2><span class="auto-style13">Healthcare Traders area</span></h2>
				<p class="auto-style12" style="color: white; background-color: #336699;">
				<?php //$st = $_GET['msg']; echo $st; ?></p>
				<p class="auto-style1">&nbsp;</p>
				<p class="auto-style1">&nbsp;</p>
				<p class="auto-style8" style="font-size: 10px;">Built on xPress 
				Technology</p>
			</div>
			<div class="cleaner">
			</div>
		</div>
		<!-- end of main -->
		<div id="dsh_main_bottom">
		</div>
	</div>
	<!-- end of  dsh wrapper --></div>
<!-- end of  dsh body wrapper -->
<div id="dsh_footer_wrapper">
	<div id="dsh_footer" style="width: 940px">
		Copyright ©2011 DS Healthcare Ltd<br/>
		DS Healthcare LTD | 94-96 Pegholme, Wharfebank Business Centre | Ilkley 
		Road | Otley | West Yorkshire | LS21 3JP | UK <br/>
		Company No 7677069 |<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;"><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px;">VAT 
		No: 116 3241 51</span></span><br/>
		<a href="../admint/Website%20Privacy%20Policy.pdf" target="_blank">Privacy 
		Policy</a> |
		<a href="../admint/Terms%20and%20Conditions%20of%20Sale%20Issue%201.pdf" target="_blank">
		Terms &amp; Conditions</a><div class="cleaner">
		</div>
	</div>
</div>
<?php } ?>
</body>
</html>

The above was based on what someone said about simply putting the html within the IF so it would only show either one... that did not work.


does anyone have any other ideas on how I can achieve the same thing?

Cheers

Jack (Scaasiboi)

Recommended Answers

All 4 Replies

If($var){
include "page1.php";
}
else{
include "page2.php;
}

hmm not quite what I had in mind but i think that would work.. cheers! :D

Thanks evstevemd, works a treat!!!!

Cheers!

Thanks evstevemd, works a treat!!!!

Cheers!

Enjoy!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.