Jump to content

phpdumdumb

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Everything posted by phpdumdumb

  1. That would help wouldn't it! I have a DB with a featured items (FeatItm) column that lists whether a product is featured or not (0 or 1) and I have to only display that on a webpage and sort the primary key. In my code under sort == 6, I put what I believe would accomplish that, but I'm not sure how to piece it together.
  2. Good evening, I'm doing a class assignmet where we have to do various sorts getting the info a DB we created I needed help with my last sort (sort ==6) where I have to display only the featured items I have and sort by primary key. I pasted the code below Can someone help? Thanks in advance. $sort = $_GET["sort"]; if ($sort == 2) $orderby = "ProName ASC"; else if ($sort == 3) $orderby = "Cost ASC"; else if ($sort == 4) $orderby = "CatId ASC"; else if ($sort == 5) $orderby = "Rtng ASC"; else if ($sort == 6) { $feature = if(isset($_GET["FeatItm"])) //if(isset($_GET[$name]) && $value==$name."=".$_GET[$name]) $orderby = "Cost ASC"; } else // Order by primary key (also will be the default if no "sort" value exists in your GET) $orderby = "PID ASC"; $sql = "SELECT * FROM project_products LEFT JOIN project_categories ON project_products.CatId = project_categories.CatId WHERE ".$feature." = 1 ORDER BY ".$orderby." LIMIT 0, 30 "; $result_products = mysql_query($sql); while($products = mysql_fetch_assoc($result_products)) { echo "<div class='product'>"; echo " <div class='prod-image'><img src='".$products["ImgURL"]."' /></div>"; echo " <div class='prod-info'>"; echo " <h3>". $products["ProName"] . "</h3>"; echo " <p>". $products["SDesc"] . "</p>"; echo " <p>". sprintf("$%01.2f", $products["Cost"]) . "</p>"; echo " </div>"; echo "</div>"; }
  3. Thanks, will do that from now on.
  4. sorry, I forgot to put the error I was getting Warning: array_multisort(): Argument #1 is expected to be an array or a sort flag in /var/www/kgibbons/A1Testing/products.php on line 145 I'm trying to to sort the items by product, cost, category, and in order from highest to lowest rated
  5. Good night all, I'm new at learning php and I'm trying to do an array multisort and it aint working! Here is the code, I'd appreciate any help, I don't know where I'm going wrong, here's the code: <html> <head> <meta charset="UTF-8"> <title>Index</title> <link href="styless.css" rel="stylesheet" type="text/css"> </head> <STYLE type="text/css"> div#wrap { margin: 0 auto; width: 800px; </style> <body> <div id="wrap"> <h2 style = text-align:center> <div id="wrapper"> <div id="header"><img src="images/banner.png" width="800" height="150" longdesc="http://sweb.yorkvilleu.ca/kgibbons/IDM143/A1/index.php"></div> <div id="menu"> <p align="center"><a href="register.php">REGISTER </a>| <a href="user.php">USER</a> | <a href="products.php">PRODUCTS</a></p> </div> <?php error_reporting(E_ALL); ini_set("display_errors", 1); $allproducts = array( array ( 'name'=>"TMA-1 Headphones", 'category'=>"DJ Accessories", 'cost'=>('199.99'), 'image'=>"tma-1_large.jpeg", 'description'=>"AIAIAI and Danish design firm KibiSi have specifically addressed all the headphone needs of the DJ and more. Plus, the minimalist, modern design in itself is stunning. Lab recommended.", 'featured'=>true, 'rating'=>4 ), array( 'name'=>"Technics 1210 M5G Turntable", 'category'=>"DJ Gear", 'cost'=>('1500.00'), 'image'=>"Tech12_large.jpeg", 'description'=>"The 1210 M5G is subtitled the grand master and takes over the top of the line position for Technics' line of turntables. The major improvement here, and the feature which is exclusive to the 1210M5G, is the pitch control. It is now completely digital, which means you should never have the problem of mismatched pitch ranges, and it also gives you the ability to choose between two separate pitch ranges: the standard +/-8 range and the larger +/-16 range.", 'featured'=>true, 'rating'=>5 ), array( 'name'=>"DJM-850 DJ Mixer", 'category'=>"DJ Gear", 'cost'=>('1699.00'), 'image'=>"djm850-morecolors-390_large.png", 'description'=>"The DJM-850 follows Pioneer's traditional mixer layout, featuring a variety of advanced sound effects that provide DJs with virtually limitless possibilities when mixing their music. Pioneer includes a new BEAT COLOR FX function, which changes effects by linking the audio input from each channel.", 'featured'=>false, 'rating'=>3 ), array( 'name'=>"Traktor Kontrol X1 DJ Controller", 'category'=>"DJ Gear", 'cost'=>('199.00'), 'image'=>"X1_large.jpeg", 'description'=>"Native Instrument's TRAKTOR KONTROL X1 is the first official TRAKTOR controller for use with any DJ software. Whether you are a DVS timecode or software DJ, simply connect the TRAKTOR KONTROL X1 to a computer running TRAKTOR (or other performance software) and gain instant control of your decks and effect parameters. Robust rotary knobs with a heavy-duty feel and backlit buttons provide precise visual and tactile status feedback - letting you delve deep inside your program without having to touch your computer.", 'featured'=>false, 'rating'=>4 ), array( 'name'=>"Clear Traktor Pro 2/ Kontrol S4 Keyboard Cover", 'category'=>"DJ Accessories", 'cost'=>('12.50'), 'image'=>"KBTRKT_large.jpeg", 'description'=>"Traktor Pro 2 and Traktor Kontrol S4 users can now play and mix tracks faster with this custom designed keyboard cover. Each button is color coded to take advantage of Traktor Pro 2’s extensive keyboard shortcuts for both the left and right turntables including control and alt key combinations. ", 'featured'=>false, 'rating'=>4 ), array( 'name'=>"Traktor Scratch Kontrol Vinyl MK2", 'category'=>"DJ Accessories", 'cost'=>('12.50'), 'image'=>"traktorcontrolmk2-more390_large.png", 'description'=>"MK2 Control vinyl for use with Traktor versions 2.1.1. and higher (will not work with older versions). Boasts the tightest time code control of any system to date for precision mixing and scratching. Marking stickers included.", 'featured'=>false, 'rating'=>4), array( 'name'=>"Crane Standard DJ Laptop Stand White", 'category'=>"DJ Accessories", 'cost'=>('79.00'), 'image'=>"Cranestand_large.jpeg", 'description'=>"The Crane Standard DJ Laptop Stand comes in at a much lower price point than the bestselling Crane Stand Pro, but still features the same convenient one-piece folding design and dj-friendly functionality. In addition, the Standard is quite durable (it weighs a bit more than the Pro), easy to set up, and includes removable accessory tray (for your interfaces) and a nylon carrying bag.", 'featured'=>false, 'rating'=>2 ), array( 'name'=>"Lacie USB 2.0 A to B Flat Cable, 4ft Blue", 'category'=>"DJ Accessories", 'cost'=>('9.99'), 'image'=>"usb-blu_large.jpeg", 'description'=>"Cool flat USB cables from Lacie. These cables stand out from the rest with a unique design by French design firm Item. Since the cables are flat, they are easy to coil and to carry - you'll never have to deal with another tangle of wires behind your desk or in your laptop bag. Perfect for use with your external hard drive or digital interface. Each cable comes with 24 adhesive labels, so you can customize your cables and always know which device is plugged in.", 'featured'=>false, 'rating'=>3 ), array( 'name'=>"Odyssey Black Label Turntable Flight Case", 'category'=>"DJ Gear", 'cost'=>('152.95'), 'image'=>"ODY-FZ1200BL1_large.jpeg", 'description'=>"All-black turntable flight case from Odyssey. The sturdy Black label case is constructed with the same high standards as the regular ATA approved Flight Zone case, but with the aluminum trim and hardware anodized and powder-coated in black for a sleek look. The inner compartment is lined with dense foam to keep your turntable safe and features a valley for ventilation and an area for cable management. An essential piece for DJ's that bring their own tables to gigs. Fits most turntables.", 'featured'=>true, 'rating'=>4 ), array( 'name'=>"Mono 365 DJ Pack", 'category'=>"DJ Accessories", 'cost'=>('149.99'), 'image'=>"365-morecolors_large.png", 'description'=>"Mono's 365 DJ pack is the result of ground-zero research and prototyping conducted among some of the world's most respected international DJs. Combining intelligent features, bomb-proof construction, a low profile form factor for air travel, smart storage that puts everything in its place and a cool, minimalist design, the 365 DJ pack is an excellent choice for DJs on the go.", 'featured'=>false, 'rating'=>3) ); //Sort 1) ascending by product name $sortArray = array(); foreach($allproducts as $key=>$value){ if(!isset($sortArray[$key])){ $sortArray[$key] = array(); } $sortArray[$key][] = $value; } $orderby = "name"; //change to whatever key you want from the array array_multisort($sortArray[$orderby],SORT_ASC,$products); echo'<table>'; echo"<tr>"; echo"<th>Product</th>\n"; echo"<th>Category</th>\n"; echo"<th>Cost</th>\n"; echo"<th>Image</th>\n"; echo"<th>Description</th>\n"; echo"<th>Feature</th>\n"; echo"<th>Rating</th>\n"; echo"</tr>"; foreach($allproducts as $product) { echo '<tr>'; echo "<td>{$product['name']}</td>\n"; echo "<td>{$product['category']}</td>\n"; echo "<td>{$product['cost']}</td>\n"; echo "<td><img src='images/{$product['image']}'></td>\n"; echo "<td>{$product['description']}</td>\n"; echo "<td>{$product['featured']}</td>\n"; echo "<td>{$product['rating']}</td>\n"; echo '</tr>'; } echo'</table>'; ?> </body> </html> MOD EDIT: . . . BBCode tags added.
×
×
  • 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.