| Welcome to Webforumz.com. |
|
Apr 15th, 2008, 06:58
|
#1 (permalink)
|
|
New Member
Join Date: Apr 2007
Location: Brisbane, Australia
Posts: 7
|
HTML, css and php
Hi, I am building an on-line shop website which has php scripts to handle the shopping functions, also HTML pages. With the HTML pages, I am using linked css, but have not been able to do this with the php scripts, although they have HTML code. Consequently, the formatting in the menu bars looks different on different pages. I can insert styles in the HTML sections of the individual php pages, but still can't get the appearance identical. Also, the php pages do not like a "DOCTYPE" declaration. Can anyone help or direct me to any resources regarding this problem.
Thanks in advance. 
|
|
|
Apr 15th, 2008, 08:41
|
#2 (permalink)
|
Join Date: Jun 2007
Location: uk
Posts: 459
|
Re: HTML, css and php
Can you show us one of your php pages you are having problems with the doctype, I suspect your problem may be that the php code is starting after your doctype giving you a "headers already sent" error.
As for the styling, until we see the code not much we can do.
HTH
Pat
|
|
|
Apr 16th, 2008, 06:26
|
#3 (permalink)
|
|
New Member
Join Date: Apr 2007
Location: Brisbane, Australia
Posts: 7
|
Re: HTML, css and php
Quote:
Originally Posted by dab42pat
Can you show us one of your php pages you are having problems with the doctype, I suspect your problem may be that the php code is starting after your doctype giving you a "headers already sent" error.
As for the styling, until we see the code not much we can do.
HTH
Pat
|
Here is the code for a php page:
- PHP: Select all
<?php session_start();
//connect to database $conn = mysql_connect("localhost", "user","my_pass") or die(mysql_error()); mysql_select_db("products",$conn) or die(mysql_error());
$display_block = "<h1>Products</h1> <p>Select a category to view items.</P>";
//show categories
$get_cats = "select id, cat_title, cat_desc from product_categories"; $get_cats_res = mysql_query($get_cats) or die(mysql_error());
if (mysql_num_rows($get_cats_res) <1) { $display_block = "<P><em> There are no categories to browse.</em></P>"; } else {
while ($cats = mysql_fetch_array($get_cats_res)) { $cat_id = $cats[id]; $cat_title = strtoupper(stripslashes($cats[cat_title])); $cat_desc = stripslashes($cats[cat_desc]);
$display_block .="<P><strong><a href=\"$SERVER[PHP_SELF]?cat_id=$cat_id\">$cat_title</a></strong> <br>$cat_desc</P>";
if ($_GET[cat_id] ==$cat_id) { //var_dump ($_GET[cat_id]);
//get items $get_items ="select id, item_name, item_desc, item_thumb from product_items where cat_id = $cat_id order by item_name";
$get_items_res = mysql_query($get_items) or die(mysql_error()); $num = mysql_num_rows($get_items_res); if(mysql_num_rows($get_items_res) < 1) { $display_block = "<P><em>Sorry, no items in this category.</em></P>";
} else { $cols = ($num/2); $times = 0; $counter = 0; $display_block .= " <table cellspacing=3 cellpadding=1 border=1 width=98%> <tr> <th>Product</th> <th>Name</th> <th>Description</th> <th>Action</th> </tr>"; while ($items = mysql_fetch_array($get_items_res)) { $item_id = $items['id']; $item_title = stripslashes($items['item_name']); $item_desc = substr($items['item_desc'],0,40); $item_desc_brief = ($item_desc."..."); $item_thumb = $items['item_thumb']; $display_block .= "<tr> <td valign=middle align=center><img src=\"$item_thumb \" alt =\"Image not available\"></td> <td align=center><strong>$item_title</strong></td> <td valign=middle align=center>$item_desc_brief</td> <td align=center> <form method=post action= \"prod_display.php\"> <p><strong>Select Currency</strong><br><br> <input type=\"radio\" name=\"curr\" value=\"us\"><strong>US Dollars</strong> <br> <input type=\"radio\" name=\"curr\" value=\"aus\"><strong>AU Dollars</strong> <input type =\"hidden\" name=\"item_id\" value=\"$item_id\"> <p><input type =\"submit\" name=\"submit\" value=\"View\"></p> </form> </tr>";
}
} } } }
?> <HTML> <HEAD> <STYLE> <!--
h1, h2, h3 {color: red} h1, h2, h3 {font-family: Arial, Helvitica, "sans-serif"}
h1 {text-transform: uppercase; text-decoration: underline; text-align: center}
BODY {font-family: Arial, Helvitica, "sans-serif"} a {color: black;} a:link {color: black;} a:visited {color:blue;} a:active {color: red;}
#navcontainer {background-color: rgb(139,179,220); height: 32px; padding-bottom: 0px;} ul #navlist {margin-left: 0; padding-left:0; white-space: nowrap; float:left;} #navlist li {display: inline; list-style-type: none; padding-top: 12px;padding-right:20px;}
#navlist a:link, #navlist a:visited {color: black; text-decoration : none; text-align: center; text-transform: uppercase;font-size: 12px; font-weight: bold; letter-spacing: 1px; min-width: 10px; border-right: rgb(206,222,238); border-right-width: 2px; padding: 8px 20px 10px 10px;}
#logo {padding-bottom: 12px;}
--> </style> <TITLE>Categories</TITLE>
</HEAD> <BODY> <body bgcolor="#D0E0F1" link="#000000">
<div id="logo" align="center"> <img border="0" src="healthlogo.gif" alt="health secrets logo" width="746" height="174" align="center"> </div>
<div id="navcontainer"> <ul id="navlist"> <li><a href="http://localhost/healthsecrets_new/index.html">HOME</a></li> <li><a href="http://localhost/healthsecrets/health_headings.php">HEALTH INFORMATION</a></li> <li><a href="contact_us.html">CONTACT US</a></li> </ul> </div>
<?php echo $display_block; ?> </BODY> </HTML>
Last edited by saltedm8; Apr 17th, 2008 at 10:00.
Reason: added [php] tags
|
|
|
Apr 16th, 2008, 12:10
|
#4 (permalink)
|
Join Date: Jun 2007
Location: uk
Posts: 459
|
Re: HTML, css and php
Hmm!
Strange for some reason with your php code located where it is it will not see a doctype.
I have done a few alterations to the code but cant test the output for obvious reasons.
It will now see a doctype and validate. Can you check the output for me.
Pat
- PHP: Select all
<?php session_start(); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <style type="text/css"> <!--
h1, h2, h3 {color: red} h1, h2, h3 {font-family: Arial, Helvitica, "sans-serif"}
h1 {text-transform: uppercase; text-decoration: underline; text-align: center}
body {font-family: Arial, Helvitica, "sans-serif"} a {color: black;} a:link {color: black;} a:visited {color:blue;} a:active {color: red;}
#navcontainer {background-color: rgb(139,179,220); height: 32px; padding-bottom: 0px;} ul #navlist {margin-left: 0; padding-left:0; white-space: nowrap; float:left;} #navlist li {display: inline; list-style-type: none; padding-top: 12px;padding-right:20px;}
#navlist a:link, #navlist a:visited {color: black; text-decoration : none; text-align: center; text-transform: uppercase;font-size: 12px; font-weight: bold; letter-spacing: 1px; min-width: 10px; border-right: rgb(206,222,238); border-right-width: 2px; padding: 8px 20px 10px 10px;}
#logo {padding-bottom: 12px;}
--> </style> <title>Categories</title>
</head>
<body bgcolor="#D0E0F1" link="#000000"> <?php //connect to database $conn = mysql_connect("localhost", "user","my_pass") or die(mysql_error()); mysql_select_db("products",$conn) or die(mysql_error());
$display_block = "<h1>Products</h1>
<p>Select a category to view items.</P>";
//show categories
$get_cats = "select id, cat_title, cat_desc from product_categories"; $get_cats_res = mysql_query($get_cats) or die(mysql_error());
if (mysql_num_rows($get_cats_res) <1) { $display_block = "<P><em> There are no categories to browse.</em></P>"; } else {
while ($cats = mysql_fetch_array($get_cats_res)) { $cat_id = $cats[id]; $cat_title = strtoupper(stripslashes($cats[cat_title])); $cat_desc = stripslashes($cats[cat_desc]);
$display_block .="<P><strong><a href=\"$SERVER[PHP_SELF]?cat_id=$cat_id\">$cat_title</a></strong> <br>$cat_desc</P>";
if ($_GET[cat_id] ==$cat_id) { //var_dump ($_GET[cat_id]);
//get items $get_items ="select id, item_name, item_desc, item_thumb from product_items where cat_id = $cat_id order by item_name";
$get_items_res = mysql_query($get_items) or die(mysql_error()); $num = mysql_num_rows($get_items_res);
if(mysql_num_rows($get_items_res) < 1) { $display_block = "<P><em>Sorry, no items in this category.</em></P>";
} else {
$cols = ($num/2); $times = 0; $counter = 0;
$display_block .= "
<table cellspacing=3 cellpadding=1 border=1 width=98%> <tr> <th>Product</th> <th>Name</th> <th>Description</th> <th>Action</th> </tr>";
while ($items = mysql_fetch_array($get_items_res)) {
$item_id = $items['id']; $item_title = stripslashes($items['item_name']); $item_desc = substr($items['item_desc'],0,40); $item_desc_brief = ($item_desc."..."); $item_thumb = $items['item_thumb'];
$display_block .= "<tr> <td valign=middle align=center><img src=\"$item_thumb \" alt =\"Image not available\"></td> <td align=center><strong>$item_title</strong></td> <td valign=middle align=center>$item_desc_brief</td> <td align=center> <form method=post action= \"prod_display.php\"> <p><strong>Select Currency</strong><br><br> <input type=\"radio\" name=\"curr\" value=\"us\"><strong>US Dollars</strong> <br> <input type=\"radio\" name=\"curr\" value=\"aus\"><strong>AU Dollars</strong>
<input type =\"hidden\" name=\"item_id\" value=\"$item_id\"> <p><input type =\"submit\" name=\"submit\" value=\"View\"></p> </form>
</tr>";
}
} } } }
?> <div id="logo" align="center"> <img border="0" src="healthlogo.gif" alt="health secrets logo" width="746" height="174" align="center"> </div>
<div id="navcontainer"> <ul id="navlist">
<li><a href="http://localhost/healthsecrets_new/index.html">HOME</a></li> <li><a href="http://localhost/healthsecrets/health_headings.php">HEALTH INFORMATION</a></li> <li><a href="contact_us.html">CONTACT US</a></li> </ul> </div>
<?php echo $display_block; ?> </body> </html>
|
|
|
Apr 17th, 2008, 07:44
|
#5 (permalink)
|
|
New Member
Join Date: Apr 2007
Location: Brisbane, Australia
Posts: 7
|
Re: HTML, css and php
Thanks Pat,
I altered the code as you suggested. The display is OK, but if I try linking to the external style sheet rather than using embedded style, it still won't work. However, after fiddling with the styles in both locations, the display is close (but not identical) on the html and php pages.
Thanks for your help.
Gecko
|
|
|
| Thread Tools |
|
|
| Rate This Thread |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|