Jump to content

Recommended Posts

Hi, In this code each product shows vertical in line,

 

Pic

text

 

Pic

text

 

 

I want to show my Products item in horizontal line.

 

Pic Pic Pic

text text text

 

can please someone look into it :)

Thanks

 

 

<?php

include "storescripts/connect_to_mysql.php";

$dynamicList = "";

$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 10");

$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="154" border="0" cellspacing="0" cellpadding="6">

 

<td width="142" valign="top" align="center"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" /></a><p>' . $product_name . '</td>

</table>';

}

} else {

$dynamicList = "We have no products listed in our store yet";

}

mysql_close();

?>

Link to comment
https://forums.phpfreaks.com/topic/270388-layout/
Share on other sites

You should to add outside th while loop to add:

echo '<table><tr>';

 

And code before loop:

echo '<table><tr>';

 

And delete table tags (start and end tag) from the $dynamicList variable.

 

 

Thanks but i am very new..... can you please tell me which line to change?

 

should i paste complete page coding?

Link to comment
https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390687
Share on other sites

I removed table tag but i can not Understand

 

(You should to add outside th while loop to add:

echo '<table><tr>';

 

And code before loop:

echo '<table><tr>';)

 

 

<?php

// Run a select query to get my letest 6 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 10");

$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 .= '<td width="142" valign="top" align="center"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" /></a><p>' . $product_name . '</td>';

}

} else {

$dynamicList = "We have no products listed in our store yet";

}

mysql_close();

?>

Link to comment
https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390690
Share on other sites

your table have a problem...

 

you can do it something like this..

 

// print table heading before start while loop
echo '<table align="center" cellspacing="3" cellpadding="3" width="100%">
<tr>
<td align="left"><b>Product Name</b></td>
<td align="left"><b>Price</b></td>
<td align="left"><b>Added Date</b></td>
</tr>';

 

 

In while loop.. you need to echo table body.. like this

 

echo '<tr><td align="left">' . $row["product_name"] . '</td>
   <td align="left">' . $row["price"] . '</td>
   <td align="left">' . $row["date_added"] . '</td>
     </tr>';

 

after while loop.. close the table

 

echo '</table>'; // Close the table.

Link to comment
https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390691
Share on other sites

This is the complete code.

Please check....

 

 

<?php

// This file is www.developphp.com curriculum material

// Written by Adam Khoury January 01, 2011

// http://www.youtube.com/view_play_list?p=442E340A42191003

// Script Error Reporting

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";

$dynamicList = "";

$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC 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"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" /></a></td>

<td width="83%" valign="top">' . $product_name . '<br />

$' . $price . '<br />

<a href="product.php?id=' . $id . '">View Product Details</a></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>Store Home Page</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="100%" border="0" cellspacing="0" cellpadding="10">

<tr>

<td width="32%" valign="top"><h3>What the Hell?</h3>

<p>This website is very temporarily being used as an online live showcase area for an E - Commerce tutorial script set Adam is creating which can be seen on his channel here:<br />

<a href="http://www.youtube.com/flashbuilding" target="_blank">http://www.youtube.com/flashbuilding</a> </p>

<p>It is not an actual store and it will change directly after the tutorial series. <br />

<br />

This tutorial series is for educational purposes only. Use the scripts at your own risk.</p></td>

<td width="35%" valign="top"><h3>Latest Designer Fashions</h3>

<p><?php echo $dynamicList; ?><br />

</p>

<p><br />

</p></td>

<td width="33%" valign="top"><h3>Handy Tips</h3>

<p>If you operate any store online you should read the documentation provided to you by the online payment gateway you choose for handling the checkout process. You can get much more insight than I can offer on the various details of a gateway, from the gateway providers themselves. They are there to help you with whatever you need since they get a cut of your online business dealings.</p></td>

</tr>

</table>

 

</div>

<?php include_once("template_footer.php");?>

</div>

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390693
Share on other sites

