PHP return to previous page - php

I've created a product catalogue with category - subcategory - individual product page. I pass a $category to the individual product page. This page lists various details about the item, including which category the item belongs to. Since the $category variable is already set, I thought Return to previous category would be enough to return it to the subcategory page but it doesn't, part of the category.php that handles this looks like this.
EDIT: Full code
product_list.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
include "storescripts/connect_to_mysql.php";
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
</style>
<meta name="Description" content="Lightweight aluminum boat docks, lifts, and accessories" />
<meta name="Keywords" content="Aluminum boat dock ladder lift water wheels" />
<script src="scripts/swfobject_modified.js" type="text/javascript"></script>
</head>
<title>Products</title>
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen"/>
</style>
<body>
<div align="center" id="mainWrapper">
<?php include_once("template_header.php");?>
<table width="100%" border="0" cellspacing="0" cellpadding="15">
<tr>
<td valign="top" align="center"><table width="100%" border="0" align="center">
<tr>
<td align="center" valign="middle"><p>Aluminum Docks</p>
<p><img src="inventory_images/aluminum docks/PN99002-6_24x4_PKG_LG.jpg" width="25%" height="64"/></p></td>
<td align="center"><p>Floating Docks</p>
<p><img src="inventory_images/floating dock/100225279.jpg" width="25%" height="64"/></p></td>
<td align="center"><p>Frame Docks</p>
<p><img src="inventory_images/frame dock/frameDock.jpg" width="25%" height="64" alt="Frame Dock" /></a></p></td>
<td align="center"><p>Pipe Docks</p>
<p><img src="inventory_images/pipe dock/PN99002_16X4_SECTION_LG.jpg" width="25%" height="64" alt="Pipe Dock" /></p></td>
</tr>
<tr>
<td align="center"><p>Boat Lifts</p>
<p><img src="inventory_images/boat lifts/GM1060_LG.jpg" width="25%" height="64" alt="Boat Lift" /></p></td>
<td align="center"><p>Boat Lift Accessories</p>
<p><img src="inventory_images/boat lift acceessories/canopy_lg (1).png" width="25%" height="64" alt="Boat Lift Accessory" /></p></td>
<td align="center"><p>Rollers & Caddies</p>
<p><img src="inventory_images/rollers and caddies/caddy270 (1).jpg"width="25%" height="64" alt="Caddy" /></p></td>
<td align="center"><p>Accessories</p>
<p><img src="inventory_images/accessorries/2step_LG.png" width="25%" height="64" alt="Accessory" /></p></td>
</tr>
</table>
</table>
<p> </p>
<?php include_once("template_footer.php");?>
</div>
</body>
</html>
**category.php**
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
// Run a select query to get my letest 6 items
// Connect to the MySQL database
include "storescripts/connect_to_mysql.php";
$category=$_GET['category'];
$sql = mysql_query("SELECT * FROM products WHERE category='$category' LIMIT 50");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
$dynamicList="";
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$product_name = $row["product_name"];
$price = $row["price"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="17%" valign="top"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="100" height="64" border="1" /></td>
<td width="83%" valign="top">' . $product_name . '<br />
$' . $price . '<br />
View Product Details</td>
</tr>
</table>';
}
} else {
$dynamicList = "We have no products listed in our store yet";
}
mysql_close();
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
</style>
<meta name="Description" content="Lightweight aluminum boat docks, lifts, and accessories" />
<meta name="Keywords" content="Aluminum boat dock ladder lift water wheels" />
<script src="scripts/swfobject_modified.js" type="text/javascript"></script>
</head>
<title><?php echo $category; ?></title>
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen"/>
</style>
<body>
<div align="center" id="mainWrapper">
<?php include_once("template_header.php");?>
<div align="left">
<p><?php echo $dynamicList;?>
</p>
<div id="target_product"></div>
<p> </p>
</div>
<?php include_once("template_footer.php");?>
</div>
</body>
</html>
**product.php**
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
include "storescripts/connect_to_mysql.php";
session_start();
//Check to see if the URL variable is set and exists in the database
if(isset($_GET['id'])){
$id=preg_replace('#[^0-9]#i','',$_GET['id']);
// Use this variable to see if the id exists, if yesthen get the product
// details, if no then exit the script and give message why.
$sql = mysql_query("SELECT * FROM products WHERE id ='$id' LIMIT 1");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
// Get all product details
while($row = mysql_fetch_array($sql)){
$product_name = $row["product_name"];
$price = $row["price"];
$details = $row["details"];
$quantity = $row["quantity_in_stock"];
$category = $row["category"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
}
}else{
echo "That item does not exist.";
exit();
}
}else{
echo "Data to render this page is missing.";
exit();
}
mysql_close();
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
</style>
<meta name="Description" content="Lightweight aluminum boat docks, lifts, and accessories" />
<meta name="Keywords" content="Aluminum boat dock ladder lift water wheels" />
<script src="scripts/swfobject_modified.js" type="text/javascript"></script>
</head>
<title><?php echo $product_name; ?></title>
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen"/>
</style>
<body>
<div align="center" id="mainWrapper">
<?php include_once("template_header.php");?>
<table width="100%" border="0" cellspacing="0" cellpadding="15">
<tr>
<td width="20%" valign="top" ><img src="inventory_images/<?php echo $id;?>.jpg" alt="<?php echo $product_name; ?>" />
<td width="80%" valign="top"> <h3><?php echo $product_name; ?></h3>
<p>$<?php echo $price; ?><br/>
<?php echo $category; ?>
<br/>
<?php echo $details; ?><br/>
<?php echo $quantity;?>
<p>Return to previous category</p>
</table>
<p> </p>
<?php include_once("template_footer.php");?>
</div>
</body>
</html>

