PHP - Modify An Automatically Generated Product List Using Php While() Html From Mysql
hi
i have generated a product list from a mysql table called product_list, once i enter a new product in to the table the product will be shown in the generated list and the list will grow and the table grows. and i want to allow user the edit/delete/save the products from the generated table, i have no idea how to do it and what is the algorithmic idea to do it so. here is the php and the html code. <!--Body container for creating a new product in to the list--> <div class="body_orderviewform"> <form name="form1" method="post" action="upload_file.php" enctype="multipart/form-data"> <p> <label for="user_id">User ID:</label> <input type="text" name="user_id" id="user_id"> <label for="customer_name">Customer Name:</label> <input type="text" name="customer_name" id="customer_name"> <label for="customer_family">Customer_family</label> <input type="text" name="customer_family" id="customer_family"> <label for="freelancer_name">Purchaser:</label> <input name="freelancer_name" type="text" id="freelancer_name"> <? if (isset($_COOKIE['picAdd'])) echo $_COOKIE['picAdd'];?> </p> <!------------------------------------------------------------------------------------------------------- for generating the list --> <div class="div.neworder_list" > <div class="div.neworder_listheader" align="center"> <table width="637" border="1" > <tr> <td width="193"><label for="link">link:</label> <label for="link_new"></label> <input type="text" name="link_new" id="link_new"></td> <td width="202"><label for="unitprice">Unit Price:</label> <label for="Unit_price_new"></label> <input type="text" name="Unit_price_new" id="Unit_price_new"></td> <td width="220"><label for="qty">Quantity:</label> <label for="quantity_new"></label> <input type="text" name="quantity_new" id="quantity_new"></td> </tr> <tr> <td><label for="express">Express Fee:</label> <label for="express_new"></label> <input type="text" name="express_new" id="express_new"></td> <td><label for="commission_new">Commission:</label> <input type="text" name="commission_new" id="commission_new"></td> <td><label for="customer_description">Description</label> <label for="description_new"></label> <textarea name="description_new" id="description_new" cols="45" rows="5"></textarea></td> </tr> <tr> <td> </td> <td colspan="2">Picture Upload: <input type="hidden" name="<?php echo ini_get("session.upload_progress.name");?>" value="123" /> <input name="file" type="file" autofocus="autofocus"/> <br /> </tr> <tr> <td colspan="3"><input type="reset" name="reset" id="reset" value="Reset"> <input type="submit" name="submit" id="submit" value="Submit The Product"></td> </tr> </table> </form> </div> <div class="neworder_listview"> <p> <form action="" method="post" name="list"> <input type="submit" name="del" id="del" value="Save"> <input type="submit" name="save" id="save" value="Del"> </p> <table width="1022" border="1" align="center"> <tr> <th width="24" scope="col"> </th> <th width="24" scope="col">Row#</th> <th width="137" scope="col">Manager</th> <th width="137" scope="col">Purchaser Desc</th> <th width="40" scope="col"><p>Link</p> <p>/Ссылки</p></th> <th width="53" scope="col">ФОТО</th> <th width="50" scope="col">Unit Price/Цена за еденицу товара</th> <th width="46" scope="col">Quantity/ Кол-во</th> <th width="138" scope="col">Total Unit Price/ Общая цена</th> <th width="89" scope="col">Express/Доставка по Китаю</th> <th width="119" scope="col">Description/Описание</th> <th width="89" scope="col">ADDITIONAL LINKS/ЗAMЕНЫ</th> </tr> <?php $username = "my username"; $password = "my pass"; $database = "userinfo"; $link = mysql_connect("localhost", "$username", "$password"); if(!$link) {echo("Failed to establish connection to mysql server"); exit();} $status = mysql_select_db($database); $query = "SELECT * FROM order_list"; $result = mysql_query($query); $num = mysql_num_rows($result); $i=0; while ($i < $num) { $field1_name=mysql_result($result,$i,"admin_st"); $field2_name=mysql_result($result,$i,"freelancer_st"); $field3_name=mysql_result($result,$i,"link"); $field4_name=mysql_result($result,$i,"picture"); $field5_name=mysql_result($result,$i,"unitprice"); $field6_name=mysql_result($result,$i,"qty"); $field7_name=mysql_result($result,$i,"express"); $field8_name=mysql_result($result,$i,"customer_st"); $i++; } ?> <?php $i=0; $row=1; while ($i < $num) { $f1=mysql_result($result,$i,"admin_st"); $f2=mysql_result($result,$i,"freelancer_st"); $f3=mysql_result($result,$i,"link"); $f4=mysql_result($result,$i,"pic_address"); $f5=mysql_result($result,$i,"unitprice"); $f6=mysql_result($result,$i,"qty"); $f7=mysql_result($result,$i,"express"); $f8=mysql_result($result,$i,"customer_st"); $totao_unit_price = $f5*$f6; ?> <tr> <td><input type="checkbox" name="del_chbox" id="del_chbox"> <td><p><font face="Arial"><input name="row_txtbox" type="text" id="row_txtbox" size="2" value="<?php echo $row; ?>"></font></td> <td><p><font face="Arial"> <textarea name="manager_txtbox" cols="10" id="manager_txtbox"><?php echo $f1; ?></textarea></font></td> <td><p><font face="Arial"> <textarea name="purchase_txtbox" cols="10" id="purchase_txtbox"><?php echo $f2; ?></textarea> </font></td> <td><font face="Arial"><a href="<?php $f3 ?>" target="_blank"><?php echo $f3; ?></a></font></td> <td><font face="Arial"><img src="<?php echo $f4;?>" width="100" align="middle"100></font></td> <td><font face="Arial"><input name="unitprice_txtbox" type="text" id="unitprice_txtbox" size="2" value="<?php echo $f5; ?>"></font></td> <td><font face="Arial"> <input name="qty_txtbox" type="text" id="qty_txtbox" size="2" value="<?php echo $f6; ?>"></font></td> <td><p><font face="Arial"><?php echo $totao_unit_price; ?></font></td> <td><p><font face="Arial"><input name="express2" type="text" id="express3" size="2" value="<?php echo $f7; ?>"></font></td> <td><p><font face="Arial"> <textarea name="custdesc_txtbox" cols="20" id="custdesc_txtbox"><?php echo $f8; ?></textarea></font></td> <td><input name="express2" type="text" id="express3" size="2" value="<?php echo "new link" ?>"></td> </tr> <p> <?php $i++; $row++; } ?> </table> </p> <p> </p> </form> Similar TutorialsI'm wanting to make a sitemap for my website but as it's quite big there are a lot of url's I need to include. I was wondering if anyone know's of a way this can be done using PHP. e.g. using PHP to generate a list of URL's. I had a think myself but wasn't sure how to do it. Thanks for any help. Hi there i have a big issues which is starting to cause me lots of stress. I have two tables one which is products and contains the following below and the other which is additionalCategories which the contains is also below. products id name image1 image2 image3 image4 image5 description department category subcategory Price additonalCategories id departmentID categoryID subcategoryID productID i have made a products upload script to my site where i can add products too it saves the category and subcategory id's in the fields above then if i wish to add the product to additional categories i do so and again this adds all the data to the addiotnalCategories table. however i can seems to be able to display this on the view products page i tried the below code but get no luck Code: [Select] <?php session_start(); $username=$_SESSION['username']; include_once"../includes/db_connect.php"; $cat=$_GET['cat']; ?> <!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>Untitled Document</title> </head> <body> <?php $query("SELECT products.name AS name, products.price AS price, addtionalCategories.productID AS productID FROM products, addtionalCategories WHERE category='$cat' AND products.id = addtionalCategories.productID"); while($fetch=mysql_fetch_object($query)){ echo"$fetch->name"; } ?> </body> </html> i need a way in which on the page it check the category id then finds all the products that are saved in the additionalCategories table then to find the data saved in the products table such as the name and price etc please any help will be appreciated thank you for reading Hello, I've created a page search to return results from my database inventory. On top of these results I would like to display a seperate list of five products not included in the search results but share the same sub_category_b (a column in my SQL table). Posted below is my primary query of the database. If anyone can help me out with this it would be appreciated. Code: [Select] $colname_product = "-1"; if (isset($_GET['title'])) { $colname_product = $_GET['title']; } mysql_select_db($database_inventory, $inventory); $query_product = sprintf("SELECT * FROM inventory WHERE item_name LIKE %s OR item_desc LIKE %s ", GetSQLValueString("%" . $colname_product . "%", "text"),GetSQLValueString("%" . $colname_product . "%", "text")); $product = mysql_query($query_product, $inventory) or die(mysql_error()); $row_product = mysql_fetch_assoc($product); I've fooled around with this one for some time and haven't come up with a clear cut answer. Thank you in advance! Hi, I am just wondering if there is any way that I can link Google Maps which will then link to my product stocklist - see attachment for what I am trying to achieve. Please let me know if this is possible. Thanks, I would like to customize my product-list page to display all my products in a grid with an ADD TO CART option for each product. That means i have two ADD TO CART button on the site, in productDetail.php there is a ADD TO CART button original from the tutorial, i need customize another ADD TO CART button on productList.php. Does anyone know how to accomplish this customization? . Please help because I am stuck with the coding for 3weeks Tutorial site: http://www.phpwebcommerce.com/plaincart/index.php productDetail.php: Code: [Select] <?php if (!defined('WEB_ROOT')) { exit; } $product = getProductDetail($pdId, $catId); // we have $pd_name, $pd_price, $pd_description, $pd_image, $cart_url extract($product); ?> <table width="100%" border="0" cellspacing="0" cellpadding="10"> <tr> <td align="center"><img src="<?php echo $pd_image; ?>" border="0" alt="<?php echo $pd_name; ?>" width="230" height="170"></td> <td valign="middle"> <strong><?php echo $pd_name; ?></strong><br> Price : <?php echo displayAmount($pd_price); ?><br> <?php // if we still have this product in stock // show the 'Add to cart' button if ($pd_qty > 0) { ?> <input type="button" name="btnAddToCart" value="Add To Cart >" onClick="window.location.href='<?php echo $cart_url; ?>';" class="addToCartButton"> <?php } else { echo 'Out Of Stock'; } ?> </td> </tr> <tr align="left"> <td colspan="2"><?php echo $pd_description; ?></td> </tr> </table> productList.php: Code: [Select] <?php if (!defined('WEB_ROOT')) { exit; } $productsPerRow = 2; $productsPerPage = 8; //$productList = getProductList($catId); $children = array_merge(array($catId), getChildCategories(NULL, $catId)); $children = ' (' . implode(', ', $children) . ')'; $sql = "SELECT pd_id, pd_name, pd_price, pd_thumbnail, pd_qty, c.cat_id FROM tbl_product pd, tbl_category c WHERE pd.cat_id = c.cat_id AND pd.cat_id IN $children ORDER BY pd_name"; $result = dbQuery(getPagingQuery($sql, $productsPerPage)); $pagingLink = getPagingLink($sql, $productsPerPage, "c=$catId"); $numProduct = dbNumRows($result); // the product images are arranged in a table. to make sure // each image gets equal space set the cell width here $columnWidth = (int)(100 / $productsPerRow); ?> <table width="100%" border="0" cellspacing="0" cellpadding="20"> <?php if ($numProduct > 0 ) { $i = 0; while ($row = dbFetchAssoc($result)) { extract($row); if ($pd_thumbnail) { $pd_thumbnail = WEB_ROOT . 'images/product/' . $pd_thumbnail; } else { $pd_thumbnail = WEB_ROOT . 'images/no-image-small.png'; } if ($i % $productsPerRow == 0) { echo '<tr>'; } // format how we display the price $pd_price = displayAmount($pd_price); echo "<td width=\"$columnWidth%\" align=\"center\"><a href=\"" . $_SERVER['PHP_SELF'] . "?c=$catId&p=$pd_id" . "\"><img src=\"$pd_thumbnail\" border=\"0\" width=\"230\" height=\"170\"><br>$pd_name</a><br>Price : $pd_price<br>"; // format display add to cart echo "<input type=\"button\" name=\"btnAddToCart\" value=\"Add To Cart >\" onClick=\"window.location.href='<?php echo $cart_url;?>';\" >"; // if the product is no longer in stock, tell the customer if ($pd_qty <= 0) { echo "<br>Out Of Stock"; } echo "</td>\r\n"; if ($i % $productsPerRow == $productsPerRow - 1) { echo '</tr>'; } $i += 1; } if ($i % $productsPerRow > 0) { echo '<td colspan="' . ($productsPerRow - ($i % $productsPerRow)) . '"> </td>'; } } else { ?> <tr><td width="100%" align="center" valign="center">No products in this category</td></tr> <?php } ?> </table> <p align="center"><?php echo $pagingLink; ?></p> Product-functions.php: Code: [Select] <?php require_once 'config.php'; /********************************************************* * PRODUCT FUNCTIONS **********************************************************/ /* Get detail information of a product */ function getProductDetail($pdId, $catId) { $_SESSION['shoppingReturnUrl'] = $_SERVER['REQUEST_URI']; // get the product information from database $sql = "SELECT pd_name, pd_description, pd_price, pd_image, pd_qty FROM tbl_product WHERE pd_id = $pdId"; $result = dbQuery($sql); $row = dbFetchAssoc($result); extract($row); $row['pd_description'] = nl2br($row['pd_description']); if ($row['pd_image']) { $row['pd_image'] = WEB_ROOT . 'images/product/' . $row['pd_image']; } else { $row['pd_image'] = WEB_ROOT . 'images/no-image-large.png'; } $row['cart_url'] = "cart.php?action=add&p=$pdId"; return $row; } ?> any help will be greatly appreciated This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=343748.0 I am wanting to create a basic product listing page for a product category called "Belts". My latest attempt was this, but I got an error: PHP Code: Code: [Select] $query = "select * from products"; $result = mysql_query($query); while($row=mysql_fetch_assoc($result)) { print ".$row['name'] where category = 'Belts'.$row['colour'] where category = 'Belts'"; } Quote PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING This is what my MySQL table looks like: http://i54.tinypic.com/2j1si8w.png I image what I am trying to do will print "Somename Black, ProductName2 Brown"? I'm not really interested in styling at the moment, I just want to see the PHP-MySQL work at the most basic level. I am unsure what the error cosde means. Can anyone see a fault in my code? hey all so I have this bit down: Code: [Select] $query="SELECT `2010 Region Code` AS codes FROM locations"; $results = mysql_query($query); $options=""; $options = "<select location='codes'>"; while($nt=mysql_fetch_assoc($results)) { $thing=$nt["codes"]; $options.="\r\n<option value ='{$nt['codes']}'> {$nt['codes']}</option>"; } $options .="\r\n</select>"; echo $options; what I'm trying to do is grab the selection from the drop down and display it as a table (the sql query would be extended should we manage to figure this one out I've tried Code: [Select] echo"<form name='LOCATIONS' action='".$_SERVER['PHP_SELF']."' target='iframe' method='post'>"; any ideas? The Script:
<?php include($_SERVER['DOCUMENT_ROOT'] . "/gallerysite/header.php"); ?> <?php include($_SERVER['DOCUMENT_ROOT'] . "/gallerysite/connect.php"); ?> <?php if(isset($_GET['thread_id'])) { $tqs = "SELECT * FROM `thread` WHERE `id` = '" . $_GET['thread_id'] . "'"; $tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc)); $row = mysqli_fetch_assoc($tqr); ?> <div class="div"> <h1>Admin Modify</h1> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="text" name="title" value="<?php echo $row['title']; ?>"/><br/> <textarea type="text" name="caption"><?php echo $row['caption']; ?></textarea> <input type="submit" name="admin_update" value="Update" /> </form> </div> <?php // This prints e.g.: // 47 echo "The Thread ID: "; echo $_GET['thread_id']; if(isset($_POST['admin_update'])){ $tqs = "UPDATE `thread` SET `title` = '" . $_POST['title'] . "', `caption` = '" . $_POST['caption'] . "' WHERE `id` = '" . $_GET['thread_id'] . "'"; $tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc)); } } ?> <?php include($_SERVER['DOCUMENT_ROOT'] . "/gallerysite/footer.php"); ?>I do not see why this is not working. The "UPDATE" SQL statement has worked without the "WHERE" part and modified all of the posts. (With this the database connection works too.) Though, this statement does work in PhpMyAdmin: UPDATE `thread` SET `title` = 'testing', `caption` = 'testing' WHERE `id` = '47';I added the "WHERE" part to the script and now it is not modifying the text in the table anymore, basically the "updates" do not happen. What could be the issue here? Any suggestions are much appreciated. Also, I have used this way of "syntax style" in PHP, perhaps somebody could be modifying the "UPDATE" SQL statement into a different syntax style so I can try it out, I would much appreciate it. I would also like to ask how the "syntax style" I have used is and if it can be better than this? Edited by glassfish, 20 October 2014 - 05:52 AM. Hi My problem is that text that is in my database are showing up next to each other in a line rather than on seperate lines, normally I would have just used <br> but as it's generated from my sql I don't know how to do it. Code: [Select] <ul id="headlines"> <?php foreach ( $results['articles'] as $article ) { ?> <a href=".?action=viewArticle&articleId=<?php echo $article->id?>"><?php echo htmlspecialchars( $article->title )?></a> <?php } ?> </ul> Anyone have any idea? Thanks Hi am in processes of making a bespoke CMS for a project in uni am having a problem with my scrip basically i have three php files i have content which echos out the database tables i wish to edit with a link to an update_content page when u click on that it bring u too update_content.php which allows the user to modifier the content in the tables but when i hit update am getting a Parse error: syntax error, unexpected T_IF in line 4 of my update_ac file any help would be great cheers richie <?php require("includes/connection.php") // If form button has been pressed then do the following if(isset($_POST['update'])){ // Get id of post $id = $_GET['id']; $header = $_POST['header']; $content = $_POST['content']; // Update database table $query = "UPDATE pages SET header = '$header', content = '$content' WHERE id = '$id'"; $result = mysql_query($query); if ($result){ echo "Successfully edited entry"; } else { echo "There was error editing entry"; } } ?> Hi friends. I want to php code on how i can modify my retrieved database values from a particular table before echoing out. Please could you help me correct the code. Or if there is any better way of editing loop datas before printing out, please kindly drop the code for me. Thanks <?php please if there is any better way of editing loop values from mysql database before printing out, please kindly drop the code for me. Thanks Hi,
I have this snippet in my page:
<?php echo $EM_Booking->get_price(true) * $EM_Booking->get_spaces(); ?>The page executes with no hitches except the price is not multiplied by the spaces. I get and echo of "0". I'm new to this. Any help would be greatly appreciated and thanks! Hi, I have a regular MySQL query that displays it's results to the screen in a browser as an HTML table, all nice and fruity. The managers who use this function like to send out the results to staff, currently they simply take a screen shot and paste it into an email to send out to everyone - quite an overhead on the email system, company network, not to mention the time taken to do the screen shot and paste it into an email in the first place. It would be good if I could include a standard HTML form button (preferably) or link on the results page to shove the displayed results to Outlook as an email, that contains the table all ready for the manager to add in what ever they want to the email and then send (usually to 'all@mysite.com' but it would be useful if they could change or add to this as they see fit). This is kind of what happens with a normal mailto HTML tag, except I want it to contain the MySQL query result too. This is the existing table output routine (something I inherited): Code: [Select] /* Output data into a HTMl table */ echo "<p>"; echo "<table align=center width=800 border=\"1\">"; echo "<tr>"; echo "<td BGCOLOR=\"#ffcc00\"><strong>Agent name</strong></td> <td BGCOLOR=\"#ffcc00\"><strong>Number of calls made / handled</strong></td> <td BGCOLOR=\"#ffcc00\"><strong>Average call minutes</strong></td> <td BGCOLOR=\"#ffcc00\"><strong>Total mins (inc hours + secs rounded)</strong></td> </tr>"; while($row = mysql_fetch_row($numresults)) { echo "<tr>"; for($i=0; $i < mysql_num_fields($numresults); $i++) { echo "<td align=center width=443>$row[$i]</td>"; } echo "</tr>\n"; } echo "</table></p>"; I am creating a drink recipe site. So far I have created the mysql table and the page where i can enter in the drink name ingredients ect. and it inserts into the table. Could some one point me in the right direction where when I make an entry into this table a new page is created from the content. How would I go about doing this? Hi there, I'm trying to get the full Product Name in the <title> of each of the product pages - I can't seem to figure out what to put in the product_info.php... I've tried a few different options but I'm not great with php Here's what I have currently but it creates errors... <script language="javascript"><!-- document.write('<title><?php echo TITLE; ?> : <?php echo $product_info['products_name']; ?> </title>'); //--></script> Hope someone can help - thanks so much! Hello, New to this forum so appreciate the patience and apologize for any breaking of etiquette. I currently have a PHP script which generates the appropriate HTML headers and body packet and would like to place it in either a Thunderbird outbox so that Thunderbird will handle sending it or put it in the Evolution outbox so Evolution will handle the actual sending of the e-mail. I've scoured the internet looking for an answer and I know it is possible because I wrote a bash script to do it a few years back that I can't find. Would appreciate any insight. Thanks, I have a submit.php file that includes the following jQuery code: <script> [...] request.done(function( json ) { jQuery('input[name=thumbnail-url]').val(json.thumbnail_url); jQuery('input[name=job_title]').val(json.title); jQuery('textarea[name=htmlcode]').val(json.html); [...] </script> I need to remove jQuery('textarea[name=htmlcode]').val(json.html); and pass the "json.html" value into a PHP variable in another php file (functions.php). The code in the functions.php file is already there. The thing i need to do (and i am seriously struggling with it) is placing the value of json.html into a $phpvariable that i can then call from the function.php file. Do you need any more info for this issue? Thanks. |