PHP - Echo Product Size If It Exists In Array
I'm a total noob trying to figure out how to get this function to work right. I want to echo for each Code: [Select]
'<OPTION value="'.$SKUCAPS.$skunum.$size.'">'.$size.'</OPTION>' for each size in the $skus[$type][$skunum]['sizes'] array. and if no size exists echo Code: [Select] '<input value="'.$SKUCAPS.$skunum.'" type=hidden" name="item">' Code: [Select] <?php $BANDNAME="Band Name"; $BANDCAPS="BANDNAME"; $BANDLOWER="bandname"; $SKUCAPS="BND"; $SKULOWER="bnd"; $skus = array( 'shirts' => array( '165' => array( 'name' => 'World Khaos Tour <br> Limited Edition Tour Track Jacket.', 'price' => '70.00', 'sizes' => array('M', 'L', '1X' ) ), '139' => array( 'name' => 'KHAOS LEGIONS ALBUM COVER', 'price' => '15.95', 'sizes' => array('S', 'M', 'L', '1X' ) ), ), //end product type 'misc' => array( '603' => array( 'name' => 'Ring Button', 'price' => '3.00', 'sizes' => array('none') ), '602' => array( 'name' => 'Logo Button', 'price' => '3.00', 'sizes' => array('none') ) ) //end product type ); //end skus function makeProduct($type){ global $skus; foreach ( $skus[$type] as $skunum => $value) { $price = $skus[$type][$skunum]['price']; $name = $skus[$type][$skunum]['name']; echo ' <!-- PRODUCT BEGIN --> <li class="product" > <a href="images/'.$SKULOWER.$skunum.'lg.jpg" rel="lightbox"><img src="product_files/'.$SKULOWER.$skunum.'.png"></a><br> <strong>'.$name.'</strong><br>'.$SKUCAPS.$skunum.'<br>$'.$price.'<br> <form name="'.$SKUCAPS.$skunum.'" method="GET" target="_blank" action="http://www.jsrdirect.com/cgi-bin/Make-a-Store.cgi"> <input type="hidden" name="band" value="'.$BANDCAPS.'"> <input type="hidden" name="back" value="http://www.jsrdirect.com/bands/'.$BANDLOWER.'/index.html"> <strong>Qty:</strong> <input type="text" name="quantity" size="1" value="1" > <strong>Size:</strong> <SELECT name="item">'.makeSizes(). '</SELECT> <br><br> <input class="css3button" value="Add To Cart" type="image"> </form> </li> <!-- Product End -->'; } } ?> any help would be greatly appreciated Similar TutorialsHi,
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! Ok, here's my code: How do i make it so that it outputs a maximum of only 5 results from the query where the img file exists. When I add LIMIT to the sql query it doesnt work so I guess its something else, but I have no clue. Can anyone help? $query = mysql_query("SELECT * FROM table WHERE date >= '$now' ORDER BY max(date) desc"); while ($row = mysql_fetch_assoc($query)) { $cid = $row['cat_id']; $title = $row['name']; $seoname = $row['seourl']; $img = 'images/'.$seoname.'.jpg'; if (!file_exists($img)) { $img = ''; } else { $img = 'images/'.$seoname.'.jpg'; } if (!empty($img)) { echo '<a href="images/'.$seoname.'/"><img src="'.$img .'" style="width:528px;" alt="" /></a>' . "\n"; } } Thanks. Hi all - I'm trying to echo $_GET something from the URL, and display a short message to the user if the echo $_GET fails - but I'm new to PHP and the code I've whipped up doesn't work. It always displays the message even if the information is present in the url and the $_GET should work. Here's the code I've got:
<h3> <?php $qset = strpos($_SERVER['SCRIPT_NAME'], 'qtitle'); if ($qset === false) { echo "You haven't added any questions yet."; } else { echo $_GET['qtitle']; } ?> </h3>The URL will contain "qtitle=(something)" if they've filled out a form on the prior page. Can someone tell me what I'm doing wrong? I have a feeling I've overcomplicated things... Thanks again! I'm trying to make one big array with my websites menu that has the categorys and the products i'm using code i found at http://www.phpfreaks.com/forums/index.php?topic=326419.msg1536842#msg1536842 its working fine till i try get the sub category and its products into the array $cats = array( 0 => array( 'categoryID' => 1, 'name' => 'Menu', 'parent' => 0) ,1 => array( 'categoryID' => 50, 'name' => 'Takeaway', 'parent' => 60) ); //root of the category $categorys = array( 1 => array( 1 => array( 'categoryID' => 6 , 'name' => 'Breads' , 'parent' => 1 ) ,0 => array( 'categoryID' => 2 , 'name' => 'Drinks' , 'parent' => 1 ) ,2 => array( 'categoryID' => 7 , 'name' => 'Salads' , 'parent' => 1 ) ) ,2 => array( 0 => array( 'categoryID' => 4 , 'name' => 'Tea' , 'parent' => 2 ) ,1 => array( 'categoryID' => 18 , 'name' => 'Coffee' , 'parent' => 2 ) ) ); // the category themselfs $product = array(6 => array( 0 => array('productID' => 1, 'categoryID' => 6,'name' => 'Plain Bread', 'description' => 'description') ,1 => array('productID' => 2, 'categoryID' => 6, 'name' => 'Garlic Bread', 'description' => 'description') ) ,7 => array( 0 => array('productID' => 44, 'categoryID' => 7, 'name' => 'Garden Salad', 'description' => 'description') ,1 => array('productID' => 45, 'categoryID' => 7, 'name' => 'Greek Salad', 'description' => 'description') ) ,4 => array( 0 => array('productID' => 74, 'categoryID' => 4, 'name' => 'Green Tea', 'description' => 'description') ) ,18 => array( 0 => array('productID' => 75, 'categoryID' => 18, 'name' => 'Espresso', 'description' => 'description') ) ); // the products if(is_array($cats)) { foreach($cats as $cat) { if(is_array($categorys[$cat['categoryID']])) { foreach($categorys[$cat['categoryID']] as $category) { if(is_array($categorys[$category['categoryID']])) { foreach ($categorys[$category['categoryID']] as $subcat){ $subcat['product'] = $product[$subcat['categoryID']]; $subprod[] = $subcat; //have tryed using parent $subprod[$subcat['parent']] but it over rides it self each time } } $category['product'] = $product[$category['categoryID']]; $category['subcategory'] = $subprod; // here is where I'm having problem $this_category[] = $category; } } if(!empty($this_category)){ $ncategory[] = array($cat,$this_category); } $this_category = array(); } } print_r($ncategory); thank you for your time sorry for any spelling or grammar errors Maybe I am over thinking this, but I would like to see if their is another value after the current value without moving the internal array pointer. What can I do? I am trying to compare an array containing required questions to an array holding survey responses. When a user submits a survey, I take the $_POST array and write the values to a new array called $surveyResponseArray. How can I determine if $surveyResponseArray exists?
Edited February 16 by SaranacLake hello, have a question. im trying to do a select * where id exists in array $id8 here is my array Code: [Select] $result8 = mysql_query("SELECT * FROM customers WHERE whosclient = 'Lansoft'"); while($row8 = mysql_fetch_array($result8)) { $id8=$row8['id']; } here is my select code. it is only returning results for the highest number in the array Code: [Select] $result = mysql_query("SELECT * FROM timesheets WHERE status = 3 AND billable = 1 AND client = '$id8' ORDER BY date, starttime"); while($row = mysql_fetch_array($result)) { Thanks for any help! Code: [Select] $result = mysql_query("SELECT field_item_id_value FROM `content_type_ads`"); while($row = mysql_fetch_array($result)){ echo $row['field_item_id_value']; echo "<br />"; echo $result; } I am trying to use an "array diff()" argument and I am getting errors with it stating the above is not an array. I have used $row and $result, and neither work. Is this not dumping into an array properly? Hey Guys, I need some assistance, hopefully there is just a simple command that I am not aware of or an easy answer to this. Suppose I have an array with x amount of values... $arr = array("111111" => 10, "222222" => 20); And i have a query.. mysql_query("SELECT * FROM table WHERE table.zip = "111111" "); Suppose I want to modify the query, so it can check if table.zip exists anywhere in $arr, regardless of length of array. And Select the value that the array location refers to. So I need it to check if "111111" is anywhere in the array, and then take the value 10. The example I am applying this to is that I have a database full of business addresses/zip codes and a database full of every zip code in country. So I have a script to get every zip within x miles, and the distance from it, but need to be able to apply it when I query my business addresses to see if it exists within x miles. Thanks! Greg I have an existing PHP array ($products) with various fields in it.... id / title / description / link / image link etc. etc. as per requirements for a Google Products feed (https://support.google.com/merchants/answer/7052112). My issue is that, for clothing, Google want a separate record for each size available. My array includes the "size" field as a comma separated list e.g. 6,8,10,12,14 or XS,S,M,L,XL etc. etc. So before creating the feed (a text file, which is currently outputting fine except for the size field issue) I need to duplicate each id where there's more than 1 size in that field, for each size, and then manipulate the fields a little so that (ignoring all the duplicated fields that would remain unchanged) instead of the single record : -
id size item group id I'd have 11 records, item group id would be what the id is, the size appended to the id, and the size field only one (in sequence of those from the original), so: - id size item group id
52-6 6 52 That's just one product....there are quite a lot, each with multiple sizes, but all in the same format within the $products array. As always, any help / pointers / solutions much appreciated! Hi All, There is a very interesting solved topic here (http://www.phpfreaks.com/forums/index.php?topic=304966.0) about how to access elements in embedded _POST array. But before accessing an element, it might be appropriate to check whether the array it is supposed to be in exists. According to the solution given in the topic indicated above, Code: [Select] $_POST['matType'] is an example of embedded array . Is there a way to check if this array exists? Thanks in advance for your help. Hi, I am a newbie in PHP (about week and a half). I'm writing a website for myself right now. I've got a problem that I cannot solve. The website is about buying files with website custom balance. What I want to do is disable buy button if user bought this file b4. The is a table user_files that stores user id and file id. And another table that stores files data, ID name who uploaded date time ect.... What I'm trying to do, is disabling buy button if the user has already the file. This is what I've done : while ($row = $rocket->fetch()) { ?> <tr> <td><?php echo $row['id']; ?></td> <td><?php echo $row['name']; ?></td> <td><?php echo $row['uploader']; ?></td> <td><?php echo $row['uploadtime']; ?></td> <td><button <?php // Echo "disabled" if $row['id'] id is present in row2['file_id'] <<<<<<< Need to do this in a while. ?> ><a href="download.php?id=<?php echo $row['id']; ?>"></a><?php echo $row['price'] . "D$" ?></button></td> </tr> <?php } ?> What I can't do is check if the file id ($row['id']) is present in ($row2['file_id']), if yes echo "disabled";
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! I did a phpfreaks search for this, but didn't find anything specific. How can I echo out an array name? I have a function to return the array contents (for debugging purposes), and I need it to generate the actual name of the array as well. Thanks! How do I check to see if a value is in an array and then echo it? If index.php is found in the pages column. Check to see if it's value is in the $pages array. If the value matches, echo the value. Code: [Select] function fetch_feedback_top_performers() { $sql = "SELECT `page`, SUM(`like`) FROM `feedback` GROUP BY `page` ORDER BY SUM(`like`) DESC LIMIT 10"; $rs = mysql_query($sql); while($row = mysql_fetch_assoc($rs)) { $results[] = $row; } return $results; } $pages = array( 'about' => 'About', 'index' => 'Homepage', ); Echo it here... Code: [Select] <?php $results = fetch_feedback_top_performers(); foreach ($results as $result) { $page = $result['page']; $total = $result['SUM(`like`)']; $extremoved = substr($page, 0, -4); ?> <div class="mhl mvs"><span class="left"><?php echo ucwords($extremoved); ?></span><span class="f_right">(<?php echo $total; ?>)</span></div> <?php } ?> I just have no idea how to perform the check. I want to do this for security. How can I echo the array value? Here is the pre... Array ( => Array ( [count] => 2 ) ) Here is my currrent code... Code: [Select] <span class="blue"><?php echo $count; ?></span> Can I do this without using a foreach loop? Hello everyone. I'm a self learner that is very new to programming. I'm trying to print out the value of ["mid"] from a json_decode variable in the code shown below: I'm trying to use for each to access the value of "mid'. using foreach function. I know I'm not doing it the right way. please help me or show me an easy was to go around it. /////the json resopnd form the url is : {"terms":"http://www.xe.com/legal/dfs.php","privacy":"http://www.xe.com/privacy.php","from":"USD","amount":1.195,"timestamp":"2021-02-09T16:52:00Z","to":[{"quotecurrency":"NGN","mid":454.6559871014}]} ///////////////////////////////////////////////// <?php $auth = base64_encode("username:password"); $context = stream_context_create([ "http" => [ "header" => "Authorization: Basic $auth" ] ]); $homepage = file_get_contents("https://xecdapi.xe.com/v1/convert_from?to=NGN&amount=1.195", false, $context ); $json = json_decode($homepage, TRUE); foreach ($json as $price){ echo $price['mid']; }; ?>
Hello I Have a few problems understanding what to do with this Arrays So if i have a string that echo's : Array ( [TEST1] => Tested 1 [TEST2] => Tested 2 [TEST3] => Tested 3 ) How may i echo the middle line from the array ?? Hello,
I am working on this function that echo's out images from my database restricted to 10 images with 4 default images if the database is empty.
<?php $query = mysql_query('SELECT image_id, image_expiry FROM images ORDER BY RAND() LIMIT 10'); $i = 0; class myCounter3 implements Countable { public function count() { static $count = 0; return ++$count; } } $counter = new myCounter3; while ($row = mysql_fetch_array($query)) { if($i % 10 === 0) { } echo '<img src="http://www.mysite.com/'.$row['image_id'].'.jpg" width="300" height="auto"/>'; $i++; } for (; $i <= 4; $i++) { echo '<img src="http://www.mysite.com/default.jpg" width="300" height="auto"/>' } ?>I need to include an image expiry function with the function above, but I am not sure how to properly include it. Here is my planned expiry function (each image as an expiry date). $today = date("Y-m-d", time()); $expiry = $row['image_expiry'] if( $today > $expiry) { ## ignore expired image } else { ## display image }Bottom line I need to exclude expired images from being echoed out in the first function. Thanks in advance. Everything I have tried hasn't worked. Hello all, I've run in to a very strange problem that I've never seen before. in my "config.php" file I have something like this... <?php // the URL of the script. NO trailing slash. $xconfig['url'] = $r['cfg_site_url']; // the site name $xconfig['title'] = $r['cfg_site_title']; // the YouTube user name to populate the site with. $xconfig['youtube_user'] = $r['cfg_site_youtube']; // the video to show on the homepage $xconfig['homepage_video'] = $r['cfg_homepage_video']; ?> and in my index.php page, I have <?php include "config.php"; ?> but, also in index.php, I have this <?php echo $xconfig['title'] ; ?> but it won't echo! None of the values in $xconfig[] output anything. I've even done put this in index.php <?php var_dump($xconfig); exit; ?> and that shows the array with the contents I expected. So, why does the array have the correct contents, but will not echo? Thanks a ton! |