If you want all data that was containing your previous page, use SESSION superglobal for this purpose.

Related

How to update form in PHP

I want to update record in php using GET method but whenever i click on "update button" it does not change anything and just refresh the page.and data remains the same.Here are the codes. Kindly tell me where i m doing it wrong. Thanks
<?php
include_once"dbconfig.php";
if(isset($_GET['edit']))
{
$id=$_GET['edit'];
echo $id;
$sql_query="SELECT * FROM users WHERE user_id='$id' ";
$result_set=mysql_query($sql_query);
$fetched_row=mysql_fetch_array($result_set);
}
if(isset($_POST['btn-update']))
{
// variables for input data
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$city_name=$_POST['city_name'];
//sql query to update into database
$sql_query="UPDATE users SET first_name='$first_name',last_name='$last_name',user_city='$city_name' WHERE user_id='$id' ";
mysql_query($sql_query);
//if(!$sql_query)
//die('data can not update'.mysql_error());
//else
//echo 'data updated successfully';
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<center>
<form method="post">
<table align="center">
<tr>
<td><input type="text" name="first_name" placeholder="First Name" value="<?php echo $fetched_row['first_name']; ?>"required /> </td>
</tr>
<tr>
<td><input type="text" name="last_name" placeholder="Last Name" value="<?php echo $fetched_row['last_name']; ?>" required /> </td>
</tr>
<tr>
<td><input type="text" name="city_name" placeholder="City" value="<?php echo $fetched_row['user_city']; ?>" required /> </td>
</tr>
<tr>
<td>
<button type="submit" name="btn-update"><strong>UPDATE</strong></button>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
Second File
<?php
include_once"dbconfig.php";
?>
<!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>
<meta>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>CRUD Operations With php and MySql </title>
<link rel="stylesheet" href="style.css" type="text/css"/>
</head>
<body>
<center>
<div id="body">
<div id="content">
<table align="center">
<table align="center">
<tr>
<th colspan="9">Add data Here ! </th>
</tr>
<tr>
<th colspan="2">FirstName </th>
<th colspan="8">LastName</th>
<th colspan="4">CityName </th>
<th>Operations</th>
<!--<th colspan="2">Operations</th> -->
</tr>
<?php
$sql_query="SELECT * FROM users";
$result_set=mysql_query($sql_query);
while($row=mysql_fetch_row($result_set))
{
?>
<tr>
<td><?php echo $row[0]; ?> </td>
<td colspan="4"><?php echo $row[1]; ?></td>
<td colspan="6"><?php echo $row[2];?></td>
<td colspan="4"><?php echo $row[3];?></td>
<td> <a href='edit_data.php?edit=$row[0]'>EDIT</a> </td>
<!--<td align="center"><a href="javascript edt_id('<//?php echo $row[0]; ?><img src="b_edit.png" align="EDIT" /></a></td>
<td align="center"><a href="javascript:delete_id('<//?php echo $row[0];?><img src="b_drop.png" align="DELETE" /></a></td>
</tr> -->
<?php
}
?>
</table>
</div>
</div>
</center>
</body>
</html>
Change
mysql_query($sql_query);
To
mysql_query($sql_query) or die (mysql_error()) ;
You're not sending the id (the form action property is missing

Inserting mysql data into a div

Trying to complete a tutorial and am trying to retrofit the styling.
I know the whole sheet of code may be anything from current,
but its helping me break down the parts and understand the whole.
That said, I am trying to insert the mysql data into divs instead of a table.
(for the thought of more responsive CSS design possibilities)
Any help would be awesome.
<?php
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
// Run a select query to get my letest 4 items
// Connect to the MySQL database
include "storescripts/connect_to_mysql.php";
$dynamicList = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 4");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$product_name = $row["product_name"];
$price = $row["price"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="17%" valign="top"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" /></td>
<td width="83%" valign="top">' . $product_name . '<br />
$' . $price . '<br />
View Product Details</td>
</tr>
</table>';
}
} else {
$dynamicList = "We have no products listed in our store yet";
}
mysql_close();
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The Shop</title>
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen" />
</head>
<body>
<div align="center" id="mainWrapper">
<?php include_once("template_header.php");?>
<div id="pageContent">
<table width="85%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="14%" valign="top"><h3></h3>
<p><br />
<br />
</p></td>
<td width="66%" align="center">
<h3>The Shop </h3>
<p><?php echo $dynamicList; ?><br />
</p>
<p><br />
</p></td>
<td width="20%" valign="top"><h3></h3>
<p></p></td>
</tr>
</table>
</div>
<?php include_once("template_footer.php");?>
</div>
</body>
</html>
I'm assuming this should get you headed in the right direction (Ignore the ... accordingly)
<?php
...
$dynamicList .= '
<div>
<img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" />
</div>
<div>' . $product_name . '<br />
$' . $price . '<br />
View Product Details
</div>';
...
?>
...
<div id="pageContent">
<h3>The Shop </h3>
<?php echo $dynamicList; ?>
</div>

