Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
This code load from mysql data based on varchar 'group' to table and put picture in each of them. It is working but result is vertical album but I want horizontal.
<?php
include "../script/connect_to_mysql.php";
if (isset($_GET['a'])) {
$ge = $_GET['a'];
$tisk = "";
$sql = mysql_query("SELECT * FROM lch WHERE `group` = '$ge' ");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$name = $row["name"];
$tisk .='<table width="120" height="120" ><br>
<tr><br>
<td height="118" colspan="2"><br><img src="../lch/ikon/' . $id . '.jpg" alt=' . $name . ' width="100" height="100" /><br>;</td>
</table>';<br>
}<br>
}<br>
echo "$tisk";<br>
}<br>
?>
LOL I can post my own answer. I found solution what working for me. Here I am posting it. Anyway thanks for help :-P
include "../script/connect_to_mysql.php";
if (isset($_GET['a'])) {
$ge = $_GET['a'];
$tisk = "";
$sql = mysql_query("SELECT * FROM lch WHERE `group` = '$ge' ");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
$tisk = '<table width="120" height="120"><tr>';
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$name = $row["name"];
$tisk .='<td height="118" colspan="2"><img src="../lch/ikon/' . $id . '.jpg" alt="$name" width="100" height="100" /></td>';
}
echo '<table width="120" height="120">
<tdbody>
<tr>
' .$tisk. '
</tr>
</tbody>
</table>
';
}
}
I sort-of fixed your post, SO certainly does let you post tables within code. (I left in what might be syntax errors)
Assuming that the <br>s are an artifact of your posting messy code in the editor, you simply need to move the <tr></tr> outside the loop.
if ($productCount > 0) {
$tisk = '<table><tr>';
while(row = mysql_fetch_array($sql)){
$id = $row["id"];
$name = $row["name"];
$tisk .='<td><img src="../lch/ikon/' . $id . '.jpg" alt=' . $name . ' width="100" height="100" /></td>';
}
$tisk = '</tr></table>';
echo $tisk;
}
This will produce a table with all the cells in the same row, instead of a bunch of tables with all one column each.
If you then want a certain number per row, you'll need to use modulo:
if ($productCount > 0) {
$cellCount = 0;
$tisk = '<table><tr>';
while(row = mysql_fetch_array($sql)){
$cellCount++;
if($cellCount%5==0){
$tisk .= '</tr><tr>';
}
$id = $row["id"];
$name = $row["name"];
$tisk .='<td><img src="../lch/ikon/' . $id . '.jpg" alt=' . $name . ' width="100" height="100" /></td>';
}
$tisk = '</tr></table>';
echo $tisk;
}
Related
I would like to put status on item. When the quantity is 0 it should come out Sold Out else Available. But I'm getting a parse error on line 16. Why is that?
<?php
// Connect to the MySQL database
include "storescripts/connect_to_mysql.php";
$dynamicList = "";
$status = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added");
$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"];
$quantity = $row["quantity"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$status = if($quantity == 0) echo "Sold Out";
else echo "Available";
$dynamicList .= '<table width="100%" border="0" cellspacing="1" cellpadding="6">
<tr>
<td width="17%" valign="top"><img style="border:#666 0px 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 />
Quantity =' .$quantity . '
<br /> Status = ' . $status . ' <br />
</td>
</tr>
</table>';
}
} else {
$dynamicList = "We have no products listed in our store yet";
}
mysql_close();
?>
You have syntax errors in your code : you can't assign value to the if statement while echoing something in it.Try the following :
$status = $quantity == 0 ? "Sold Out" : "Available";
echo $status;
This is completely wrong syntax-wise:
$status = if($quantity == 0) echo "Sold Out";
else echo "Available";
Try this instead:
if ($quantity == 0)
$status = "Sold Out";
else
$status = "Available";
echo $status;
I'm new to this so please be gentle
I want to style for example $product_name, $author, $details.
I guess I could style the echos but in this case the only echo is
<?php
// Connect to the MySQL database
include "storescripts/connect_mysql.php";
// This block grabs the whole list for viewing
$dynamicList = "";
$sql = mysql_query("SELECT * FROM products ORDER BY id DESC");
$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"];
$author = $row["author"];
$details = $row["details"];
$link = $row["link"];
$isbn = $row["isbn"];
$isbn13 = $row["isbn13"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '<table width="580" border="0" cellspacing="0">
<tr>
<td width="120"><img src="/inventory_images/' . $id . '.jpg" width="120" height="184" border="0" /></td>
<td width="456"><p>' . $product_name . '<p><br />
<p>' . $author . '</span><br />
<p>' . $details . '<br />
visa </td>
</tr>
</table>';
}
} else {
$dynamicList = "Database empty.";
}
mysql_close();
?>
Have you tried adding some CSS classes to your table cells?
$dynamicList .= '
<table width="580" border="0" cellspacing="0">
<tr>
<td width="120"><img src="/inventory_images/' . $id . '.jpg" width="120" height="184" border="0" /></td>
<td width="456"><p class="product_name">' . $product_name . '<p><br />
<p class="author">' . $author . '</span><br />
<p class="detail">' . $details . '<br />
visa </td>
</tr>
</table>';
In the head add some styles:
<style>
.product_name{color:red;}
.author{color:green;}
.detail{color:blue;}
</style>
Why not just add CSS rules to your stylesheet?
table tr td p {
// some styles
}
You can add a class with styles to the <p> elements that contain each value
<td width="456"><p class="product-name">' . $product_name . '</p>...
PHP is only a preprocssor and coughs up the code as the page loads and before any of the css of HTML kicks in so you can style it as normal
You can use style="" and class="" parameters on your <p> paragraph tags as well on the table cells <td>. You can also try to add for example styled <span> or <div> tags to your variables I suppose.
For example:
$product_name = "<span class='yourstyleclass'>$row['product_name']</span>";
The code given below which display all the products in the home page.. and each product has a checkbox.. I wanted to select the checkbox of few products, and if I click on submit, the next page doesn't view the selected checkbox results
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 15");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
$colindex = 1;
$totcols = 3;
$rowclosed = false;
//$totrows=ceil($count/$totcols);
$dynamicList .= "<dl id='Searchresult'> <form action='selected.php' method='POST'> <table width=\"50%\" border=\"0\" cellspacing=\"0\" align=\"center\" cellpadding=\"3\">";
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"]));
if ($colindex == 1) {
$dynamicList .= "<tr>";
$rowclosed = false;
}
$dynamicList .= '<td width="142" valign="top" align="center">
<div id="products">
<div class="product">
<img style=" 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="100" height="100" border="0" /><div class="pr-info"><h4>' . $product_name . '</h4>
<input type="checkbox" name="check[]" value="<?php .$id. ?>"/>
</div>
</div></td>';
}
}
The Code below is where i used to retrieve the data from database of selected checkbox
foreach ($_POST['check'] as $k => $check) {
$where[ ] = $k . " = '" . mysql_real_escape_string($check) . "'";
}
include "storescripts/connect_to_mysql.php";
$sql = mysql_query("Select * from products where " . implode(' AND ', $where)); // Connect to the MySQL database
$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"];
$details = $row["details"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '<td width="142" valign="top" align="center">
<div id="products">
<div class="product">
<a href="printer.php?id=' . $id . '">
<img style=" 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="200" height="200" border="0" />
</a>
<div class="pr-info"><h4>' . $product_name . '</h4><p>' . $details . ' </p>
<span class="pr-price"><span>Rs.</span><sup>' . $price . '</sup></span>
</div>
</div></td>';
}
} else {
echo "That item does not exist.";
exit( );
}
Try changing the beginning of your second code to this:
include "storescripts/connect_to_mysql.php";
$sql = mysql_query('SELECT * FROM products WHERE id IN ('.implode(', ', array_values($_POST['check'])).')');
// rest of your code, beginning at $productCount = ...
But, how it was said before, you should start using PDO!
I think you final query and code should look this way...please change your code with this...and post the results:
foreach($_POST['check'] as $k){
$where[]= $k;}
var_dump($where); //it show you something, show me the var_dump result ???
include "storescripts/connect_to_mysql.php";
$query = "Select * from products where id IN(".implode(",",$where).")";
echo $query; //this line too....show me the result
$sql = mysql_query($query);
// Connect to the MySQL database
$productCount = mysql_num_rows($sql);
//the rest of your code ;)
-----------------------EDITED--------------------------------
Your problem is in this line:
<input type="checkbox" name="check[]" value="<?php .$id. ?>"/>
That line is wrong, make this change and see how it's work:
<input type="checkbox" name="check[]" value="<?php echo $id;?>"/>
Saludos ;)
I have a mysql database where the name of the products and prices and details get saved on there. This is done using PHP. and it works fine.
I just need to load the images of the products and their details into flash using AS3.
This is my PHP code:
<?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 "../config/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"><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();
?>
<?php echo $dynamicList; ?>
any help would be appreciated.
Thanks
1.- Use PHP and SQL to generate a XML file
-> http://code.activestate.com/recipes/576499-converting-mysql-queries-to-xml/
2.- use Flash/Flex to display the data than you obtained from your XML
-> http://www.republicofcode.com/tutorials/flash/as3xml/
3.- Use your imagination and generate some great stuff:
-> http://www.republicofcode.com/tutorials/flash/as3slideshow/
I have the following code that shows the items added in the producs table in the database and i want to make it every 10 items creating a new array so that it won't be a long list of items.
$dynamicList = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC");
$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="10%" valign="top"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpeg" alt="' . $product_name . '" width="93" height="102" border="1" /></td>
<td width="90%" valign="top">' . $product_name . '<br />
€' . $price . '<br />
<a class="provoli" href="product.php?id=' . $id . '">Προβολή Λεπτομεριών</a></td>
</tr>
</table>';
Your code-style could use some work, as it is not very pretty, but, to make this work, you could try putting your list in an array.
This requires two steps, the first is keeping record of an index. The second is adding the values to your new array.
$index = 0;
while(<your condition>) {
$index++;
<more code>
$list[((int)$index/10)] .= <string>
}
A better way is to implement this when printing the array with all your items. But I don't know how you're implementing this further.