Jump to content

Search the Community

Showing results for tags 'loop'.

  • 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. I have 3 staff members that need to pick vacation in a certain order. Each have X weeks vacation and can pick off a calendar their choice 1-3 weeks per round. I'm trying to loop through the DB to find who is next to pick with weeks left ~~~~~~First round of picking~~~~~~ STAFF 1 - PICK ORDER 1 - 3 weeks available STAFF 2 - PICK ORDER 2 - 5 weeks available STAFF 3 - PICK ORDER 3 - 3 weeks available Staff 1 takes 2 Weeks Staff 2 takes 1 Weeks Staff 3 takes 3 Weeks ~~~~~~Second round of picking~~~~~~ STAFF 1 - PICK ORDER 1 - 1 weeks available STAFF 2 - PICK ORDER 2 - 4 weeks available STAFF 3 - PICK ORDER 3 - No weeks left Staff 1 takes 1 Weeks Staff 2 takes 3 Weeks Staff 3 Skipped ~~~~~~Third round of picking~~~~~~ STAFF 1 - PICK ORDER 1 - No weeks left STAFF 2 - PICK ORDER 2 - 1 weeks available STAFF 3 - PICK ORDER 3 - No weeks left Staff 1 Skipped Staff 2 takes 1 Weeks Staff 3 Skipped ~~~~~~~~~~~~ All staff 0 weeks left end --calendar.php-- $year=2020; $sql = "SELECT * FROM vac_admin WHERE pick_year='$year'; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { $row_admin = mysqli_fetch_assoc($result); } $current_pick_staff = $row_admin['current_pick_staff']; $sql = "SELECT * FROM vac_pick_order WHERE pick_year='$year' && pick_order = '$current_pick_staff'"; $result = mysqli_query($conn, $sql); $row = mysqli_fetch_assoc($result); if($row['vac_c_counter'] < 0){ $emp_num = $row['emp_num']; }ELSE{ ?????????????????? goto next staff with weeks > 0 ?????Somthing like if ($current_pick_staff == 3){ $current_pick_staff = 1; }ELSE{ $current_pick_staff++; } ?????????????????? } ~<FORM>~~~~~~~~~~~~~~~~~~~~~ Staff with $emp_num can now pick ~~~~~~ $_POST -> $date = XXXX-XX-XX; $num_weeks = X; $emp_num; ~</FORM>~~~~~~~~~~~~~~~~~~~~~ --process.php-- $year = 2020; $date = $_POST['date']; $num_weeks = $_POST['num_weeks']; $emp_num = $_POST['emp_num']; $sql = "INSERT INTO vac_picks (pick_year,emp_num,date) VALUES ($year,$emp_num,$date)"; $sql = "UPDATE vac_pick_order SET vac_c_counter=vac_c_counter - $num_weeks WHERE emp_num='$emp_num'; $sql = "UPDATE vac_admin SET pick_order=pick_order +1 WHERE pick_year='$year' ; Then back to calendar.php until all weeks gone.
  2. I have a questions table and feedback table. I able to foreach the question header but not the feedback. My code as above: <?php $sql2 = "SELECT DISTINCT[question_id],[q_text] FROM [question]"; $ques = array(); $stmt2 = sqlsrv_query($conn, $sql2, $ques); while ($row = sqlsrv_fetch_array($stmt2, SQLSRV_FETCH_ASSOC)) { $ques[$row['question_id']] = $row['q_text']; } $sql = "SELECT [question_id], [Expr3],[Expr2] FROM [feedback] ORDER BY [Expr2] ASC"; $data = array(); $stmt = sqlsrv_query($conn, $sql); while (list($qid, $a, $eid) = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC)) { if (!isset($data[$qid][$eid])) { $data[$qid][$eid] = $newArray2; } $data[$qid][$eid][] = $a; } ?> <div class="container"> <?php // produce table header echo "<table border='1' id='table2excel'>\n"; echo "<tr><th>Employee ID</th>"; // loop over array of questions for the header foreach ($ques as $question) { echo "<th>$question</th>"; } echo "</tr>\n"; foreach ($data as $qid => $question) { foreach ($question as $question => $replies) { echo "<tr><td>$question</td>"; foreach (array_keys($ques) as $q_id) { echo "<td>"; echo $replies[$q_id]; echo "</td>"; } echo "</tr>\n"; echo "</tr>\n"; } } echo "</table>\n"; Questions Table: question_id q_text 1 Do you Like Red Color? 02A Do you Like Yellow Color? 02B Do you Like Blue Color? 3 Do you Like Green Color? 4 What color you like among them? 5 Do you Like Purple Color? 6 Do you Like Gold Color? 7 Do you Like Rose Gold Color? 8 Do you Like Black Color? 9 Do you Like Orange Color? The question 4, might be multiple answer. Feedback Table: question_id Expr2 Expr3 1 EMP1001 Yes 02A EMP1001 No 4 EMP1001 Red 4 EMP1001 Yellow 4 EMP1001 Blue 5 EMP1001 No 6 EMP1001 No 3 EMP1001 Yes 02B EMP1001 Yes 7 EMP1001 Yes 8 EMP1001 Yes 9 EMP1001 Yes 1 EMP1002 Yes 02A EMP1002 No 4 EMP1002 Red 5 EMP1002 No 6 EMP1002 Yes 3 EMP1002 Yes 02B EMP1002 Yes 7 EMP1002 No 8 EMP1002 9 EMP1002 Yes Result: Employee ID Do you Like Red Color? Do you Like Yellow Color? Do you Like Blue Color? Do you Like Green Color? What color you like among them? Do you Like Purple Color? Do you Like Gold Color? Do you Like Rose Gold Color? Do you Like Black Color? Do you Like Orange Color? EMP1001 EMP1002 EMP1001 EMP1002 EMP1001 EMP1002 EMP1001 EMP1002 EMP1001 EMP1002 EMP1001 EMP1002 EMP1001 EMP1002 EMP1001 EMP1002 EMP1001 EMP1002 EMP1001 EMP1002 Expected Result: Employee ID Do you Like Red Color? Do you Like Yellow Color? Do you Like Blue Color? Do you Like Green Color? What color you like among them? Do you Like Purple Color? Do you Like Gold Color? Do you Like Rose Gold Color? Do you Like Black Color? Do you Like Orange Color? EMP1001 Yes No Yes Yes Red No No Yes Yes Yes EMP1001 Yes No Yes Yes Yellow No No Yes Yes Yes EMP1001 Yes No Yes Yes Blue No No Yes Yes Yes EMP1002 Yes No Yes Yes Red No Yes No Yes The question id no.4 will allow multiple choice to select, hence there will be multiple feedback for that particular question. foreach.txt
  3. Hi - can anyone help? I'm new to PHP land, and failing at this particular part. I have an image slider - where each image is contained in a div (e.g it is not a slider using ul and il...) It is will be used in a template for many pages, which will each have a varying number of images. There for I need to create a loop that say 'when there is no img url found, return to img 1' I'm stump. Currently this is beyond me ..... Or do I need to start from scratch? (ARGH!) Here is my function function getImage($num) { global $more; $more = 1; $link = get_permalink(); $content = get_the_content(); $count = substr_count($content, '<img'); $start = 0; for($i=1;$i<=$count;$i++) { $imgBeg = strpos($content, '<img', $start); $post = substr($content, $imgBeg); $imgEnd = strpos($post, '>'); $postOutput = substr($post, 0, $imgEnd+1); $postOutput = preg_replace('/width="([0-9]*)" height="([0-9]*)"/', '',$postOutput);; $image[$i] = $postOutput; $start=$imgBeg+$imgEnd+1; } if(stristr($image[$num],'<img')) { echo '<a href="'.$link.'">'.$image[$num]."</a>"; } $more = 0; } and here's how I use it in the html: <div class="project-slider-mask w-slider-mask"> <div class="w-slide"> <?php getImage('1'); ?> </div> <div class="w-slide"> <?php getImage('2'); ?> </div> <div class="w-slide"> <?php getImage('3'); ?> </div> <div class="w-slide"> <?php getImage('4'); ?> </div> etc etc etc Help much much appreciated....been failing at this for so long!
  4. <?php function factorial($number) { if ($number < 2) { return 1; } else { return ($number * factorial($number-1)); } } function poisson($occurrence,$chance) { $e = exp(1); $a = pow($e, (-1 * $chance)); $b = pow($chance,$occurrence); $c = factorial($occurrence); return $a * $b / $c; } $x = 2.5; $y = 1.5; $calAll = array(); for($z = 0 ; $z <= 9 ; $z++) { array_push($calAll, (poisson($z,$x) * poisson(0,$y))*100, (poisson($z,$x) * poisson(1,$y))*100, (poisson($z,$x) * poisson(2,$y))*100 ); } $value = max($calAll); $key = array_search($value, $calAll); print_r($calAll) . "\n"; echo "max =",$value , " key =",$key . "\n";; ?> it is possible to find $z and the number 0,1 or 2 from the max of the returned array ? I used excel to perform this action and i found that for max=8.5854557290941 the $z is 2 and number 1 how to achieve this in php ?
  5. Here's a line. I want to add 100 more of same lines and increment the page numbers as shown below. I know I can just manually add 100 lines but Is there a way to do this with PHP that would make it easy? Or is this more of a javascript thing? // original $page1 = '<a href="?type='. $type_id .'&name='. $get_type_3_name_slug .'&page=1">1</a>'; // new $page1 = '<a href="?type='. $type_id .'&name='. $get_type_3_name_slug .'&page=1">1</a>'; $page2 = '<a href="?type='. $type_id .'&name='. $get_type_3_name_slug .'&page=2">2</a>'; $page3 = '<a href="?type='. $type_id .'&name='. $get_type_3_name_slug .'&page=3">3</a>'; $page4 = '<a href="?type='. $type_id .'&name='. $get_type_3_name_slug .'&page=4">4</a>'; $page5 = '<a href="?type='. $type_id .'&name='. $get_type_3_name_slug .'&page=5">5</a>'; ...etc
  6. Is it possible to append to cdatasection within xml file using a loop without creating a new cdata section with each loop thru. The code starts out by creating the basics for xml then enters into a loop to go thru each element of an array, appending the cdata. $xml=new DOMDocument('1.0', 'UTF-8'); $xml->preserveWhiteSpace = false; $xml->formatOutput = true; $components = $xml->createElement("components"); $name=$xml->createAttribute("name"); $name->value = "customEPGGrid"; $extends=$xml->createAttribute("extends"); $extends->value = "EPGGrid"; $components->appendChild($name); $components->appendChild($extends); $script = $xml->createElement("script"); $type=$xml->createAttribute("type"); $type->value = "text/brightscript"; foreach ($items as $item){ //ENTER INTO LOOP $cdata=$xml->createCDATASection(<<<EOT function init() m.content = createObject("RoSGNode","ContentNode") m.top.setFocus(true) dateNow = CreateObject("roDateTime") dateNow = dateNow.asSeconds() - 2000 addChannel({$item['name']}) addItem({$item['name']}, dateNow) m.top.content = m.content m.top.translation = [50, 300] m.top.numRows = 5 m.top.duration = 10800 m.top.nowNextMode = false m.top.infoGridGap = 0 m.top.channelInfoColumnLabel = "HELLO" end function sub addChannel(channelText as string) m.channel = m.content.createChild("ContentNode") m.channel.TITLE = channelText m.channel.HDSMALLICONURL = "http://css.boshanka.co.uk/wp-content/uploads/2015/04/icon-logo-design-small.png" end sub sub addItem(progText as string, timeStart) For i=0 To 5 Step 1 program = m.channel.createChild("ContentNode") program.TITLE = progText + str(i) program.PLAYSTART = timeStart + (i * 2000) program.PLAYDURATION = "2000" End For end sub EOT ); } $script->appendChild($cdata); $script->appendChild($type); $components->appendChild($script); $xml->appendChild($components); $xml->save($filename2); When executed like this, I get a new createCDATASection with each pass thru the loop. Not really wanting this, but one createCDATASection with different value or $item['name'].
  7. Hi, guys i'm trying to fetch all results from DB through a foreach loop. But it is not working as intended, as it brings only the first record and not the others. here is my code:- $sql1="select * from group_posts"; $stmt_t=$conn->prepare($sql1); $stmt_t->execute(); $data_fetch=$stmt_t->fetchAll(); foreach ($data_fetch as $row_d) { $postid=$row_d['gp_id']; $post_auth=$row_d['author_gp']; $post_type=$row_d['type']; $post_title= html_entity_decode($row_d['title']); $post_data= html_entity_decode($row_d['data']); $data1= array($post_data); // $data1= taggingsys($data0); $post_date=$row_d['pdate']; $post_avatar=$row_d['avatar']; $post_uid=$row_d['user_id']; if ($post_avatar != ""){ $g_pic='user/'.$post_uid.'/'.$post_avatar; } else { $g_pic='img/avatardefault.png'; } $user_image="<img src='{$g_pic}' alt='{$post_auth}' title='{$post_auth}' width='30' height='30'>"; $vote_up_count=$project->voteGroupCheck($postid, $_SESSION['id']); }
  8. Hello. Just a quick question about using a loop to create a string from post variables that will then be used in a query. I have several post variables submitted in a form, some of which contain a value of T. Others are not selected. In the database there are several columns which may contain values of T or may not. I would like to construct a query that searches for specific columns containing T and ignoring the rest. I'm using WHERE "T" IN(colnames). I need to get the column names into a comma separated string. Here's what I'm using: $postVal = array("1", "2", "3", "4", "5"); foreach ($postVal as $key=>$val){ $newVar = “col”.$val; if ($$newVar == "T") { *create/add to comma-separated string } else { *ignore } } I hope that seems clear enough. I'm just not sure if I'm on the right track or not. What do you think? Thank you, in advance!
  9. Hi, I am having a small issue with a front end html form, which through a series of looped input fields will update multiple WordPress posts at once, on submisson. The issue i'm having currently, is on submission it's only updating 1 post. I have found a solution to my problem, here: http://wordpress.stackexchange.com/questions/206372/how-to-handle-dynamic-form-data-with-repeating-fields But as i am still a bit of a novice, I have tried to apply the max_id solution to my code below, so far i've not got it to work. Using the solution on the above link, I don't suppose someone could show/tell me, what the code should be in it's entirety?? Including the foreach section, thanks! foreach( $testArray as $value ) { $post_information = array( 'post_title' => $value, 'post_status' => 'publish', // Choose: publish, preview, future, draft, etc. 'post_type' => 'predictions' //'post',page' or use a custom post type if you want to ); //update post wp_update_post($post_information);
  10. I have the following in a form that edits values already put into a dbase. $alev = array(1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => 'AP'); $dblev = explode(',',$row['hw_lev']); foreach ($alev as $key => $lev){ if(in_array($lev,$dblev)){ echo "<input type='checkbox' name='ud_lev[]' value='$lev' checked> $lev"; } else { echo "<input type='checkbox' name='ud_lev[]' value='$lev'> $lev"; } When I attempt to edit the dbase values, the following occurs: When I select the "A" checkbox, it is input into the database and reflects in the results. When I attempt to edit this, the "A" box is checked and all is well. When I select anything else AND "A" ("1", "A"), it is input into the database and reflects in the results. When I attempt to edit this, the "1" box is checked but the "A" box is NOT checked. This is what I need. I feel like the problem is with the array? But it could be the loop.. Probably something totally staring me in the face. You know how it goes. I was wondering if you see a problem in the array or in the loop. Any thoughts would be appreciated!
  11. Here's what I'm trying to do. I retrieve results using php foreach loop. Within that loop results, I want to show a div(.show-details) on mouse over only. How do I do that? This is my code so far. <style> .show-details { display: none; } </style> $get_records = $db->prepare("SELECT * FROM records WHERE record_id = :record_id"); $get_records->bindParam(':record_id', $record_id); $get_records->execute(); $result_records = $get_records->fetchAll(PDO::FETCH_ASSOC); if(count($result_records) > 0){ foreach($result_records as $row) { $get_record_title = $row['record_title']; $get_record_details = $row['record_details']; $get_record_price = $row['record_price']; ?> <div class="product"> <div class="product-title"> <?php echo $get_record_title; ?> </div> <div class="product-price"> <?php echo $get_record_price; ?> </div> </div> <div class="show-details"> <?php echo $get_record_details; ?> </div> <?php } } else { echo 'no results.'; } <script> $(document).ready(function() { $(".product").mouseover(function(){ $(".show-details").css("display", "block"); }); }); </script>
  12. Hi all, I am trying to calculate the straight line distance between two points by using their co-ordinates on each row from a mysql db that satisfies the query. It works fine, except the last for loop below calculates $lat[$x+1],$long[$x+1] to have blank fields as they no longer exist in the database therefore i have invalid distances calculated. My goal of this script is to find all the routes a particular day a flight attendant is working, by searching my db, rosters, then gathering the departure and arrival airport from this table. With these airports, I then extract their co-ordinates from the table, airports, and use the function below to calculate the distance. Hope it makes sense what I am trying to do below!! <?php function distance($lat1, $lon1, $lat2, $lon2, $unit) { $theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 60 * 1.1515; $unit = strtoupper($unit); if ($unit == "K") { return ($miles * 1.609344); } else if ($unit == "N") { return ($miles * 0.8684); } else { return $miles; } } $today = '2016-01-04'; $sql = "SELECT * FROM rosters WHERE Code = 'TESTUSER' AND SectorDate = '$today' ORDER BY BeginTime ASC"; $result = mysqli_query($cxn,$sql) or die ("Cant get rosters distance."); $dep = array(); $arr = array(); $lat = array(); $long = array(); while($row=mysqli_fetch_array($result)) { $dep[] = $row['Dep']; $arr[] = $row['Arr']; } echo 'Number of flights: '.count($dep).'<br />'; foreach($dep as $key => $value) { $sql = "SELECT * FROM airports WHERE IATA = '$value'"; $result = mysqli_query($cxn,$sql) or die ("Cant get airport coordinates."); while($row=mysqli_fetch_array($result)) { $lat[] = $row['Latitude']; $long[] = $row['Longitude']; } } $max = count($dep); for ($x = 0; $x <= $max; $x++) { echo $dep[$x].' - '.$arr[$x].'<br />'; echo floor(distance($lat[$x],$long[$x],$lat[$x+1],$long[$x+1], "N")) . "nm<br />"; } ?>
  13. Say I have this loop. foreach($record as $row) { <div class="hello">Hello World!</div> } I want to loop through and add a letter alongside the "Hello World!" above. To do that, I found this code. $azRange = range('A', 'Z'); foreach ($azRange as $letter) { print("$letter\n"); } How can I combine the two loops so that I get a result like this? A Hello World! B Hello World! C Hello World! D Hello World! E Hello World! F Hello World!
  14. This is my database structure: http://www.awesomescreenshot.com/image/733881/57d01b042ca99b9a36dde90dd6640cdc I would like to loop through all the child elements (those who's parent_id is set to the data_id within the same table). Therefore those with "parent_id" as "0" are parents, and those with parent_id with a number in it is a child. I would like help creating a function that will generate tables, with the table itself as the parent, and all the rows within it would be children of that parent. There is only one layer of depth in this project (one parent and one child layer always. ). Can anyone help, or would want a more detailed description? Thank you, and looking forward to a reply.
  15. 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.
  16. Hi, I am trying to add values together in my while loop, so far I have: $q->query($DB, $SQL); while($avrating=$q->getrow()): $averageratings = $avrating['sum(rating)'] / $noofreviews; $overallaverage = round($averageratings, 2) + round($averageratings, 2); echo '<p>'.$avrating['rating_name'].': '.round($averageratings, 2).'</p>'; endwhile; echo 'x'.$overallaverage; $overallaverage += $overallaverage / 10; echo 'The Average: '.$overallaverage; from this, I get: x7.34The Average: 8.074 the total shold be: 42.34 then dived by 10 should be 4.23
  17. Hi, I have 2 tables of data REVIEWS and RATINGS I would like to show a list of my reviews and a list of rating for each of my reviews I have tried putting my second WHILE loop inside teh first one but that doesn't work, can anyone please help? here is my code: $SQL = "SELECT * FROM school_reviews WHERE active = 1 AND is_deleted = 0 AND school_id = '" . $school_id . "' ORDER BY review_date DESC"; $q->query($DB,$SQL); while($review = $q->getrow()): $reviewid = $review['review_id']; echo $reviewid; echo '<h3>'.$review['review'].'</h3>'; endwhile; echo '<ul>'; $SQL = "SELECT * FROM ratings WHERE review_id = '".$reviewid."'"; $q->query($DB,$SQL); while($rating = $q->getrow()): echo '<li>'.$rating['rating_name'].': '.$rating['rating'].'</li>'; endwhile; echo '</ul>'; here is an example of the review I get: ReviewID: 46 Review: testing the reviews ReviewID: 43 Review: Because I know John is sooo handsome and he works at Cactus ReviewID: 40 Review: iuhi Ratings: Course / Course content: 5 Teacher: 5 Social Programme: 5 School Facilities: 5 Atmosphere: 5 Location: 5 Accommodation: 4 Service from Cactus: 2 Value for money: 3 Overall Experience: 5
  18. Hello so I have a simple code here that will check if a random number already exists in the database and will generate a new one: $rand = mt_rand(100000, 999999); $sid = array( ":sponsorID" => $rand ); $accounts = $db->select("accounts", "sponsorID = :sponsorID", $sid) while(count($accounts) > 0) { $newNum = mt_rand(100000, 999999); } What I wanted to do is to echo out $newNum. When I echo it out I get undefined index of that variable. How can I solve this?
  19. Hi everyone, I am still learning PHP, I am getting better a little, but i am still struggle with while and foreach loop to create few columns. I create one column with while or foreach, but I couldn't figure to create few columns intsead of one long column. Can you help me or make any suggest? Thank you so much
  20. Hi I'm currently connecting to a API to retrieve info. The info I'm retrieving is in the form of Std Class Object. The problem I'm experiencing is that the results I get from one call is limited to 25. They say I should iterate it. But im not sure how to do so. My code so far <html> <?php require_once('MxitAPI.php'); try { $key = '************************'; $secret = '*****************************'; $api = new MxitAPI($key, $secret); if (isset($_GET) && isset($_GET['code'])) { $api->get_user_token($_GET['code'], 'http://********************'); // Get Contacts $contacts = $api->get_contact_list('@Friends', 0, 25); //print_r($contacts); foreach ($contacts->Contacts as $data) { echo $data->DisplayName."<br>"; $invite = $data->UserId; $invite1 = $invite . ','; /* generate the message */ $id = $_SERVER["HTTP_X_MXIT_USERID_R"]; $msg = "Hey! Come join me on {0}! And lets chat like a boss... :-P :-D"; $link = array( array( 'CreateTemporaryContact' => true, 'TargetService' => '********', 'Text' => '*****' ) ); /* send the message */ $api->send_message($id, $invite1, $msg, 'true', $link); } } elseif (isset($_GET) && isset($_GET['error']) && isset($_GET['error_description'])) { echo "<h2>There was an error requesting access from the API</h2>"; echo '<strong>Error:</strong> '. $_GET['error'] .'<br />'; echo '<strong>Error Description:</string> '. $_GET['error_description'] .'<br />'; } else { $api->request_access('***********************', 'graph/read message/user'); } } catch (Exception $e) { echo $e->getMessage(); } ?> <a href="page.php">Back</a> </html> They say I should turn $contacts = $api->get_contact_list('@Friends', 0, 25); into a loop but not sure how to do so the 0 is the files to skip and 25 is the amount to retrieve with each call. they say There is a default page limit of 26, so to access the user's complete contact list you will be iterate this call. More info can be found here regarding the API im trying to use with print_r option my object looks like stdClass Object ( [Contacts] => Array ( [0] => stdClass Object ( [DisplayName] => Zyco [FirstName] => zyco [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1426134583000+0200)/ [LastOnline] => /Date(1426139350470+0200)/ [StatusMessage] => ) [UserId] => 0769114834 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [1] => stdClass Object ( [DisplayName] => cobusbo [FirstName] => Cobus [LastName] => Botma [State] => stdClass Object ( [Availability] => 2 [IsOnline] => 1 [LastModified] => /Date(1426162593000+0200)/ [LastOnline] => /Date(1426180367476+0200)/ [Mood] => 0 [StatusMessage] => checkout spamchat ) [UserId] => 27765238453 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [2] => stdClass Object ( [DisplayName] => Bassmaker [FirstName] => Stefan [LastName] => Hattingh [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1425535612000+0200)/ [LastOnline] => /Date(1426232999571+0200)/ [StatusMessage] => Lesson learned!!!! Never fall inlove!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ) [UserId] => 27828456765 [Blocked] => [Group] => MXit [ContactType] => 0 [SubscriptionType] => 66 ) [3] => stdClass Object ( [DisplayName] => SHERIFF [FirstName] => ``ॐ☀☺ॐB.I.G5☺™♦.+LIONKIng [LastName] => ँ๏°˚ _♥_☺™♦☀LORDMINATI☀☺™♦๏° [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1420610808000+0200)/ [LastOnline] => /Date(1426171691976+0200)/ [StatusMessage] => #ff425a #ff425aLaVeyan sHaitAn Bible. ) [UserId] => m11231391002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [4] => stdClass Object ( [DisplayName] => HunterPoint. [FirstName] => Caroline [LastName] => Boot [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1426227463000+0200)/ [LastOnline] => /Date(1426240850456+0200)/ [StatusMessage] => Friend isn't about who you've know the longest it's about who walked into your life said "I'm here for you" and proved it. ) [UserId] => m18323190002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [5] => stdClass Object ( [DisplayName] => $Sugar$ $Max$ [FirstName] => $sugar$ $max$ [LastName] => Sugar$ $max$ [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1425995353000+0200)/ [LastOnline] => /Date(1426237305719+0200)/ [StatusMessage] => ) [UserId] => m19055694002 [Blocked] => [Group] => MXit [ContactType] => 0 [SubscriptionType] => 66 ) [6] => stdClass Object ( [DisplayName] => .-.-.-KID☀BIG [FirstName] => *#c0c00c.+.+.+KID #c0c0c0BIG* [LastName] => *#c0c0c0.+.+.+BUMS#00ff00HAKA* [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1424843034000+0200)/ [LastOnline] => /Date(1425665935177+0200)/ [StatusMessage] => ) [UserId] => m24542119002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [7] => stdClass Object ( [DisplayName] => Kλzεhιτsυjι [FirstName] => [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1425991633000+0200)/ [LastOnline] => /Date(1425991773513+0200)/ [StatusMessage] => #9966fb phone broken ) [UserId] => m25912500002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [8] => stdClass Object ( [DisplayName] => (H)FATIMA(H) [FirstName] => /#ff0000Fatima/ [LastName] => /#ff0000Japhta/ [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1425912639000+0200)/ [LastOnline] => /Date(1426239237672+0200)/ [StatusMessage] => Busy..... Flaming spirit-: SITTER ) [UserId] => m35370741002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [9] => stdClass Object ( [DisplayName] => ��m�H� W�YB�Y [FirstName] => Francois Barnard [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1426006669000+0200)/ [LastOnline] => /Date(1426183951042+0200)/ [StatusMessage] => ...... Ķãmãķãżī Wãřłøřđś .... If anyone knows coding pls msg me ... or if u know wapka msg me pls ((( Checkout Extreme_gamers ))) ) [UserId] => m37042581002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [10] => stdClass Object ( [DisplayName] => *#ff0000 #0000ffXena* [FirstName] => Km vnd yt [LastName] => Vra jw nek [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1424576823000+0200)/ [LastOnline] => /Date(1424577160006+0200)/ [StatusMessage] => .+#0000ff ) [UserId] => m40566397002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [11] => stdClass Object ( [DisplayName] => {{*BL!TZKR!3G#]] [FirstName] => [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1425809938000+0200)/ [LastOnline] => /Date(1425818270545+0200)/ [StatusMessage] => Cheers Galaxy Wars. ) [UserId] => m41544489002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [12] => stdClass Object ( [DisplayName] => Lord of chaose [FirstName] => [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1426188520000+0200)/ [LastOnline] => /Date(1426224169262+0200)/ [StatusMessage] => ) [UserId] => m42930422002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [13] => stdClass Object ( [DisplayName] => Morning-staR• [FirstName] => Apocalypse [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1426016522000+0200)/ [LastOnline] => /Date(1426236913282+0200)/ [StatusMessage] => D.N.A femceE's Crew be Making a one hella sick tour around DBN. Lol err don't even ask about the Males Crew but i'm happy for all my gals daddy cant wait for ya'll to come back so we can start eating some MoOLa(((LMAO))) ) [UserId] => m43239048002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [14] => stdClass Object ( [DisplayName] => #Ff0000*.+.+.+©£MP£ROR©#Ff0000*.+.+.+ [FirstName] => #Ff0000*.+.+JUMONG#Ff0000*.+.+ [LastName] => #cc00cc*.+.+DYNA§TY#Ff0000*.+.+ [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1421736155000+0200)/ [LastOnline] => /Date(1426225275110+0200)/ [StatusMessage] => #ff00ff®eally.. Visit my download portal- VENTRICK | Home Of Downloads Remember d sabbath dat 2 kip it holy. I can do all tins 2ru christ which streghteneth me! ) [UserId] => m46623264004 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [15] => stdClass Object ( [DisplayName] => kira [FirstName] => Kira [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1426111312000+0200)/ [LastOnline] => /Date(1426231189633+0200)/ [StatusMessage] => Havent! ) [UserId] => m48340699002 [Blocked] => [Group] => MXit [ContactType] => 0 [SubscriptionType] => 66 ) [16] => stdClass Object ( [DisplayName] => DEATHANGEL [FirstName] => DEATH [LastName] => ANGEL [State] => stdClass Object ( [Availability] => 3 [IsOnline] => 1 [LastModified] => /Date(1426239062000+0200)/ [LastOnline] => /Date(1426239536392+0200)/ [Mood] => 1 [StatusMessage] => ) [UserId] => m49191486002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [17] => stdClass Object ( [DisplayName] => Shadow Reaper [FirstName] => dont [LastName] => know [State] => stdClass Object ( [Availability] => 1 [IsOnline] => 1 [LastModified] => /Date(1426189573000+0200)/ [LastOnline] => /Date(1426237783400+0200)/ [Mood] => 6 [StatusMessage] => Leave me alone not in the mood...tik verby ) [UserId] => m51256041002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [18] => stdClass Object ( [DisplayName] => 《■□●◆8-)¿¥¤UNG §K@T£R¿8-)●■●♧》 [FirstName] => #fe333d??? [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1425840233000+0200)/ [LastOnline] => /Date(1425126238187+0200)/ [StatusMessage] => #669966 ) [UserId] => m52626156002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [19] => stdClass Object ( [DisplayName] => .+_*#ffff00ICON*_ [FirstName] => .+*MCKINGO #ffff00 [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1424897461000+0200)/ [LastOnline] => /Date(1425331624085+0200)/ [StatusMessage] => THE ICON NOT AND NEVER WILL BE XCON.AM THE APEX OF APEX PREDATORS ) [UserId] => m56408943004 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [20] => stdClass Object ( [DisplayName] => *N-R* [FirstName] => [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1424209196000+0200)/ [LastOnline] => /Date(1426181775833+0200)/ [StatusMessage] => ) [UserId] => m58722247002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [21] => stdClass Object ( [DisplayName] => ZIYAD [FirstName] => [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1426097756000+0200)/ [LastOnline] => /Date(1426182338901+0200)/ [StatusMessage] => I'm not here right now ) [UserId] => m60626483002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [22] => stdClass Object ( [DisplayName] => king•othello [FirstName] => [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1426175909000+0200)/ [LastOnline] => /Date(1426176930152+0200)/ [StatusMessage] => ) [UserId] => m61831903002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [23] => stdClass Object ( [DisplayName] => #c0c00c.+.+.+*Mxit hacker* [FirstName] => $Mxit hacker$ [LastName] => $Mxit hacker$ [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1423285744000+0200)/ [LastOnline] => /Date(1423285748616+0200)/ [StatusMessage] => 2015 comes with new cheat tricks tht i created [Image] [Image] ) [UserId] => m62798876002 [Blocked] => [Group] => MXit [ContactType] => 0 [SubscriptionType] => 66 ) [24] => stdClass Object ( [DisplayName] => james basson [FirstName] => [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1425222833000+0200)/ [LastOnline] => /Date(1425224038803+0200)/ [StatusMessage] => ¿Grim Give¿ ) [UserId] => m63089464002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [25] => stdClass Object ( [DisplayName] => Kizer Dengram [FirstName] => Clinton [LastName] => Ifeanyichukwu [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1424621304000+0200)/ [LastOnline] => /Date(1426236525690+0200)/ [StatusMessage] => Ooh Lord My havenly father, as i arrange my wonderful bed (Future) so i will lie on it... But lord as i am part of your family, please lord come and help me to arrange my Bed (My Future) coz only me cant arrange a whole wide Bed, for fear of Wolves! Amen! ) [UserId] => m63748006002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) ) ) this is only the first 26 people info on my contact list I need to get a way to iterate it when the call is done with the first 26 to move on to the next 26. and then the next 26 etc. I looked at $contacts = $api->get_contact_list('@Friends', 0, 25) and saw the 0 for skipped items and 25 for page limit. is there maybe a way to create a loop to say with the first call skip 0 with the second recall skip the first 25 and with 3rd recall skip the first 50 till its done...
  21. First off, I am very new to php and I am learning the best I can. I am trying to display a dynamic grid style table within a loop and display my mysql data inside of it. The data is a Image URL, directory URL, URL description, and it prints all this data as an image with a link to the gallery. The code works fine as... 5 wide x 5 down. It's supposed to look a little something like this: [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] Now that works, however when I change my rows and column variable # to 7 and 7 is when the problems start.. Here is my main code for this function: //define variables $uniqhash = ""; $modelname = ""; $email = ""; $galleryurl = ""; $gallerydesc = ""; $category = ""; $datesubmitted = ""; $gallerythumb = ""; $rows = 0; $count = 0; $columns = 0; $select = "SELECT * From `models`"; $images_rows = mysqli_query($conn, $select); $images = array(); if( empty( $images ) ) { echo 'Sorry, there was a fatal error in selecting images from database.'; } while ($image = mysqli_fetch_assoc($images_rows)) { $images[] = $image; } echo '<table align="center" border="0"><tr>'; $size = sizeOf($images) - 1; //get count of array and put into $size foreach($images as $image){ if($rows == 7) { echo '</tr><tr>'; // if our count is x wide, start a new row $rows = 0; } if ($columns == 7){ echo '</tr><tr>'; $columns = 0; } echo "<td><a href=" . $image['galleryurl'] . " target=\"new\"><img src=" . $image['gallerythumb'] . " height=\"160\" width=\"160\" alt=\"" . $image['gallerydesc'] . "\"></a></td>"; $rows++; $count++; $columns++; echo ($rows == 7 && $columns == 5 && $count != $size) ? '</tr>': ''; } echo '</tr></center></table>'; When I change $rows and $columns to 7 each it will display images like: (sample of 13 images) [] [] [] [] [] [] [] [] [] [] [] [] [] [] I would like it to print x images across for $rows and x amount of rows for $columns in a grid like fashion. If anyone can give me some help on this I would appreciate it...I have been desperately reading up on loops trying to figure it out but so far no luck. P.S I am familiar with sanitizing all my data and that I need to implement this but I want to make sure my code functions first.
  22. I am having a bit of issue. I have a simple query that loops to find each record, like this. // select query here if(count($result) > 0) { foreach($result as $row) { $userid = $row['user_id']; $_SESSION['userid'] = $userid; } } else { // error here } I want to use the "$userid" on a different page; so I created a session for it. When ever I use that session on another page, it gives me only the last record's user id and not the first one. How can I fix this?
  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. Hi everyone, greetings from Brazil. I am an average php coder, much more a designer than an programer, and i am in a looper trouble.. Can anyone try to help me? Here is my code: <table border="1"> <tr> <?php //pega cada uma das operadoras do campo operadoras $operadoras = $opers_trazOperadoras ; $logos = explode(",",$operadoras); $x = 0 ; foreach ($logos as $v) { mysql_select_db($database_webroker, $webroker); $query_trazLogoOperadora = "SELECT * FROM tb_operadora WHERE tb_operadora.id_operadora = " . $v ; $trazLogoOperadora = mysql_query($query_trazLogoOperadora, $webroker) or die(mysql_error()); $row_trazLogoOperadora = mysql_fetch_assoc($trazLogoOperadora); $totalRows_trazLogoOperadora = mysql_num_rows($trazLogoOperadora); ?> <td><img src="http://www.we-broker.com.br/admin/imagens_upload/<?php echo $row_trazLogoOperadora['logo']; ?>"> <?php do { ?> <?php } while ($x++ < 4); { echo $x ;?> </td></tr><tr> <?php } $x = 0 ; } ?> </table> The URL for this code is: http://valsegs.we-broker.com.br/operadorasPATO.php Tks!
  25. Hi guys, Having trouble trying to show values from my $friend array. Only the first friend code is being displayed in my output. There are several fields in my mysql associated with the $sql. Any ideas? Thanks $sql = "SELECT * FROM friends WHERE Code = '$code' OR FriendCode = '$code' AND Status ='A'"; $result = mysqli_query($cxn,$sql) or die ("Can't get friends."); $friend = array(); while($row=mysqli_fetch_array($result)) { if($code == $row['FriendCode']) { $friend[] = $row['Code']; } elseif($code == $row['Code']) { $friend[] = $row['FriendCode']; } foreach($friend as $key => $value) { echo $value.'<br />'; }
×
×
  • 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.