reload the page using ajax in order to create a live chat

I have this code:
<?php require_once("config.inc.php"); ?>
<?
ob_start();
session_start();
if(isset($_SESSION['myusername'])) {
// do nothing here
} else { ?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Live chat</title>
</head>
<body bgcolor="#000000">
<font color="white" size="+3"><b>You are not logged in! <br />
Log in and start chatting!</b></font>
</body>
</html>
<?php exit(); }
ob_flush();
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="description" content="<?php echo $meta_description ?>" />
<meta name="keywords" content="<?php echo $meta_keywords ?>" />
<title><?php echo $site_name; ?> | Live chat</title>
<link rel="icon" type="image/gif" href="favicon.png" >
<link href="style.css" rel="stylesheet" type="text/css" />
<style>
body { margin:0;padding:0; background-image:url(images/background.jpg); }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function() {
$("#lolmesazhet").load("mesazhetnechat.php");
var refreshId = setInterval(function() {
$("#lolmesazhet").load("mesazhetnechat.php");
}, 1000);
$.ajaxSetup({ cache: false });
});
</script>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="500px" bgcolor="#000000" >
<?php include 'headerchat.inc.php'; ?>
</td>
</tr>
<tr>
<td width="500px" align="left" valign="top" style="padding:20px 5px 20px;">
<?php
if($_POST['submit654']) {
$result128 = mysqli_query($con,"SELECT id FROM users WHERE email = '$_SESSION[myusername]'");
$row128 = mysqli_fetch_array($result128);
date_default_timezone_set("Europe/Tirane");
$todaydate3 = date("Y-m-d H:i:s");
mysqli_query($con,"INSERT INTO chat (id, derguesi, dhoma, mesazhi, ora) VALUES (NULL, '$row128[id]', 'Main room', '$_POST[mesazhi]', '$todaydate3')");
}
?>
<table width="470px" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="50px" valign="middle" colspan="2" style="border-bottom:1px solid #FFFFFF;"> </td>
</tr>
<tr>
<td width="320" height="339px" valign="top" style="padding:3px;">
<div style="width:320px; height:339px; overflow-y:auto;">
<?php
$result73 = mysqli_query($con,"SELECT * FROM chat WHERE dhoma = 'Main room' ORDER BY id DESC");
while($row73 = mysqli_fetch_array($result73))
{
$result127 = mysqli_query($con,"SELECT username FROM users WHERE id = '$row73[derguesi]'");
$row127 = mysqli_fetch_array($result127);
?>
<table width="320px" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150" align="left"><font color="white" size="4"><b><?php echo $row127['username']; ?></b></font></td>
<td width="170" align="right"><?php echo $row73['ora']; ?></td>
</tr>
<tr>
<td colspan="2">
<font color="white"><?php echo $row73['mesazhi']; ?></font>
</td>
</tr>
</table>
<?php } ?>
</div>
</td>
<td width="150" height="450px" rowspan="2" valign="top" style=" padding:3px; border-left:1px solid #FFFFFF;">
<div style="width:150px; height:450px; overflow-y:auto;">
<font color="#FFFFFF" size="+2"><b>Online users:</b></font><br /><br />
<?php
$result = mysqli_query($con,"SELECT username FROM users WHERE verifikuar='po' AND online = 'po'");
while($row = mysqli_fetch_array($result))
{ ?>
<font color="#FFFFFF"><b><?php echo $row['username']; ?></b></font> <br />
<?php }
?>
</div>
</td>
</tr>
<tr>
<td height="50px" valign="middle" style="border-top:1px solid #FFFFFF; padding:3px; border-right:1px solid #FFFFFF;">
<form action="" method="post" name="comesazh">
<textarea name="mesazhi" cols="35" rows="4" required="required"></textarea>
<br /><input type="submit" name="submit654" id="submit654" value="Send" style="border-radius:0px; border-size:1px; border-style:solid; border-color:#ffffff; border-width:thin; background-color:#000000; color:#ffffff; height:26px; width:60px; font-size:16px;" />
</form>
</td></tr>
</table>
</body>
</html>
I would like to know if it is possible to reload that page using ajax in order to create a live chat and if yes, how to do it.
I tried many ways like reloading just a part of it using $.load function but it does not work. Then I tried to $.load all the page, but still did not work. After a lot of silly efforts, I gave up.
Here is what you can do to have the chat box update without reloading the page.
Chat page that you have:
<script>
window.setInterval(function(){
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","response.php",true);
xmlhttp.send();
}, 5000);
</script>
<div id="myDiv"><h2>This should be your chat box</h2></div>
Response.php
<?php
//do the while loop for the amount of chat you want to see
//example
for ($i = 1; $i <= 10; $i++) {
echo $i.'<br/>'; // Print out $i
}
?>
This will update the chat box every 5 seconds with the most recent chats. Give it a shot
If no element is matched by the selector — in this case, if the document does not contain an element with id="result" — the Ajax request will not be sent.
From jQuery.load manual. I can't see element with ID "lolmesazhet" in your code. Or I'm missing something.

