PHP - Split Items Into Parts, Then Create A Select List From Results
Hi. I will try and explain simply.
I have a list of item codes eg.
size1 Acolor1
size1 Bcolor3
size1 Bcolor1
size1 Acolor3
size1 Acolor4
size2 Acolor1
size3 Bcolor1
size3 Bcolor2
size3 Bcolor2
size3 Acolor1
I want to take these and split them into parts:
size1 Acolor2
size1 Bcolor3
etc.
Then I want to create a form with 2 dropdowns. The first option would just have all unique sizes so:
size1
size2
size3
Then when one is selected, option 2 would show the colours available in that size.
Is there a standard way of doing this? Can I use PHP to create the array and then jquery to display and hide the options?
I'm totally stuck and i'm not just looking for somebody to code it all for me. any help would be greatly appreciated
thanks
Sam
Similar TutorialsHi , I have one question .. Can I split showing of content of dynamic list in 2 parts , when I echo list in code .. Code: [Select] <?php // Run a select query to get my letest 8 items // Connect to the MySQL database include "../connect_to_mysql.php"; $dynamicList = ""; $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 8"); $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="2" cellspacing="2" cellpadding="2"> <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="2" /></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(); ?> Code: [Select] <p><?php echo $dynamicList; ?><br /> </p> It works ok, and putting my files, everything works, but when I put 8 pictures with price and other details, it just show one image with details and another image below with details, and the third image below and so on .. Can I split dynamic list to show 4 images with details on the left side and 4 on the right side? Thank you in advance for help , if is possible hello guys
i wand to split the 24h of a day to parts and select the time that i wand to start the 24h circle to count!
lets say
i give 2 int variables
$day_starts_to_count_from=00;
$split_day_to_parts=4;
so!
$hours_per_part = 24/$split_day_to_parts;
this gives me $hours_per_part = 6 (i split the 24h every 6hr)
how to know the part of my current hour?
lets say the system time is 15:35
how to find that im at the 3d part 12:00-18:00 if the 24h circle starts to count from 00:00
thanks in advance
My query gets the results and orders by one of the fields. Once I get the MySQL results I would like to find the first entry that has a letter as the first character of the same field that the list was ordered by, then split the results in to two parts and swap them. So that the results that have a letter at the start of the same sorted field are as the begining and the results that have the numbers as the start at the end of the array. But also so that the array works the same way as the original results string, so i can use say $results['mysqlfield'] I'm getting the number of friends in each STATE. How do I split the results in $returnS? $query = "SELECT statez, COUNT(statez)FROM abs GROUP BY statez"; $results = mysql_query($query); $returnS=""; while($line = mysql_fetch_array($results)) { $returnS.= $line['COUNT(statez)'].",,".$line['statez'].",,,"; } echo $returnS; mysql_close($link); ?> Hello: I am having a brain fart on how to get this done and any ideas would greatly be appreciated. I am working on a in-house mailbox project and have my first problem. I am going to try and explain this a simple as possible as putting the words from my head to screen harder than I thought. I have a page with 1 div called msgs_main. Inside of that div are 2 more, top one called msgs_msgs and the bottom called msgs_content. The msgs_msgs div contains a simple mysqli query displaying the records that correspond to the user. What I want/need is that when the user clicks one of the rows, the contents of the message are displayed in the msgs_content div. I could provide the code, if it helps, but I am not really looking for answered code, but a process to learn from, like. "First, get a join and have all the records display in the msg_msgs div. Display them all to see that all the data is there. Later in production, remove the un-necessary fields from top div". Then research .... etc How hard would something like this be? I have a database with all my users. I need an empty list and when a user clicks a button "Add me to the list" they are added to the first position in the list Slots 1. Tom 2. 3. 4. 5. Later, Jerry wants to be added to the list. So this happens Slots 1. Jerry 2. Tom 3. 4. 5. More people join the list 1. Bob 2. John 3. Jerry 4. Tom 5. Tom gets upset clicks the same button to join the list again, and he's bumped back up to first place. Slots 1. Tom 2. Bob 3. John 4. Jerry 5. Is this possible? And is so, how would I go about getting started on such a thing? I've been using PHP for about a year and a half. so far I have: $crawler->filter('li.date, dt > a, li.style')->each(function ($node) { $output = $node->text()."\n"; $array = explode("\n", $output); $data = array_chunk($array, 3); // print_r($data); foreach ($data as $row) { [$date, $title, $type] = array_pad($row, 3, null); // here you have your variables print 'Date: '.$date; print 'Title: '.$title; print 'Type: '.$type; } }); and this outputs: QuoteDate: Saturday 13th Jun 2020Title: Type: Date: Alice in Chains UKTitle: Type: Date: Metal/ RockTitle: Type: Date: Monday 29th Jun 2020Title: Type: Date: Cage the ElephantTitle: Type: Date: Funk/ RockTitle: Type: Date: Friday 31st Jul 2020Title: Type: Date: The CureheadsTitle: Type: Date: Indie/ RockTitle: Type: Date: Thursday 20th Aug 2020Title: Type: Date: CreeperTitle: Type: Date: PunkTitle: Type: Date: Saturday 22nd Aug 2020Title: Type: Date: Fleetwood BacTitle: Type: Date: Pop/ RockTitle: Type: Date: Monday 31st Aug 2020Title: Type: Date: GZATitle: Type: Date: Hip HopTitle: Type: Date: Saturday 5th Sep 2020Title: Type: Date: Cock SparrerTitle: Type: Date: Only $date variable is set for each?! please help??
it should be: Date: Saturday 13th Jun 2020Title: Alice in Chains UKType: Metal/ Rock Date: Monday 29th Jun 2020Title: Cage the ElephantType: Funk/ Rock and so on.... Hi, Im trying to learn how to build a shopping cart system, im have a few problems and im not sure where im going wrong, it looks as though im getting an item into the session, but it looks like when i add another it over writing the first one, and im having trouble trying to echo it out. Here is what i have atm Code: [Select] session_start(); include('functions.php'); $pid = $_GET['product']; $q = $_GET['qty']; if($_GET['function']=="add") { echo "add " . $_GET['product']; $_SESSION['cart']=array(); $_SESSION['cart']['productid']=$pid; $_SESSION['cart']['qty']=$q; } print_r($_SESSION['cart']); echo showCart(); Am i way off on my code? regardless of how many things i try to add to session, all i can print out is the last one i entered. Cheers Preferably using PHP, I'd like to create X number of colors based on X number of items and using a predefined color range. For example: ITEM VALUE 1 1,234,567,890 2 234,567,890 3 34,567,890 4 4,567,890 5 567,890 Color Range red = largest value green = medium value blue = smallest value Example Item 1 gets color red Item 2 gets whatever color naturally comes between red and green Item 3 gets color green Item 4 gets whatever color naturally comes between green and blue Item 5 gets color blue Requirements The code should be able to handle any number of items. 5 items was just an easy example. Some Thoughts - Number of items = number of colors - How to divide a color range into number of items? - Colors can be represented in decimal format: red=255,000,000 blue=000,000,255 - Can a formula be created, based on the color decimal format, to solve this problem? I think it's the math portion of the problem that I'm stuck on right now. Thanks for your help, Nick Hi, In my mysql database i have a text input option, in the registration form and edit my details form i have a multiple select dropdown list, which user selects options to populate the text input box, which ultimately populates the text field in the mysql database. All works perfectly. The dropdownlist consists of 3 parts <optgroups> first is current selection (what is the usesr current selection)works fine, The second <optgroup> is existing words, what words we(the site) have given as options, and the third <optgroup> is the words that others have used. This is where im having a small problem. Because its a text field when i call the data from the database, it calls the entire text box as a single option in my select list.. I want to break the words in the text field (at the comma) and have them listed each one as an option in the select list. Example what i need: Words in text box:(my input allows the "comma") word1, word2, word3, word4, word5, word6, How i want them called/displayed: <option value=\"word1\">word1</option> <option value=\"word2\">word2</option> <option value=\"word3\">word3</option> <option value=\"word4\">word4</option> <option value=\"word5\">word5</option> <option value=\"word6\">word6</option> here's my code: $query = "SELECT allwords FROM #__functions_experience WHERE profile_id = '".(int)$profileId."' LIMIT 1"; $original_functionsexperience =doSelectSql($query,1); $query = "SELECT allwords FROM #__functions_experience WHERE profile_id = '".(int)$profileId."' LIMIT 1"; $functionsexperiencelist=doSelectSql($query); $funcexpList ="<select multiple=\"multiple\" onchange=\"setFunctionsexperience(this.options)\">"; foreach ($functionsexperiencelist as $functionsexperienceal) { $selected=""; if ($functionsexperienceals->allwords == $original_functionsexperience) $selected=' selected="selected"'; $allwords=$functionsexperienceal->allwords; $funcexpList .= "<optgroup label=\"Current selection\"> <option value=\"".$allwords."\" ".$selected." >".$allwords."</option> </optgroup> <optgroup label=\"Existing Words\"> <option value=\"existing1,\">existing1</option> <option value=\"existing2,\">existing2</option> <option value=\"existing3,\">existing3</option> <option value=\"existing4,\">existing4</option> <option value=\"existing5,\">existing5</option> <option value=\"existing6,\">existing6</option> </optgroup> <optgroup label=\"Others added\"> //heres problem <option value=\"".$allwordsgeneral."\">".$allwordsgeneral."</option> </optgroup>"; } $funcexpList.="</select>"; $output['FUNCEXPLIST']=$funcexpList; The result im getting for optgroup others added: word1, word2, word3, word4, word5, how can i get it like this: <option value=\"word1\">word1</option> <option value=\"word2\">word2</option> <option value=\"word3\">word3</option> <option value=\"word4\">word4</option> <option value=\"word5\">word5</option> <option value=\"word6\">word6</option> hello all, I was hoping someone could help me figure out how to add sizes to my shopping cart. Right now the items add just fine. The site sells shirts and I'm having trouble displaying the sizes once selected and added to the cart. It will post the size selected, but if the customer tries to add another shirt the size will overwrite the last. Any help is appreciated. Heres how I add items to the cart... Code: [Select] session_start(); // Process actions $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'empty': if($cart) { unset($cart); } break; case 'add': if ($cart) { $cart .= ','.$_GET['product_id']; } else { $cart = $_GET['product_id']; } break; The form with the size selection and add to cart button.. Code: [Select] <form action="cart.php?action=add&product_id=<?php echo $row_rs_products['product_id'] ?>" method="POST" name="addcart" id="addcart"> <table width="300" border="0"> <tr> <td><label for="sizes"></label> <select name="product_size" id="product_size" title="<?php echo $row_rs_products['product_size']; ?>"> <?php do { ?> <?php } while ($row_rs_sizes = mysql_fetch_assoc($rs_sizes)); $rows = mysql_num_rows($rs_sizes); if($rows > 0) { mysql_data_seek($rs_sizes, 0); $row_rs_sizes = mysql_fetch_assoc($rs_sizes); } ?> </select></td> <td><input type="submit" name="submit" id="submit" value="add to cart"> function displaying the cart.. Code: [Select] function showCart() { global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; $output[] = '<table>'; // start div $output[] = '<div id="cart_table">'; // $output[] = '<tr>'; $output[] = '<td><h4>Product</h4></td>'; $output[] = '<td><h4>Item No.</h4></td>'; $output[] = '<td><h4>Price</h4></td>'; $output[] = '<td><h4>Size</h4></td>'; $output[] = '<td><h4>Quantity</h4></td>'; $output[] = '<td><h4>Price Total</h4></td>'; $output[] = '<td><h4> </h4></td>'; $output[] = '</tr>'; //new row foreach ($contents as $product_id=>$qty) { $sql = 'SELECT * FROM products WHERE product_id = '.$product_id; $result = $db->query($sql); $row = $result->fetch(); extract($row); // $output[] = '<tr>'; $output[] = '<td><a href="product.php?product_id='.$product_id.'">'.$product_title.'</a></td>'; $output[] = '<td>'.$product_plu.'</td>'; $output[] = '<td>$'.$product_price.'</td>'; // //$output[] = '<td>'.$product_size.'</td>'; $output[] = '<td>'.$_POST['product_size'].'</td>'; // $output[] = '<td><input type="text" name="qty'.$product_id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '<td>X $'.($product_price * $qty).'</td>'; $total += $product_price * $qty; $output[] = '<td><a href="cart.php?action=delete&product_id='.$product_id.'" class="r">Remove</a> </td>'; $output[] = '</tr>'; //end div $output[] = '</div>'; } $output[] = '</table>'; $output[] = '<p>Grand total: <strong>$'.$total.'</strong></p>'; $output[] = '<div class="float-right"><button type="submit">Update cart</button>'; $output[] = '</form>'; Hi first tyvm for reading my help request me and my friend ar trying to build a order form (see png file ^^) so the main idea is some on go to order form.php
in that order form they fil in thear info like name, adress you know ^^
thean here is the treaky part at the and of the form they kan add products to there order by selecting it or search it from the drop down list the items in the dropdown list come from msql
the client can add more or delete items by clicking - or + whean the clint click send the client need to get a mail whit there a list of what theay have orderd and there unic order number wel so far we can do that but we wont to send another list to the company of order where the added products in the order ar sorted out based on the product id number
this is what we have so far http://clientconstru...sion.nl/valeri/
tyvm again voor anyone who read this ^^
Attached Files
bestel-form.png 37.78KB
0 downloads Hi,
I am looking for a tutorial or code sample I can use to learn MySQLi pagination with an option to select items per page, like the attached screenshort.
Any help is grately appreciated.
Regards.
joseph
Attached Files
table-pagination.jpg 32.87KB
0 downloads I coded the following but some parts are not working (the "curveball" mentioned at the end). How would YOU do this? I have a page (A) displaying a form with a textarea field using a WYSIWYG interface. The user will enter a list of unordered items and upon submit the string will look something like this: This is my list of food items: <ul> <li> Lettuce </li> <li> Tomatoes </li> <li> Eggs </li> <ul> Upon submit, I need to give each list item an unique id and store this id along with the text next to it in a separate table: List_item_id List_item_text List_item_state food_1 Lettuce food_2 Tomatoes food_3 Eggs The user will then land in another page with a form displaying the list. The text is now in the page itself and not in a textarea. Instead of the bullets a dropdown list appears, and the user can select "buy" or "sell" for each list item. This page (B) looks something like this: <form> This is my list of food items: <br><select name="food_1"> <option value="buy">Buy</option> <option value="sell">Sell</option> </select> Lettuce <br><select name="food_2"> <option value="buy">Buy</option> <option value="sell">Sell</option> </select> Tomatoes <br><select name="food_2"> <option value="buy">Buy</option> <option value="sell">Sell</option> </select> Eggs <input type=submit value="submit"> </form> When the user hits "submit" the table with the list items will be updated with the values selected in the dropdown list: List_item_id List_item_text List_item_state food_1 Lettuce Buy food_2 Tomatoes Buy food_3 Eggs Sell The next time the user goes to Page B the list will remember the states. Here's the curveball: At any point the user may click on "EDIT LIST" on Page B so they may add more items (at the begining, middle or end of the string). On edit mode the list items should appear as bullets again inside the WYSIWYG interface. Keep in mind that some of the text in the string may not be a list item (ie, "this is my list of food...") Hello! We our creating an admin page to display a list of all the items within a mysql database, these items are within a table called "item". Each item is categorized, these categories are in a table called "category" each category has an ID. There is then a table called "links" which links the items to their category using ID's. We want to display each item by their category with an edit and delete button. We have it so all the items display with the two buttons in no specific order however we are not too sure how to make it so they all display via their category. Here is the code we are currently using: Code: [Select] <?php $itemlist = mysql_query("SELECT item.item_name, item.item_description, item.item_image, item.item_price, item.item_id FROM item ORDER BY item.item_id ASC"); $item_count = 0; ?> <?php while( $row = mysql_fetch_array($itemlist) ){?> <?php if(($row['item.item_name'] == 1) && (isset($item_count) && $item_count < 1)) { ?> <?php $item_count ++; } ?> <li class="title"> <h3><?php echo $row['item_name'];?></h3><br /> <form action="ourworkadmin.php" method="get"> <input type="hidden" name="item_id" value="<?php echo $row['item_id'];?>" /> <input name="edit" value="Edit" type="submit" /> <input name="remove" value="Remove" type="submit" /> </form> </li> <?php } ?> </ul> <!--Close-items_list--> </div> Any help would be appreciated! Thank you!!! I want visitors to be able to sort the results on my Browse Documentaries page by popularity, date, and type. The only way I know how to do this is to create a separate page for each sorting arrangement and provide a link to each page. Is there any way of doing it on a single page?
I am guessing that I can do things like that with Javascript or jQuery. Is that correct?
I am writing a CRON job that will execute daily. First it will identify from a MySql table the date in a field 'FAPforSale_repost35' If the date is the today date it will then execute commands to delete photo images in a directory, delete the directory, and finally remove the record from the database.
I am on step one which is to build the array of records that match the days date. When I run the code, there are no errors but I am not getting results even though the records in the test table are set for today. Below is the select
<?php define( "DIR", "../zabp_employee_benefits_processor_filesSm/", true ); require( '../zipconfig.php' ); require( DIR . 'lib/db.class.php' ); require_once( $_SERVER['DOCUMENT_ROOT'] . '/_ZABP_merchants/configRecognition.php' ); require_once( $_SERVER['DOCUMENT_ROOT'] . '/_ZABP_merchants/libRecognition/MailClass.inc' ); $todayRepost35 = date("Y-m-d"); echo $todayRepost35; function repostEndSelect() { global $db; $this->db = $db; $data = $this->db->searchQuery( "SELECT `FAPforSale_IDnumber`, `FAPforSale_image1`, `FAPforSale_image2`, `FAPforSale_image3`, `FAPforSale_repost35` FROM `FAP_forSaleTest` Where `FAPforSale_repost35` = '$todayRepost35' "); $this->FAPforSale_IDnumber = $data[0]['FAPforSale_IDnumber']; $this->FAPforSale_image1 = $data[0]['FAPforSale_image1']; $this->FAPforSale_image2 = $data[0]['FAPforSale_image2']; $this->FAPforSale_image3 = $data[0]['FAPforSale_image3']; $this->FAPforSale_repost35 = $data[0]['FAPforSale_repost35']; echo $this->FAPforSale_IDnumber; echo $this->FAPforSale_image1; echo $this->FAPforSale_image2; echo $this->FAPforSale_image3; echo $this->FAPforSale_repost35; } // ends function... echo( ' Finished...' ); ?>Thanks in advance for any suggestions or direction. Chapter two will be when I start testing the commands to delete. here is some simple code for getting and displaying fata from a database Code: [Select] $sql="SELECT * FROM messages WHERE m_id = '".$id."'"; $result = mysql_query($sql); <table border='0' cellspacing="4"> while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<th>Message</th>"; echo "</tr>"; echo "<tr>"; echo "<td>" . $row['message'] . "</td>"; echo "</tr>"; } now ive used that while loop to display those results how can i do that again without having a new SQL statement. i cant do 2 while loops because the first one has already got to the end of the amount of rows basically how can i have another while loop displaying those same results again? i have a php script: $sql5 = "select *,count(*) from rc_language_type_assoc_table group by language_type_id"; $result5 = mysql_query($sql5); //not correct $count5 = mysql_num_rows($result5); //not correct $myFile = "/home/rainbowcode/StatsFile.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $sql5."\n"); the above is not what i want, i want the actual result set of the select to print in my StatsFile how can i achieve this please??? Hi I have been given a task to create some SQL reports. One of the reports is to display all the customers who have purchased a certain product based on user selection and then have those results able to be extracted to a mailing list. So ive got the report done. Some drop down boxes allow a user to select a product and once submitted the results are then displayed. But i dont even know where to begin with extracting those results to a mailing list. Could someone help me please? What method should I use? and where do i begin? BTW im a rookie with PHP/Mysql ive just got my first job since leaving university and this is a task ive been given at work so any quick and helpful replies are greatly appreciated Thanks in advance. |