Your code become from initial to:

 

<?php
// Run a select query to get my letest 6 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 10");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
echo '<table><tr>';
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 .= '<td width="142" valign="top" align="center"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" /></a><p>' . $product_name . '</td>';
}
echo '</tr></table>';
} else {
$dynamicList = "We have no products listed in our store yet";
}
mysql_close();
?>

 

Now you should to check it :happy-04:

Edited by Volter9
Link to comment
https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390694
Share on other sites

Your code become from initial to:

 

<?php
// Run a select query to get my letest 6 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 10");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
echo '<table><tr>';
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 .= '<td width="142" valign="top" align="center"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" /></a><p>' . $product_name . '</td>';
}
echo '</tr></table>';
} else {
$dynamicList = "We have no products listed in our store yet";
}
mysql_close();
?>

 

Now you should to check it :happy-04:

 

 

Its geting outside the table

 

check link blow

http://arunpatal.host-ed.me/Untitled.png

Link to comment
https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390696
Share on other sites

Its geting outside the table

 

check link blow

http://arunpatal.hos...me/Untitled.png

 

Then:

 

<?php
// Run a select query to get my letest 6 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 10");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
echo '<table>';
while($row = mysql_fetch_array($sql)){
if (($productCount % 5) == 0)
echo '<tr>';
}

$id = $row["id"];
$product_name = $row["product_name"];
$price = $row["price"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '<td width="142" valign="top" align="center"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" /></a><p>' . $product_name . '</td>';

if (($productCount % 5) == 0)
echo '</tr>';
}
}
echo '</table>';
} else {
$dynamicList = "We have no products listed in our store yet";
}
mysql_close();
?>

 

if it's still going outside the table then change "... % 5" to "... % 4"

Edited by Volter9
Link to comment
https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390697
Share on other sites

Then:

 

<?php
// Run a select query to get my letest 6 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 10");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
echo '<table>';
while($row = mysql_fetch_array($sql)){
if (($productCount % 5) == 0)
echo '<tr>';
}

$id = $row["id"];
$product_name = $row["product_name"];
$price = $row["price"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '<td width="142" valign="top" align="center"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" /></a><p>' . $product_name . '</td>';

if (($productCount % 5) == 0)
echo '</tr>';
}
}
echo '</table>';
} else {
$dynamicList = "We have no products listed in our store yet";
}
mysql_close();
?>

 

if it's still going outside the table then change "... % 5" to "... % 4"

 

 

} (error)

echo '</table>';

} else { (error)

 

There is error in these two line..... can you please check...

Thanks a lot :)

Edited by arunpatal
Link to comment
https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390698
Share on other sites

There is error in these two line..... can you please check...

Thanks a lot :)

 

I cannot help without link to your site, if it's localhost I'll try to format code, try now:

 

<?php
// Run a select query to get my letest 6 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 10");
$productCount=mysql_num_rows($sql);
// count the output amount
if($productCount>0) {
echo '<table>';
while($row=mysql_fetch_array($sql)) {
if(($productCount%5)==0) {
echo '<tr>';
}
$id=$row["id"];
$product_name=$row["product_name"];
$price=$row["price"];
$date_added=strftime("%b %d, %Y",strtotime($row["date_added"]));
$dynamicList.='<td width="142" valign="top" align="center"><a href="product.php?id='.$id.'"><img style="border:#666 1px solid;" src="inventory_images/'.$id.'.jpg" alt="'.$product_name.'" width="77" height="102" border="1" /></a><p>'.$product_name.'</td>';
if(($productCount%5)==0) {
echo '</tr>';
}
}
echo '</table>';
} else {
$dynamicList = "We have no products listed in our store yet";
}
mysql_close();
?>

Link to comment
https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390699
Share on other sites

Ok, I get it:

 