iframe doesn't work in PHP? [duplicate]

This question already has an answer here:
Echo inside an element attribute?
(1 answer)
Closed 10 years ago.
I have a php file which will show a list of images/products dynamically from the mysql database! This bit works just fine.
but I am trying to but the command in the iframe so I can create a slideshow affect using iframe!
but when I put the iframe around the command it doesn't work for some reason! it will open a 404 page on my 000web hosting server!!
here is my code:
<?php
include "config/connect_to_mysql.php";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 10");
$i = 0;
// Establish the output variable
$dyn_table = '<table border="0" cellpadding="6">';
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
if ($i % 5 == 0) { // if $i is divisible by our target number (in this case "5")
$dyn_table .= '<tr><td><div style="position:relative" class="shadow tr" id="products_holder"><div style="position:absolute;left:-10px;top:-12px;">
<img src="images/best.png" width="97" height="94" />
</div><img style=" margin:5px; border:#ccc 1px solid" src="inventory_images/' . $id . '.jpg" width="150" height="160"/></div></td>';
} else {
$dyn_table .= '<td><div style="position:relative" class="shadow tr" id="products_holder"><div style="position:absolute;left:-10px;top:-12px;">
<img src="images/best.png" width="97" height="94" />
</div><img style=" margin:5px; border:#ccc 1px solid" src="inventory_images/' . $id . '.jpg" width="150" height="160"/></div></div></td>';
}
$i++;
}
$dyn_table .= '</tr></table>';
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/main.css">
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<script src="scripts/modernizr-2.6.1.min.js"></script>
<title>site.com</title>
<style type="text/css">
</style>
</head>
<body>
<div align="center" id="wrapper">
<?php include_once("temps/header.php"); ?>
<div id="content">
<div id="apDiv1">
<h2>Top pros</h2></div>
<table width="100%" border="0" cellspacing="0" cellpadding="17">
<tr>
<td width="2%" height="20"> </td>
<td width="98%" height="20"><p><?php echo $dyn_table; ?></p>
</tr>
</table>
<table align="center" style=" table-layout:fixed; background-image:url(images/secondSection.png);" height="82" width="100%" border="0" cellspacing="10" cellpadding="10">
<tr>
<td width="2%" height="31"> </td>
<td style="vertical-align:top" align="center" width="28%"><div id="apDiv555" class="top_btns">
<h6 class="shadow"> More Products</h6>
</div></td>
<td style="vertical-align:top" align="center" width="70%"><div id="apDiv55" class="top_btns">
<h6><span class="shadow"> Search By Clothing | Search By Retailers</span></h6>
</div></td>
</tr>
</table>
<table style="background-image: url(images/tbl_bg.png); background-repeat: repeat-x;" height="350px" width="100%" border="0" cellspacing="12" cellpadding="0">
<tr>
<td width="3%"></td>
<td width="97%"><iframe src="<?php echo $dyn_table; ?>" height="250" width="100%" ></iframe></td>
</tr>
</table>
</table>
<table height="100" width="100%" border="0" cellspacing="17" cellpadding="17">
<tr>
<td> </td>
</tr>
</table>
</div>
</div>
<?php include_once ("temps/footer.php"); ?>
</body>
</html>
any help would be grately appreciated as I am almost done with this project.
Th
Just loose the iFrame and echo the $dyn_table inside the table you already have?
Your are not aware of what an iframe means, maybe :
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/main.css">
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<script src="scripts/modernizr-2.6.1.min.js"></script>
<title>site.com</title>
<style type="text/css">
</style>
</head>
<body>
<div align="center" id="wrapper">
<?php include_once("temps/header.php"); ?>
<div id="content">
<div id="apDiv1">
<h2>Top pros</h2></div>
<table width="100%" border="0" cellspacing="0" cellpadding="17">
<tr>
<td width="2%" height="20"> </td>
<td width="98%" height="20"><p><?php echo $dyn_table; ?></p>
</tr>
</table>
<table align="center" style=" table-layout:fixed; background-image:url(images/secondSection.png);" height="82" width="100%" border="0" cellspacing="10" cellpadding="10">
<tr>
<td width="2%" height="31"> </td>
<td style="vertical-align:top" align="center" width="28%"><div id="apDiv555" class="top_btns">
<h6 class="shadow"> More Products</h6>
</div></td>
<td style="vertical-align:top" align="center" width="70%"><div id="apDiv55" class="top_btns">
<h6><span class="shadow"> Search By Clothing | Search By Retailers</span></h6>
</div></td>
</tr>
</table>
<table style="background-image: url(images/tbl_bg.png); background-repeat: repeat-x;" height="350px" width="100%" border="0" cellspacing="12" cellpadding="0">
<tr>
<td width="3%"></td>
<td width="97%"><iframe src="my_iframe.php" height="250" width="100%" ></iframe></td>
</tr>
</table>
</table>
<table height="100" width="100%" border="0" cellspacing="17" cellpadding="17">
<tr>
<td> </td>
</tr>
</table>
</div>
</div>
<?php include_once ("temps/footer.php"); ?>
</body>
</html>
// Context on the my_iframe.php
<?php
include "config/connect_to_mysql.php";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 10");
$i = 0;
// Establish the output variable
$dyn_table = '<table border="0" cellpadding="6">';
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
if ($i % 5 == 0) { // if $i is divisible by our target number (in this case "5")
$dyn_table .= '<tr><td><div style="position:relative" class="shadow tr" id="products_holder"><div style="position:absolute;left:-10px;top:-12px;">
<img src="images/best.png" width="97" height="94" />
</div><img style=" margin:5px; border:#ccc 1px solid" src="inventory_images/' . $id . '.jpg" width="150" height="160"/></div></td>';
} else {
$dyn_table .= '<td><div style="position:relative" class="shadow tr" id="products_holder"><div style="position:absolute;left:-10px;top:-12px;">
<img src="images/best.png" width="97" height="94" />
</div><img style=" margin:5px; border:#ccc 1px solid" src="inventory_images/' . $id . '.jpg" width="150" height="160"/></div></div></td>';
}
$i++;
}
$dyn_table .= '</tr></table>';
echo $dyn_table;
?>
An iframe it's a totally different page, so you should use 2 pages....just like a propose, one for the html and one for the iframe....i hope it helps.
PS: I change the a href ;)
Saludos ;)

