loading images and data from mysql into Flash using PHP? - php

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/

Related

Please help: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, object given [duplicate]

This question already has an answer here:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, object given
(1 answer)
Closed 5 years ago.
Im trying to create a website with this dynamic table with mysql
I tried everything and could not work out what is wrong with this code.
Please Help
<?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 = "";
mysqli_query($con,"SELECT * FROM products ORDER BY date_added DESC LIMIT 6");
$productCount = mysqli_num_rows($con); // count the output amount
if ($productCount > 0) {
while($row = mysqli_fetch_array($con)){
$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";
}
mysqli_close($con);
?>
You need to use the result of mysqli_query() as the argument to mysqli_num_rows(), not the connection.
$result = mysqli_query($con,"SELECT * FROM products ORDER BY date_added DESC LIMIT 6");
$productCount = mysqli_num_rows($result);
The same goes for mysqli_fetch_array(), it should be
while($row = mysqli_fetch_array($result)){

php mysql gallery array sorting

I Have been trying to sort my images from my database in as a product grid list shown here:
https://www.woothemes.com/wp-content/uploads/2012/08/Mystile-WooCommerce-Homepage-Grid.png...
I don't know what to change in my code I'm stuck. I need help please, Im trying to create an online store.
heres my 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 "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"];
$row = 3;
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '<table width="100" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="100%" valign="top"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width=200" height="150" border="1" /></td>
<td width="100%" valign="top">' . $product_name . '<br />
$' . $price . '<br />
View Product</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> </h3></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>
remove $row = 3 from your code to use $row["date_added"] and you creating table for each product record .
$dynamicList='We have no products listed in our store yet';
$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) {
$dynamicList='<table width="100" border="0" cellspacing="0" cellpadding="6">';
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.= 'tr><td width="100%" valign="top"><a href="product.php?id=' . $id . '">'
.'<img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width=200" height="150" border="1" />
</a></td><td width="100%" valign="top">' . $product_name . '<br />
$' . $price . '<br />View Product</td>
</tr>';
}
$dynamicList.='</table>';
}
echo $dynamicList;

Style with css in php

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

creating a new array every 10 items added

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.

Using dynamic urls to populate jquery slideshow

I am trying to dynamically populate a jquery slideshow using dynamic urls. The way this theoretically should work is the list with the images will contain dynamic links instead of the standard static links. So instead of having example.com/pics/specificpicture.jpg it would be example.com/pics/id?id=[this is what I don't know what to put]... the primary issue besides not knowing what to put there is that not only do I not know what to do to make a dynamic url, I also don't know how to make a list work proper. To explain, the jquery slideshow carousel I am using will have 6 images displaying at once, moving to the left every five seconds with the last picture being taken off to put a new picture on, so how would I keep the images from going in order, and thus each list would repeat images that another image already displayed?
EDIT this is some code very similar to what I am trying to do
PHP
<?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"><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();
?>
HTML
<td width="35%" valign="top">
<h3>Title</h3>
<p><?php echo $dynamicList; ?><br />
</p>
<p><br />
</p>
</td>
This is from developphp.com, basically how this is echoing a dynamic list, what I am trying to to is similarly echo a list, but with the 6 dynamic urls... even if I could do random images (which would not be near as productive as desired) i'd be thankful to have that much up there for now :/

Categories