<?php
// Run a select query to get my letest 6 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 10");
$productCount=mysql_num_rows($sql);
// count the output amount
if($productCount>0) {
echo '<table>';
while($row=mysql_fetch_array($sql)) {
if(($productCount%5) == 0) {
$dynamicList .= '<tr>';
}
$id=$row["id"];
$product_name=$row["product_name"];
$price=$row["price"];
$date_added=strftime("%b %d, %Y",strtotime($row["date_added"]));
$dynamicList.='<td width="142" valign="top" align="center"><a href="product.php?id='.$id.'"><img style="border:#666 1px solid;" src="inventory_images/'.$id.'.jpg" alt="'.$product_name.'" width="77" height="102" border="1" /></a><p>'.$product_name.'</td>';
if(($productCount%5)==4) {
$dynamicList .= '</tr>';
}
}
echo '</table>';
} else {
$dynamicList = "We have no products listed in our store yet";
}
mysql_close();
?>

Link to comment
https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390704
Share on other sites

The complete page coding is like this according to your editing........

 

 

<?php

// Script Error Reporting

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";

$dynamicList="";

$sql=mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 10");

$productCount=mysql_num_rows($sql);

// count the output amount

if($productCount>0) {

echo '<table>';

while($row=mysql_fetch_array($sql)) {

if(($productCount%5) == 0) {

$dynamicList .= '<tr>';

}

$id=$row["id"];

$product_name=$row["product_name"];

$price=$row["price"];

$date_added=strftime("%b %d, %Y",strtotime($row["date_added"]));

$dynamicList.='<td width="142" valign="top" align="center"><a href="product.php?id='.$id.'"><img style="border:#666 1px solid;" src="inventory_images/'.$id.'.jpg" alt="'.$product_name.'" width="77" height="102" border="1" /></a><p>'.$product_name.'</td>';

if(($productCount%5)==4) {

$dynamicList .= '</tr>';

}

}

echo '</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...nsitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Store Home Page</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="100%" border="0" cellspacing="0" cellpadding="10">

<tr>

<td width="35%" valign="top"><h3><?php echo $dynamicList; ?><br />

</h3>

<p><br />

</p></td>

<td width="33%" valign="top"><h3>Handy Tips</h3>

<p>If you operate any store online you should read the documentation provided to you by the online payment gateway you choose for handling the checkout process. You can get much more insight than I can offer on the various details of a gateway, from the gateway providers themselves. They are there to help you with whatever you need since they get a cut of your online business dealings.</p></td>

</tr>

</table>

 

</div>

<?php include_once("template_footer.php");?>

</div>

</body>

</html>

Edited by arunpatal
Link to comment
https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390708
Share on other sites

This is the Product table

 

 

<?php

// Connect to the file above here

require "connect_to_mysql.php";

 

$sqlCommand = "CREATE TABLE products (

id int(11) NOT NULL auto_increment,

product_name varchar(255) NOT NULL,

price varchar(16) NOT NULL,

details text NOT NULL,

category varchar(16) NOT NULL,

subcategory varchar(16) NOT NULL,

date_added date NOT NULL,

PRIMARY KEY (id),

UNIQUE KEY product_name (product_name)

)";

if(mysql_query($sqlCommand)){

echo "Your products table has been created successfully!";

}else {

echo "CRITICAL ERROR: products table has not been created";

}

?>

Link to comment
https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390710
Share on other sites

Hi, In this code each product shows vertical in line,

 

Pic

text

 

Pic

text

 

 

I want to show my Products item in horizontal line.

 

Pic Pic Pic

text text text

 

can please someone look into it :)

Thanks

 

 

<?php

include "storescripts/connect_to_mysql.php";

$dynamicList = "";

$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 10");

$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="154" border="0" cellspacing="0" cellpadding="6">

 

<td width="142" valign="top" align="center"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" /></a><p>' . $product_name . '</td>

</table>';

}

} else {

$dynamicList = "We have no products listed in our store yet";

}

mysql_close();

?>

Link to comment
https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390728
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.