Jump to content

Search the Community

Showing results for tags 'array'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

  1. Hello - I hope I explain this clearly... I have some php code that presently displays 4 boxes in a row with images. When you click on a box/image, you go to a web post. The code goes to the bottom, sets the link, then loops back for the next image and repeats the process. What I'm trying to do is break this code apart so that that I can make each image go to a different link - basically set it up as html - image with link to a page. ( 4 of these) However, I don't want to break the code or the page that it displays ( our home page ) Here's the code snippet: <div id="new-classes" class="carousel slide"> <!-- Wrapper for slides ufff--> <div class="carousel-inner"> <?php $pieces=array_chunk($gallery,4); $j=0; foreach ($pieces as $slice) { echo '<div class="item '; if($j==0){echo 'active';} echo '">'; foreach ($slice as $i => $conte) { ?> <div class="col-sm-6 col-md-3" > <div class="new-class" > <img src="<?php echo $slice[$i]['image']; ?>" alt="//" /> <div class="class-title" > <div class="occult" > TEST this is where the specialities boxes link is <a <?php echo colors('a');?> href="<?php echo $slice[$i]['link']; ?>" class="link" ></a> I duplicated the above line and put in a specific link but it makes all the images go to the same page <a <?php echo colors('a');?> href="https://www.absolutept.com/tendinopathy/" class="link" ></a> --> </div> <h3 <?php echo colors('h3');?>><?php echo $slice[$i]['title']; ?></h3> <p <?php echo colors('p');?> class="occult" ><?php echo wp_trim_words(insert_br($slice[$i]['desc']),10,'...'); ?></p> </div> </div> </div> <?php } //end slice echo '</div>'; $j++; } // end pieces ?> </div> our homepage is absolutept.com -- these images are the "specialties" section 3/4 of the way down In the theme( wordpress) - there's an option to enter specialties ( custom post type ) which we did but we don't want these links to go to those special posts, we want them to go to the pages that the user can find in the main menu I know this is breaking the set up of the theme but if it's doable, we'd like to try First - any idea if it's doable and if so, thoughts on how? =) Thanks in advance.
  2. I have created a JSON file from the database, which has two table semone with attributes id, semester, cname and table courses with attributes coname and credit. Code I am writing in php is following. main.php <?php $user = "root"; $password = ""; $database = "scheduler"; $con = mysqli_connect("localhost", $user, $password, $database) or die ("Unable to connect"); $query = "SELECT semone.userid AS sbuid, semone.semester AS semester, semone.cname AS name, courses.credit AS value, courses.progskill AS skill FROM semone INNER JOIN courses ON semone.cname = courses.coname" ; $result = mysqli_query($con,$query)or die ("Unable to connect"); $info = array(); $test = array(); while ($row = $result->fetch_array(MYSQLI_ASSOC)) { $row['xyz'] = array( 'name'=> $row['name'], 'value'=> $row['value'] ); $info[$row['semester']]['children'][]= $row['xyz']; $data = json_encode(array('id' => $row['sbuid'], 'children' => $info)); } echo $data; ?> I want to get JSON file as seen in the following code, but I am getting something like this. **output.json** {"id":"12345", "children": {"first": {"children": [{"name":"CSE101","value":"100"}, {"name":"CSE102","value":"100"}]}, "second": {"children": [{"name":"CSE103","value":"50"}, {"name":"CSE104","value":"100"}, {"name":"CSE105","value":"100"}]}, "third": {"children": [{"name":"CSE106","value":"50"}]} }} But this is what I am expecting. **expected.json** { "id": 12345, "children": [{ "semester": "first", "children": [{ "name": "C101","value": 100}, { "name": "C102","value": 100}] }, { "semester": "second", "children": [{ "name": "C103", "value": 50}, {"name": "C104","value": 100}, {"name": "C105","value": 100}] }, { "semester": "third", "children": [{"name": "C106","value": 50}] } }
  3. Hi I just cant in over a week figure out how I would go about setting up this work time sheet, that displays my employees work times and find any conflicting work hours. But man I have been stumped on getting this code to work! Could anyone fix, or even better teach me a much better way to acomplish this? function time_sheet_day($DB){ $manager_id = $_SESSION['man_id']; $today = date('l'); $year = date('Y'); $ddate = @date(); $date = new DateTime($ddate); $week = $date->format("W"); $page = "<table><tbody><tr><th>ID</th><th>Crew</th><th>Position</th><th>Start Time</th><th>End Time</th></tr>"; $time_sheet_db = $DB->query("SELECT {$today},member_id FROM calendar WHERE manager_id = {$manager_id} AND Week = {$week} AND Year = {$year}"); $time_sheet = []; while($time = $time_sheet_db->fetcharray(SQLITE3_ASSOC)){ $hours = explode('-', $time[$today]); $time_sheet[] = array($time['member_id'], $hours[0], $hours[1]); } $member_info = []; $time_check = $time_sheet; $conflicts = []; $rater = 0; foreach($time_check as $checker){ if($checker[0] == $time_check[$rater][0]){ $rater = $rater + 1; continue; } if($checker[1] == $time_check[$rater][1]){ $conflicts[] = array($checker[0], $time_check[$rater][0], $checker[1]); } $rater = $rater + 1; } foreach($time_sheet as $member){ $member_info_db = $DB->query("SELECT username,crew,postion FROM Members WHERE ID = {$member[0]}"); $member_info = $member_info_db->fetcharray(SQLITE3_ASSOC); $found_conflict=array_find($conflicts, $member[0]); print_r($found_conflict); if($found_conflict == False){ $page .= "<tr><td>{$member_info['username']}</td><td>{$member_info['crew']}</td><td>{$member_info['postion']}</td><td>{$member[1]}</td><td>{$member[2]}</td></tr>"; } else { $page .= "<tr style='background-color:#FF0000'><td>{$member_info['username']}</td><td>{$member_info['crew']}</td><td>{$member_info['postion']}</td><td>{$member[1]}</td><td>{$member[2]}</td></tr>"; } } $page .= '</tbody></table>'; echo ($page); } function array_find($parents, $searched) { if (empty($searched) || empty($parents)) { return false; } foreach ($parents as $key => $value) { $exists = true; foreach ($searched as $skey => $svalue) { $exists = ($exists && IsSet($parents[$key][$skey]) && $parents[$key][$skey] == $svalue); } if($exists){ return $key; } } return false; }
  4. I keep getting these errors, running php 5.4; Notice: Undefined variable: value in C:\xampp\htdocs\BK\functions.php on line 133 Warning: Creating default object from empty value in C:\xampp\htdocs\BK\functions.php on line 133 Fatal error: Cannot access empty property in C:\xampp\htdocs\BK\functions.php on line 133 and heres my code; 128 function array_find($parents, $searched) { 129 if (empty($searched) || empty($parents)) { 130 return false; 131 } 132 133 foreach ($parents as $key -> $value) { 134 $exists = true; 135 foreach ($searched as $skey -> $svalue) { 136 $exists = ($exists && IsSet($parents[$key][$skey]) && $parents[$key][$skey] == $svalue); 137 } 138 if($exists){ return $key; } 139 } 140 141 return false; 142 }
  5. I'm having an issue sorting an array. I'm getting an error of "Warning: ksort() expects parameter 1 to be array, null given in" The print_r output of the array is Array ( [0] => Array ( [text] => 96.1 km [value] => 96113 ) [1] => Array ( [text] => 52.1 km [value] => 52096 ) [2] => Array ( [text] => 102 km [value] => 102064 ) [3] => Array ( [text] => 30.0 km [value] => 29992 ) [4] => Array ( [text] => 43.9 km [value] => 43864 ) [5] => Array ( [text] => 57.4 km [value] => 57408 ) [6] => Array ( [text] => 82.2 km [value] => 82154 ) [7] => Array ( [text] => 73.6 km [value] => 73620 ) [8] => Array ( [text] => 118 km [value] => 118016 ) [9] => Array ( [text] => 137 km [value] => 136921 ) [10] => Array ( [text] => 61.6 km [value] => 61574 ) [11] => Array ( [text] => 74.2 km [value] => 74193 ) [12] => Array ( [text] => 226 km [value] => 226166 ) [13] => Array ( [text] => 140 km [value] => 140145 ) [14] => Array ( [text] => 126 km [value] => 126140 ) [15] => Array ( [text] => 45.5 km [value] => 45520 ) [16] => Array ( [text] => 211 km [value] => 211070 ) [17] => Array ( [text] => 54.1 km [value] => 54145 ) [18] => Array ( [text] => 187 km [value] => 186855 ) [19] => Array ( [text] => 271 km [value] => 271334 ) [20] => Array ( [text] => 219 km [value] => 218848 ) [21] => Array ( [text] => 67.0 km [value] => 67016 ) [22] => Array ( [text] => 13.6 km [value] => 13591 ) [23] => Array ( [text] => 153 km [value] => 153396 ) [24] => Array ( [text] => 11.5 km [value] => 11492 ) ). All I want to do is be able to sort the array by the lowest number in either text or value and display that single number. <?php include 'config/db_functions.php'; //run the query $loop = mysql_query("SELECT * FROM NEW_Venues WHERE game_nights = '5' AND status = '1'") or die (mysql_error()); while ($row = mysql_fetch_array($loop)) { $postcode2 = $row['zip']; $venue = $row['venue']; $postcode1=('33071');; $url = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=$postcode2&destinations=$postcode1&mode=driving&language=en-EN&sensor=false"; $data = @file_get_contents($url); $result = json_decode($data, true); ksort($items); foreach($result['rows'] as $distance) {; echo '' . $venue . ' - ' . $distance['elements'][0]['distance']['text'] . ' <br>'; $items[] = $distance['elements'][0]['distance']; $items1[] = $distance['elements'][0]['distance']; $itemsname[] = $venue; } } ksort($items1); foreach ($items1 as $key => $val) { echo "$key = $val <br>"; } print_r(array_values($items)); ?>
  6. Hi, I have a json data, below which contains an item with tax: "date": "2015-05-05 12:41", "shop": "Toto", "products": [ { "price": "2.00", "quantity": "1", "description": "chocolat", "tax": [ { "price": "1.00", "quantity": "1", "description": "tax1" }, { "price": "2.00", "quantity": "1", "description": "tax2" } ] } ] } I am able to calculate the price ($amountAll) with the following code: $datajs = "myJsonSimple2.json"; $datajs = file_get_contents($datajs); $decodageDatajs = json_decode($datajs); $dateBiling = $decodageDatajs->date; $shopName = $decodageDatajs->shop; foreach ($decodageDatajs->products as $obj) { $ItemPrice = $obj->price; $ItemQuantity = $obj->quantity; $ItemDescription = $obj->description; $taxes = (array)$obj->tax; $taxesPrice1 = !empty($taxes[0]) ? $taxes[0]->price : 0.00; $taxesPrice2 = !empty($taxes[1]) ? $taxes[1]->price : 0.00; $taxesQuantity1 = !empty($taxes[0]) ? $taxes[0]->quantity : 0; $taxesQuantity2 = !empty($taxes[1]) ? $taxes[1]->quantity : 0; $taxesDescription1 = !empty($taxes[0]) ? $taxes[0]->description : '1er tax null'; $taxesDescription2 = !empty($taxes[1]) ? $taxes[1]->description : '2e tax null'; $amountAll = $ItemPrice * $ItemQuantity + $taxesPrice1 + $taxesPrice2; } But how I calculate if there are several items (2 or 3 or 5...) { "date": "2015-05-05 12:41", "shop": "Toto", "products": [ { "price": "2.00", "quantity": "1", "description": "chocolat", "tax": [ { "price": "1.00", "quantity": "1", "description": "tax1" }, { "price": "2.00", "quantity": "1", "description": "tax2" } ] }, { "price": "3.00", "quantity": "1", "description": "bonbon", "tax": [ { "price": "2.00", "quantity": "1", "description": "tax1" }, { "price": "3.00", "quantity": "1", "description": "tax2" } ] }, { "price": "2.00", "quantity": "1", "description": "gateaux", "tax": [ { "price": "1.00", "quantity": "1", "description": "tax1" }, { "price": "2.00", "quantity": "1", "description": "tax2" } ] } ] } I need like as : $amountAll = $ItemPrice1 * $ItemQuantity1 + $ItemPrice2 * $ItemQuantity2 + $ItemPrice3 * $ItemQuantity3 + $taxesPrice1a + $taxesPrice2a + $taxesPrice1b + $taxesPrice2b + $taxesPrice1c + $taxesPrice2c; but this is wrong : I must counter and use while statement but I don,t know how I can write ? $calculeItems = count($decodageDatajs->products); $i = 0; while ($i < $calculeItems) { foreach ($decodageDatajs->products as $obj) { $ItemPrice = $obj->price; $ItemQuantity = $obj->quantity; $ItemDescription = $obj->description; $taxes = (array)$obj->tax; $taxesPrice1 = !empty($taxes[0]) ? $taxes[0]->price : 0.00; $taxesPrice2 = !empty($taxes[1]) ? $taxes[1]->price : 0.00; $taxesQuantity1 = !empty($taxes[0]) ? $taxes[0]->quantity : 0; $taxesQuantity2 = !empty($taxes[1]) ? $taxes[1]->quantity : 0; $taxesDescription1 = !empty($taxes[0]) ? $taxes[0]->description : '1er tax null'; $taxesDescription2 = !empty($taxes[1]) ? $taxes[1]->description : '2e tax null'; $amountAll = $ItemPrice * $ItemQuantity + $taxesPrice1 + $taxesPrice2; /* this si wrong !!!!! $amountAll = $ItemPrice1 * $ItemQuantity1 + $ItemPrice2 * $ItemQuantity2 + $ItemPrice3 * $ItemQuantity3 + $taxesPrice1a + $taxesPrice2a + $taxesPrice1b + $taxesPrice2b + $taxesPrice1c + $taxesPrice2c; */ } $i++; } can you help me please Thanks
  7. Hi, I've got this JSON output: {"result":"success","clientid":null,"serviceid":null,"pid":null,"domain":"testdomain.com","totalresults":"1","startnumber":0,"numreturned":1,"products":{"product":[{"id":"3804","clientid":"1401","orderid":"3276","pid":"53","regdate":"2010-02-14","name":"Basic","groupname":"Plans","domain":"testdomain.com","dedicatedip":"","serverid":"4","servername":"serverx.com","serverip":"123.123.123.123","serverhostname":"","firstpaymentamount":"7.99","recurringamount":"7.99","paymentmethod":"wibble","paymentmethodname":"Credit\/Debit Card","billingcycle":"Monthly","nextduedate":"2010-02-14","status":"Terminated","username":"dcdqw","password":"z1nmY1p4Y9","subscriptionid":"","promoid":"0","overideautosuspend":"","overidesuspenduntil":"0000-00-00","ns1":"","ns2":"","assignedips":"","notes":"","diskusage":"0","disklimit":"1000","bwusage":"0","bwlimit":"50000","lastupdate":"2015-05-01 06:01:17","customfields":{"customfield":[{"id":"36","name":"ThisUserID","value":"1243214"}]},"configoptions":{"configoption":[]}}]}} ... and I'm trying to get the value for ThisUserID but I'm struggling so much with the arrays! I've copied it into http://jsonviewer.stack.hu so I can understand it more but just can't get that value. I understand: $clientid = $arr->clientid; ... but can't work out how to drill deeper. Any help appreciated
  8. Hi I have a json data : { "email": "john@john.fr", "line_items": [ { "sku": "123456789", "price": "0.67", "price_with_tax": "4.00", "tax_lines": [ { "title": "tax010", "rate": 0.01, "price": "1.11" }, { "title": "tax00200", "rate": 0.02, "price": "2.22" } ] }, { "sku": "012345666", "price": "1.67", "price_with_tax": "5.00", "tax_lines": [ { "title": "tax0003000", "rate": 0.03, "price": "3.33" } ] } ] } and I try put this data in mySql. First data have a good value but second have a wrong data on 'price_tax1' and 'price_tax2' in mySql : Here is my MySql 1st item :::: good value email:john@john.fr sku:123456789 price:0.67 price_with_tax:4.00 price_tax1:1.11 price_tax2:2.22 2nd item :::: email:john@john.fr sku:012345666 price:1.67 price_with_tax:5.00 wrong value :::: price_tax1:1.11 price_tax2:2.22 here is my code : $jsondata = file_get_contents($jsondata); $dataDecode = json_decode($jsondata); $email = $dataDecode->email; try { $dtbs = new PDO($dsn_dev, $pdo_user, $pdo_password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); } catch (Exception $e) { die('Error : ' . $e->getMessage()); } try { foreach ($dataDecode->line_items as $obj) { $var_sku = $obj->sku; $var_price = $obj->price; $var_price_with_tax = $obj->price_with_tax; $taxNewArray = array(); foreach ($dataDecode->line_items[0]->tax_lines as $obj2) { array_push($taxNewArray , $obj2); } $val1st = array_shift($taxNewArray); $val2nd = array_pop ($taxNewArray); $var_tax1 = $val1st->price; $var_tax2 = $val2nd->price; $stmt = $dtbs->prepare("INSERT INTO $tabledata ($mysql_email, $mysql_sku, $mysq_price, $mysql_price_with_tax, $mysql_price__tax1___line_items, $mysql_price__tax2___line_items ) VALUES (:email, :sku, :price, :price_with_tax, :price_tax1, :price_tax2)"); $stmt->execute(array(':email'=>$email, ':sku'=>$var_sku, ':price'=>$var_price, ':price_with_tax'=>$var_price_with_tax, ':price_tax1'=>$var_tax1, ':price_tax2'=>$var_tax2 )); } } catch(Exception $e) { throw $e; } How can I put goog value of 2nd data in mySql ? thanks
  9. I have created a word game in php/mysql where users are presented with a randomly selected word in a foreign language and then have to fill in missing letters (which depending on the word length are sometimes randomly removed or sometimes all letters are removed) from the english version of these words into form input fields which are later submitted to the database via a form for checking... The code below works ok except for when a word has more than one instance of a particular letter for examples the word "Bees" For example it will go through find "e" but then replace both instances of the letter "e" with either <input type="text" name="question_1_letter_1" class="inputs" maxlength="1" value="" /> or <input type="text" name="question_1_letter_2" class="inputs" maxlength="1" value="" /> What I really want to happen is for it to just replace once the first "e" it finds so one instance of the letter "e" is replaced by <input type="text" name="question_1_letter_1" class="inputs" maxlength="1" value="" /> and the other instance is replaced with <input type="text" name="question_1_letter_2" class="inputs" maxlength="1" value="" /> here is the main code $one = "question_1_letter_$key1"; $two = "question_1_letter_$key2"; $three = "question_1_letter_$key3"; $four = "question_1_letter_$key4"; $string = Bees; $selected_letter1 = B; $selected_letter2 = e; $selected_letter3 = e; $selected_letter4 = s; $Find = Array($selected_letter1, $selected_letter2, $selected_letter3, $selected_letter4); $Replace = Array( "`<input type=\"text\" name=\"$one\" class=\"inputs\" maxlength=\"1\" value=\"\" />`", "`<input type=\"text\" name=\"$two\" class=\"inputs\" maxlength=\"1\" value=\"\" />`", "`<input type=\"text\" name=\"$three\" class=\"inputs\" maxlength=\"1\" value=\"\" />`", "`<input type=\"text\" name=\"$four\" class=\"inputs\" maxlength=\"1\" value=\"\" />`" ); $New_string = strtr($string, array_combine($Find, $Replace)); echo $New_string; Hope that makes sense! Im still very much a novice php programmer and stuck as to how I can achieve this and may well be overlooking a much simpler solution that I am currently unaware of... if anyone can lend a hand and give me some pointers it would be greatly appreciated!!
  10. I's trying to transform data from mysql into something like $books below but it doenst seem to be working $books = array( "phil" => array("my girl" => 2.5, "the god delusion" => 3.5, "tweak" => 3, "the shack" => 4, "the birds in my life" => 2.5, "new moon" => 3.5) ) this is how I tried doing: $sql = "SELECT * from rating where user_id=11 limit 5"; $db_result = mysql_db_query($dbname,$sql) or trigger_error(mysql_error()); $num_rows = mysql_num_rows($db_result) or trigger_error(mysql_error()); while ($row = mysql_fetch_array($db_result)) { $one = $row['bookId']; $two = $row['user_id']; $three = $row['rating']; $ArraY= array( $two => array($one=>$three) ); print_r($ArraY); } but this is what i get : Array ( [11] => Array ( [123715] => 5 ) ) Array ( [11] => Array ( [140329] => 5 ) ) Array ( [11] => Array ( [3083854] => 4 ) ) Array ( [11] => Array ( [871236761] => 1 ) ) Array ( [11] => Array ( [451179757] => 1 ) ) Array ( [11] => Array ( [451403886] => 3 ) ) Array ( [24] => Array ( [044661095X] => 4 ) ) Array ( [24] => Array ( [014010268X] => 1 ) ) Array ( [24] => Array ( [812576063] => 5 ) ) Array ( [24] => Array ( [038076654X] => 1 ) ) instead of something like: Array ( [phil] => Array ( [my girl] => 2.5 [the god delusion] => 3.5 [tweak] => 3 [the shack] => 4 [the birds in my life] => 2.5 [new moon] => 3.5 ) [sameer] => Array ( [the last lecture] => 2.5 [the god delusion] => 3.5 [the noble wilds] => 3 [the shack] => 3.5 [the birds in my life] => 2.5 [new moon] => 1 ) [john] => Array ( [a thousand splendid suns] => 5 [the secret] => 3.5 [tweak] => 1 ) [peter] => Array ( [chaos] => 5 => 3.5 ) [jill] => Array ( [the last lecture] => 1.5 [the secret] => 2.5 [the noble wilds] => 4 [the host: a novel] => 3.5 [the world without end] => 2.5 [new moon] => 3.5 ) [bruce] => Array ( [the last lecture] => 3 [the hollow] => 1.5 [the noble wilds] => 3 [the shack] => 3.5 [the appeal] => 2 [new moon] => 3 ) [tom] => Array ( [chaos] => 2.5 ) ) Any help with how i can transform that will be much appreciated THANKS
  11. Hi there guys, I've made some new checkbox fields in my wordpress template using Meta box. Now i want to display those selected checkboxes in the forntend, but it will display only the first checkbox that i've checked, not the other ones. The problem seems to by the array functions that displays only the first checkbox. I'll put bellow the codes that i've been using: This is the code from the meta-box-config.php // General ////////////////////////////////////////////////////////////////////////////////////// array( 'name' => 'Genearal', 'id' => "{$prefix}utilitati_general", 'clone' => false, 'type' => 'checkbox_list', 'options' => array( 'Curent Electric' => __('Curent electric','locality'), 'Telefon' => __('Telefon','locality'), 'Apa' => __('Apa','locality'), 'Gaz' => __('Gaz','locality'), 'Cablu TV' => __('Cablu TV','locality'), 'Canalizare' => __('Canalizare','locality') ), 'std' => false ), This is the code from the frontpage // General ////////////////////////////////////////////////////////////////////////////////////// $locality_utilitati_general = get_post_meta($post->ID, 'locality_utilitati_general', true); if(!empty($locality_utilitati_general)) { ?> <?php _e('General: ','locality'); ?><?php echo implode(',', $_POST['locality_utilitati_general']); ?> <?php }
  12. using php, how to delete values from an array and place those values in another array. Is it possible to take an array like this... Array ( [0] => Array ( [0] => var1 [1] => 1 [2] => var2 [3] => 2 [4] => 3 ) ) and make two arrays like this... Array ( [0] => Array ( [0] => 1 [1] => 2 [2] => 3 ) ) Array ( [0] => Array ( [0] => var1 [1] => var2 ) ) The word "var" inside of the array does not change value but numbers can change values.
  13. <? //random numbers $arr = array(); while ( count($arr) < 6 ) { $x = mt_rand(1,24); if ( !in_array($x,$arr) ) { $arr[] = $x; asort($arr); } } foreach($arr as $x){ $numbers[]=$x." "; } for($i2=0;$i2<6;$i2++){ //start cycle if($i2=="0"){ $no01=$numbers[$i2]; } if($i2=="1"){ $no02=$numbers[$i2]; } if($i2=="2"){ $no03=$numbers[$i2]; } if($i2=="3"){ $no04=$numbers[$i2]; } if($i2=="4"){ $no05=$numbers[$i2]; } if($i2=="5"){ $no06=$numbers[$i2]; } //end cycle } //connect to database $sql91="SELECT * FROM l$table WHERE draw='$draw'"; $result91=mysql_query($sql91); while($rows91=mysql_fetch_array($result91)){ $user=$rows91['user']; $show1=$rows91['no01']; $show2=$rows91['no02']; $show3=$rows91['no03']; $show4=$rows91['no04']; $show5=$rows91['no05']; $show6=$rows91['no06']; //CHECK 01 if($rows91['no01']==$no01) { $MEMBER01=1; } elseif($rows91['no02']==$no01) { $MEMBER01=1; } elseif($rows91['no03']==$no01) { $MEMBER01=1; } elseif($rows91['no04']==$no01) { $MEMBER01=1; } elseif($rows91['no05']==$no01) { $MEMBER01=1; } elseif($rows91['no06']==$no01) { $MEMBER01=1; } else { $MEMBER01=0; } //CHECK 02 if($rows91['no01'] == $no02) { $MEMBER02=1; } elseif($rows91['no02'] == $no02) { $MEMBER02=1; } elseif($rows91['no03'] == $no02) { $MEMBER02=1; } elseif($rows91['no04'] == $no02) { $MEMBER02=1; } elseif($rows91['no05'] == $no02) { $MEMBER02=1; } elseif($rows91['no06'] == $no02) { $MEMBER02=1; } else { $MEMBER02=0; } //CHECK 03 if($rows91['no01'] == $no03) { $MEMBER03=1; } elseif($rows91['no02'] == $no03) { $MEMBER03=1; } elseif($rows91['no03'] == $no03) { $MEMBER03=1; } elseif($rows91['no04'] == $no03) { $MEMBER03=1; } elseif($rows91['no05'] == $no03) { $MEMBER03=1; } elseif($rows91['no06'] == $no03) { $MEMBER03=1; } else { $MEMBER03=0; } //CHECK 04 if($rows91['no01'] == $no04) { $MEMBER04=1; } elseif($rows91['no02'] == $no04) { $MEMBER04=1; } elseif($rows91['no03'] == $no04) { $MEMBER04=1; } elseif($rows91['no04'] == $no04) { $MEMBER04=1; } elseif($rows91['no05'] == $no04) { $MEMBER04=1; } elseif($rows91['no06'] == $no04) { $MEMBER04=1; } else{ $MEMBER04=0; } //CHECK 05 if ($rows91['no01'] == $no05) { $MEMBER05=1; } elseif($rows91['no02'] == $no05) { $MEMBER05=1; } elseif($rows91['no03'] == $no05) { $MEMBER05=1; } elseif($rows91['no04'] == $no05) { $MEMBER05=1; } elseif($rows91['no05'] == $no05) { $MEMBER05=1; } elseif($rows91['no06'] == $no06) { $MEMBER05=1; } else{ $MEMBER05=0; } //CHECK 06 if ($rows91['no01'] == $no06) { $MEMBER06=1; } elseif($rows91['no02'] == $no06) { $MEMBER06=1; } elseif($rows91['no03'] == $no06) { $MEMBER06=1; } elseif($rows91['no04'] == $no06) { $MEMBER06=1; } elseif($rows91['no05'] == $no06) { $MEMBER06=1; } elseif($rows91['no06'] == $no06) { $MEMBER06=1; } else{ $MEMBER06=0; } $TOTALMEMBER=$MEMBER01+$MEMBER02+$MEMBER03+$MEMBER04+$MEMBER05+$MEMBER06; ?> Basically what I am trying to do is check all 6 numbers that are randomly generated to the already stored user numbers in a mysql database. Its DRIVING me insane as I cannot work out why it wont work or the if statements wont equal each other. The database field is set to INT for the numbers. Cheers
  14. In the file attached, there is a while loop in which am trying to display the records from a table and on each iteration a text field is also printed, which I have declared as an array 'marks[]'. Am stuck with the way how values are retrieved from those php printed text fields i.e., echo "<input type='text' name='marks[]'>"; Please help. Thanks in advance Facultymarks.php
  15. I am trying to format a normal date into a timestamp. To convert a timestamp into the normal date was no problem, but now I have an array with 4 different dates! 2 normal dates : 1991-12-09, 12.03.1984 and also 2 timestamps in one array. If I had the same format I could strpos it and make an if and test with "." that worked last time, but now I have those 4 different formats. Anyone an idea?
  16. Hi. I have a list of products and each have parts which in turn have their own codes. I need to find the correct part when I have the code. So in the example below, I already have the code '8R195'. I want to check through all the arrays and find which one contains this code, so the output would be A in this case. Any help greatly appreciated $item1 => Array ( ('A') => array('825R15', '825R16', '65R17', '21575R175', '8R195'), ('B') => array('10R225', '825x20', '900R20'), ('C') => array('15R225', '29575R225', '30570R225', '38565R225') )
  17. I have a multidimensional array, lets say it's consisting of arrays for groups of balls and then with the key as the number of the ball and then subkeys for color and size, something like what can be seen below (slightly simplified). If I want to select as many balls as possible, based on their size, but there has to be 1) at least one ball from each group and 2) the number of balls from each group multiplied with each other can't be more than lets say 20, and also 3) one of the groups has to have only one single ball selected (to maximize the number of balls selected in total). I know the basics about arrays and foreach loops and so on but how would I go about checking for these above mentioned limitations? Array( [Group1] => Array ( [1] => Array ( [color] => 'blue' [size] => 1.25 ) [2] => Array ( [color] => 'red' [size] => 1.59 ) [3] => Array ( [color] => 'red' [size] => 1.20 ) [4] => Array ( [color] => 'green' [size] => 1.91 ) [5] => Array ( [color] => 'blue' [size] => 1.73 ) ) [Group2] => Array ( [1] => Array ( [color] => 'red' [size] => 1.84 ) [2] => Array ( [color] => 'red' [size] => 1.21 ) [3] => Array ( [color] => 'green' [size] => 1.17 ) [4] => Array ( [color] => 'green' [size] => 1.46 ) [5] => Array ( [color] => 'blue' [size] => 1.70 ) ) [Group3] => Array ( [1] => Array ( [color] => 'red' [size] => 1.04 ) [2] => Array ( [color] => 'yellow' [size] => 1.99 ) [3] => Array ( [color] => 'orange' [size] => 1.07 ) [4] => Array ( [color] => 'blue' [size] => 1.12 ) [5] => Array ( [color] => 'blue' [size] => 1.18 ) ) [Group4] => Array ( [1] => Array ( [color] => 'blue' [size] => 1.66 ) [2] => Array ( [color] => 'blue' [size] => 1.24 ) [3] => Array ( [color] => 'blue' [size] => 1.45 ) [4] => Array ( [color] => 'blue' [size] => 1.42 ) [5] => Array ( [color] => 'red' [size] => 1.38 ) ))
  18. I'm developing a series of database-driven quizzes and tests. Most of the answers will be multiple choice, but there will also be some fill-in-the-blank questions. What's causing me trouble is questions that ask users to choose several answers by selecting several checkboxes. There could be one or more such questions in each quiz, and the number of correct and wrong choices will vary. The answer key below is tailored for a quiz with just one checkbox question, with six choices - three correct and three incorrect. The script awards partial scores for each correct choice and also deducts points for each wrong answer. I'd like to change it so that there are no gray areas - a question is either right or wrong. In this particular example, a user has to choose all three correct answers and no correct answers. Any variation whatsoever results in a wrong answer (0% for that answer). I would guess it should be as simple as coding it to say "a checkbox answer must be exactly identical to the array within in an array in the answer key." Unfortunately, I don't have a clue how to write that. Thanks for any tips. if (isset($_POST)): $totalCorrect = 0; $answers = array(1 => 'A', 2 => 'banana', 3 => 'C', 4 => 'D', 5 => 'A', 6 => 'C', 7 => 'C', 8 => 'C', 9 => 'B', 10 => array('A','B','C')); foreach ($answers as $num => $answer): $question = 'q'.$num; if(is_array($answer) && isset($_POST[$question])){ $ans_cnt = count($answer); $ans_value = (1 / $ans_cnt); $post_cnt = count($_POST[$question]); //find matches between answer array and post array $matches = array_intersect($answer,$_POST[$question]); $good_answers = count($matches); //Get bad answer count, which be be subtracted from overall score $bad_answers = 0; foreach($_POST[$question] as $post_answer): if(!in_array($post_answer,$answer)): $bad_answers++; endif; endforeach; //Result of good answers minus bad answers // $result = $good_answers - $bad_answers; if($good_answers > $bad_answers){ $result = $good_answers - $bad_answers; }else{ $result = 0; } if(($post_cnt != $ans_cnt) || ($post_cnt == $ans_cnt && $ans_cnt != count($matches))){ $result = $result * $ans_value; $totalCorrect = $totalCorrect + $result; }else{ $totalCorrect++; } }elseif(isset($_POST[$question]) && strtolower($_POST[$question]) === strtolower($answer)){ $totalCorrect++; } endforeach; $pct = round( (($totalCorrect/count($answers)) * 100), 0); echo $totalCorrect.' correct ('.$pct.'%)'; endif;
  19. I keep getting the following error: Fatal error: Function name must be a string in /home/dmyers53/public_html/Projects/Chisese_Zodiac_for_loop.php on line 34 I dont have a function named, where am I going wrong? <body> <img src="images/rat.jpg"></img><!--test the source. WORKS--> <?php error_reporting(E_ALL); ini_set('display_errors', 'on'); echo "<p>This line works</p>\n";//yes it does $zodiacPictures = array( "images/rat.jpg", "images/ox.jpg", "images/tiger.jpg", "images/rabbit.jpg", "images/dragon.jpg", "images/snake.jpg", "images/horse.jpg", "images/sheep.jpg", "images/monkey.jpg", "images/rooster.jpg", "images/dog.jpg", "images/pig.jpg"); for ($imgCounter = 0; $imgCounter <= 12; ++$imgCounter){ echo '<img src="' . $zodiacPictures($imgCounter) . '"></img>';// line 34 } ?> </body> </html>
  20. how i can make a insert using this fuctions I m learning php, as using this functions (mysqli abstract) but after update wont work any more. /** insert data array */ public function insert(array $arr) { if ($arr) { $q = $this->make_insert_query($arr); $return = $this->modifying_query($q); $this->autoreset(); return $return; } else { $this->autoreset(); return false; } } complement /** insert query constructor */ protected function make_insert_query($data) { $this->get_table_info(); $this->set_field_types(); if (!is_array(reset($data))) { $data = array($data); } $keys = array(); $values = array(); $keys_set = false; foreach ($data as $data_key => $data_item) { $values[$data_key] = array(); $fdata = $this->parse_field_names($data); foreach ($fdata as $key => $val) { if (!$keys_set) { if (isset($this->field_type[$key])) { $keys[] = '`' . $val['table'] . '`.`' . $val['field'] . '`'; } else { $keys[] = '`' . $val['field'] . '`'; } } $values[$data_key][] = $this->escape($val['value'], $this->is_noquotes($key), $this->field_type($key), $this->is_null($key), $this->is_bit($key)); } $keys_set = true; $values[$data_key] = '(' . implode(',', $values[$data_key]) . ')'; } $ignore = $this->ignore ? ' IGNORE' : ''; $delayed = $this->delayed ? ' DELAYED' : ''; $query = 'INSERT' . $ignore . $delayed . ' INTO `' . $this->table . '` (' . implode(',', $keys) . ') VALUES ' . implode(',', $values); return $query; } before update this class i used to insert data like this $db = Sdba::table('users'); $data = array('name'=>'adam'); $db->insert($data); this method of insert dont works on new class. if i try like this i got empty columns and empty values. thanks for any help complete class download http://goo.gl/GK3s4E
  21. Hi guys, I've got quite a few fields in my tables that i've serialised to keep the number of fields down. For everything else that works perfect as it stores the data and when needed I can use the following as an example: $dateofbirth = unserialize($row['dateofbirth']); $dobday = $dateofbirth[0]; $dobmonth = $dateofbirth[1]; $dobyear = $dateofbirth[2]; Date of birth is stored as dd,mm,yyyy and for everything else I can call it fine. My issue is now that i'm trying to use fputcsv to create a csv file using the following: $result = mysqli_query($con, 'SELECT u.user_id, b.dateofbirth FROM Users u INNER JOIN Basic b USING (user_id) ORDER BY user_id DESC'); $fp = fopen('latest.csv', 'w'); fputcsv($fp, array('User ID', 'DOB' )); The CSV generates, but for the date of birth column in the csv it outputs as "a:3:{i:0;s:2:"03";i:1;s:2:"02";i:2;s:4:"1986";}" because it's obviously still serialised. What is my best and or easiest way of handling these fields? Many thanks in advance.
  22. Hello, Here is my code: <?php require 'vendor/autoload.php'; $client = new Elasticsearch/Client(); $root = realpath('~/elkdata/for_elk_test_2014_11_24/Agencies'); $iter = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($root, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD); $paths = array($root); foreach ($iter as $path => $dir) { if ($dir -> isDir()) { $paths[] = $path; } } //Create the index and mappings $mapping['index'] = 'rvuehistoricaldocuments2009-2013'; //mapping code $mapping['body'] = array ( 'mappings' => array ( 'documents' => array ( '_source' => array ( 'enabled' => true ), 'properties' => array( 'doc_name' => array( 'type' => 'string', 'analyzer' => 'standard' ), 'description' => array( 'type' => 'string' ) ) ) ) ); $client ->indices()->create($mapping) //Now index the documents for ($i = 0; $i <= count($paths); $i++) { $params ['body'][] = array( 'index' => array( 'type' => 'documents' 'body' => array( 'foo' => 'bar' //Document body goes here ) ) ); //Every 1000 documents stop and send the bulk request. if($1 % 1000) { $responses = $client->bulk($params); // erase the old bulk request $params = array(); // unset the bulk response when you are done to save memory unset($responses); } } ?> I am looking to index a large amount of documents using elastic search and php. I have a very complex directory filled with other directories that i need to index into an array. I wanted to see if my code looked right, and if not what am I doing wrong? Thanks, Austin Harmon
  23. How come this doesn't loop? Everything is in the while loop. My database connection is in the included file you see to begin the code which is what db_conx refers to just to be clear. Database connection is not an issue nor is getting values. I just get the first one and nothing more. No looping taking place here. What I miss? require('includes/db_connect.php'); $query = "SELECT * FROM events ORDER BY displayorder ASC"; $result = mysqli_query($db_conx, $query); while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $pid = $row["id"]; $title = $row["title"]; $date = $row["date"]; $info = $row["info"]; $linkTxt = $row["linkTxt"]; $link = $row["link"]; $message = "<div id='events_holder'><table width='500' border='0' cellspacing='0' cellpadding='10'> <form action='edit_event_parse.php' method='post'> <tr> <td class='prayer_title'>Title:</td> <td><input type='text' name='title' class='admin_input' value='" .$title."' /></td> </tr> <tr> <td class='prayer_title'>Date:</td> <td><input type='text' name='date' class='admin_input' value='".$date."' /></td> </tr> <tr> <td class='prayer_title'>Link Text:</td> <td><input type='text' name='linkTxt' class='admin_input' value='".$linkTxt."' /></td> </tr> <tr> <td class='prayer_title'>Link URL:</td> <td><input type='text' name='link' class='admin_input' value='".$link."' /></td> </tr> <tr> <td class='prayer_title'>Event Details:</td> <td><textarea name='info' cols='20' rows='10' class='admin_area'>".$info."</textarea></td> </tr> <tr> <td><input type='hidden' name='pid' value='".$pid."' /></td> <td><input name='submit' type='submit' value='Edit Event' class='admin_submit'/></td> </tr> </form> </table> <p> </p> <hr /> <p> </p> </div>"; } Thanks!
  24. Hey guys i need help with a CURL code. I need to retreive all the data in a table located at http://www.listenlive.nl/tvgenre.php?g=1&page=0 and parse the data to finish with an array that looks like this: $row[0][station_name] = '3BTV'; $row[0][stream_link] = '420'; $row[0][stream_type] = 'wma'; $row[0][country] = 'United Kingdom'; $row[0][genre][0] = 'Variety'; $row[0][genre][1] = 'Alternative'; $row[0][genre][2] = 'Culture'; $row[0][rating] = '1/5'; I need that for each rows of the table where the first array number would increment $row[1], $row[2] ... My PHP code is incomplete. I currently have a loop for all the TR's of the page ... and when i loop all the TD's inside the TR's it returns a load of crap ... I am unsure where to go from here. Any help would be apreciated thx This is my code: $ch = curl_init(); $categ[url] = 'http://www.listenlive.nl/tvgenre.php?g=1&page=0'; curl_setopt($ch, CURLOPT_URL, $categ[url]); curl_setopt($ch, CURLOPT_POST, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies); curl_setopt($ch, CURLOPT_COOKIE, $cookies); curl_setopt($ch, CURLOPT_REFERER, $categ[url]); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_USERAGENT, $nav); $data2 = curl_exec($ch); $dom2 = new DOMDocument(); libxml_use_internal_errors(true); $dom2->loadHTML($data2); $trs = $dom2->getElementsByTagName('tr'); foreach ($trs as $tr) { echo "<pre>"; print_r($tr); echo "</pre>"; }
  25. I'm sure this is something simple that I'm just overlooking right now, but it's got me very frustrated and I just want a quick fix... I have 2 arrays, $data_old and $totals_old Let's say each looks like this (with the 123456 being different for both): Array ( [2014] => Array ( [123456] => Array ( [EMPS] => 114350 ) ) ) When I merge the two, I get something like this: Array ( [2014] => Array ( [0] => Array ( [123456] => Array ( [EMPS] => 114350 ) ) [1] => Array ( [60] => Array ( [EMPS] => 1470 ) ) ) ) How can I avoid the [0] and [1] and just have those be [123456] and [60], without referencing the 123456 and 60?
×
×
  • 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.