Displaying product categories

I'm creating a simple website for a business to display their products. On the index page I display the 3 newest products. What I need to do now is have a category page people can go to to view products in a certain category. I tried adapting the code from my index page but the products aren't showing up on my category.php.
I have a product_list.php with the different categories, when one is selected I'm trying to load category.php with the products from the category that was selected.
What I have:
product_list.php
<?php
include "storescripts/connect_to_mysql.php";
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
</style>
<meta name="Description" content="Lightweight aluminum boat docks, lifts, and accessories" />
<meta name="Keywords" content="Aluminum boat dock ladder lift water wheels" />
<script src="scripts/swfobject_modified.js" type="text/javascript"></script>
</head>
<title><?php echo $product_name; ?></title>
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen"/>
</style>
<body>
<div align="center" id="mainWrapper">
<?php include_once("template_header.php");?>
<table width="100%" border="0" cellspacing="0" cellpadding="15">
<tr>
<td valign="top" align="center"><table width="100%" border="1">
<tr>
<td align="center"><p>Aluminum Docks</p>
<p><img src="inventory_images/aluminum docks/PN99002-6_24x4_PKG_LG.jpg" width="100" height="64" alt="24X4" /></p></td> // There's a field in my DB called categories, and 'docks' is the value assigned to the products
<td align="center"><p>Floating Docks</p>
<p><img src="inventory_images/floating dock/100225279.jpg" width="100" height="60" alt="Floating Dock" /></p></td>
<td align="center"><p>Frame Docks</p>
<p><img src="inventory_images/frame dock/frameDock.jpg" width="100" height="64" alt="Frame Dock" /></p></td>
<td align="center"><p>Pipe Docks</p>
<p><img src="inventory_images/pipe dock/PN99002_16X4_SECTION_LG.jpg" width="100" height="64" alt="Pipe Dock" /></p></td>
</tr>
<tr>
<td align="center"><p>Boat Lifts</p>
<p><img src="inventory_images/boat lifts/GM1060_LG.jpg" width="100" height="64" alt="Boat Lift" /></p></td>
<td align="center"><p>Boat Lift Accessories</p>
<p><img src="inventory_images/boat lift acceessories/canopy_lg (1).png" width="100" height="64" alt="Boat Lift Accessory" /></p></td>
<td align="center"><p>Rollers & Caddies</p>
<p><img src="inventory_images/rollers and caddies/caddy270 (1).jpg" width="100" height="64" alt="Caddy" /></p></td>
<td align="center"><p>Accessories</p>
<p><img src="inventory_images/accessorries/2step_LG.png" width="100" height="64" alt="Accessory" /></p></td>
</tr>
</table>
</table>
<p> </p>
<?php include_once("template_footer.php");?>
</div>
</body>
</html>
in category.php I'm trying to create a variable called $dynamicList with all the products that have "dock" as a category. But when I echo out $dynamicList nothing is rendered.
<?php
// Run a select query to get my letest 6 items
// Connect to the MySQL database
include "storescripts/connect_to_mysql.php";
$category=$_GET['category'];
$sql = mysql_query("SELECT * FROM products WHERE category='$category' LIMIT 6");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$product_name = $row["product_name"];
$price = $row["price"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="17%" valign="top"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="100" height="64" border="1" /></td>
<td width="83%" valign="top">' . $product_name . '<br />
$' . $price . '<br />
View Product Details</td>
</tr>
</table>';
}
} else {
$dynamicList = "We have no products listed in our store yet";
}
mysql_close();
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
</style>
<meta name="Description" content="Lightweight aluminum boat docks, lifts, and accessories" />
<meta name="Keywords" content="Aluminum boat dock ladder lift water wheels" />
<script src="scripts/swfobject_modified.js" type="text/javascript"></script>
</head>
<title><?php echo $category; ?></title>
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen"/>
</style>
<body>
<div align="center" id="mainWrapper">
<?php include_once("template_header.php");?>
<table width="100%">
<tr>
<td valign="top"><p><?php echo $dynamicList;?><br />
</p>
<p> </p>
<p> </p> <h2> </h2></td>
</tr>
</table>
<p> </p>
<?php include_once("template_footer.php");?>
</div>
</body>
</html>
EDIT: $dynamicList is nested in a condition statement. Just write
$dynamicList = '';
before your query
What is the current output on the page? Are the # of rows returned in the query = 0?
You should also sanitize your $category input using mysql_real_escape_string()
WHERE category ='".mysql_real_escape_string($category)."' ...
You must sanitize first the strings using this function:
public static function real_escape($string)
{
if (null != $string) {
$string = (get_magic_quotes_gpc()) ? $string : addslashes($string);
return mysql_real_escape_string($string);
}
return $string;
}
Or better use third party script like phpDataMapper
$sql = mysql_query("SELECT * FROM products WHERE category='$category' LIMIT 6");
should be
$sql = mysql_query("SELECT * FROM products WHERE category='".$category."' LIMIT 6");
This is the only error I can discover for now

Categories