PHP - Increment A Variable In A "foreach" Loop
Hi Guys
Ever had the feeling your being a spoon and can't see the wood for the trees? Well, that's how I feel today. All I am trying to to is implement a variable in a "foreach" loop that increments by one through each iteration of the loop. I know how to do it in a "for" loop but can't for the life of me get it to work here. Here is the code: foreach ($cart as $prodcode => $qty) { $item = get_product_details($prodcode); echo '<input type="hidden" name="item_name_'.[b]$needavariablehere[/b].'" value="'.$item['description'].$_SESSION['finish'][$prodcode].$_SESSION['handles'][$prodcode].'" />' . "\n"; } Where I have highlighted $needavariablehere is where I want a number to appear i.e. if there is one item available and the foreach loop iterates once I want the number 1 here. If there are two items and the foreach loop iterates twice I want the output to have number 1 in the first line and number 2 the second time around and so on. How many times the foreach loop iterates is based on the $cart array which contains items in a shopping cart. Thanks for any help you can give guys. Similar Tutorialshello how do i pass a foreach loop through "Passing by Reference" say i have a foreach loop in a function like this: Code: [Select] function findText(&$output){ $word = Text::find_all(); foreach ($word as $words){ $output = $words->text; } } then one the page i put Code: [Select] findText($output); echo $output; that will just give me the last word in the database. so how do i get it to echo out the array on the page ? thanks question of perfomance .. Code: [Select] //take the names from table1 apply($sql1); foreach($names as $name){ //grab other info about the current user from table2 apply($sql2); } is this fine ? Hey guys, Got another question im hoping someone can help me with. I have a foreach loop (for use in a mysql query): foreach ($interests as $interest) { $query .= "($id, $interest), "; } problem is i do not want the comma(,) in the last loop. Is there some kinda of function i can use so it does not insert it on last loop? Or should i just use a for loop with a nested if loop? something like ; for($i=0; $i < count($interests); $i++){ $query .= "($id, '$interests[$i]')"; if($i + 1 < count($interests)) { $query .= ", "; } } Cheers guys Can someone please help me with an array problem i can not figure out. I need the array to be numbered from 1 to how ever many fields that are needed in the form and have a mysql field name and the title of the field also in the array. 1, "mysql_field_name", "Title of form field" 2, "", "" and so on then the form will be shown based on the array. I have the following draft code which I am working with. any suggestions on how i may do this array ? Code: [Select] <?php $options = array( '1'=> array('fieldtext'=>'option1', 'mysqlfield'=>'option1'), '2'=> array('fieldtext'=>'option2', 'mysqlfield'=>'option2'), '3'=> array('fieldtext'=>'option3', 'mysqlfield'=>'option3'), '4'=> array('fieldtext'=>'option4', 'mysqlfield'=>'option4'), ); // $options = array(1 => "option1", "option2", "option3", "option4"); // the line above works but i want to include the name of the mysql field as well. $userid = 1; ?> <div style="align: center; margin: 12px; font-family:Tahoma;"> <br><br><?php if ($_POST['Update'] != "Update") { // check if form submitted yet, if not get data from mysql. $res = db_query("SELECT * FROM `users` WHERE `userid` = '" . $userid . "'"); foreach($options as $key => $value) { $_POST[$key] = mysql_result($res, 0, $value); } $ok_to_update = "no"; } elseif ($_POST['Update'] == "Update") { // check if form submitted yet, if so get POST data. // error checking // foreach($options as $key => $value) { // $_POST[$i] = ""; // } $ok_to_update = "yes"; } if ($_POST['Update'] == "Update" && $ok_to_update == "yes") { // $res = db_query("INSERT INTO `users` () VALUES ()"); // add user details to database. ?><p><br><br><br>Thank you for updating</p><?php } else { ?><form name="form1" method="post" action=""> <?php foreach($options as $key => $value) { ?><p><?php echo($value); ?>: <input type="text" name="<?php echo($key); ?>" value="<?php echo($_POST[$key]);?>"></p> <?php } ?> <input name="Update" type="submit" value="Update"> </form> <?php } ?> </div> Hi, bit stuck on how to find and replace "<" and ">" with "<" and ">". I basically have a database record that outputs to screen and I need the code in the <code> tags to be rendered to the screen. I therefore need it to go through the whole array variable from the db and change the symbols just inside the code tags. Please be aware that the code tags might happen more than once here's an example below Code: [Select] <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> the desired output would be: <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> help on this would be great Cheers Rob
hi, i’m currently facing a new problem (i managed to use array_unique function successfully but i face this problem)with my php loop. i couldn’t seem to increment in my foreach loop to get the value of an array. $update_id1=Array ( [0] => 398 [1] => 397 [2] => 393 [3] => 391 [8] => ); //$i=0; foreach ($update_id1 as $i => $v) { $ex= explode(",", $v); $unique=array_unique($ex); //f$ketch username from update table in db and inject it to the feed query. $imp_id= implode(',', $ids); //$id1=$ids[$i]; // $x=0; // for($x=0;$x<count(unique);$x++){ echo 'ids:- '.$i; print_r($unique[$i]); echo '<br>'; //} $totalUpdates=$project->totalUpdates($ids[$i],$_SESSION['uname'] ,$unique[$i],$load); //$i++; } i tried every method nothing seems to work can anyone help me in this regard please. Edited December 25, 2019 by narutofanGreetings to all! I am very new to this so I may not be on the right track. I am providing some code I have because I think this is the best way to explain what I am trying to do. I have a database and php pages that generate a pedigree when one selects any particular dog from the search page. If anyway has a tip on how to simplify this, I would sure appreciate it!! First, I request an array for the dog selected: Code: [Select] $sql = "SELECT RegName, SireID, DamID FROM pedigrees WHERE ID="; $thisDogQ = $sql . $values["ID"]; $thisDogR = db_query($thisDogQ,$conn); $thisDogRow_value = mysql_fetch_assoc($thisDogR); $thisDogRow_value = array ( 'RegName' => $thisDogRow_value['RegName'], 'SireID' => $thisDogRow_value['SireID'], 'DamID' => $thisDogRow_value['DamID']); </code> //Next I request the same information for his sire <code> if (is_numeric($thisDogRow_value['SireID'])) { $query_SireQ = $sql . $thisDogRow_value['SireID']; $SireR = mysql_query($query_SireQ, $conn) or die(mysql_error()); $SireRow_value = mysql_fetch_assoc ($SireR); $SireRow_value = array ( 'RegName' => $SireRow_value['RegName'], 'SireID' => $SireRow_value['SireID'], 'DamID' => $SireRow_value['DamID']); </code> //and then his dam <code> if (is_numeric($thisDogRow_value['DamID'])) { $query_DamQ = $sql . $thisDogRow_value['DamID']; $DamR = mysql_query($query_DamQ, $conn) or die(mysql_error()); $DamRow_value = mysql_fetch_assoc ($DamR); $DamRow_value = array ( 'RegName' => $DamRow_value['RegName'], 'SireID' => $DamRow_value['SireID'], 'DamID' => $DamRow_value['DamID']); </code> Now, here's the rub: Now I need the sire and the dam for those 2 [described above] so this time through, I will need the same information for FOUR dogs. The next time will be for EIGHT, then SIXTEEN - and so on until there are a total of 256 dogs. <code> //Get PatGrandSire 2 if (is_numeric($SireRow_value['SireID'])) { $PatGrandSireQ = $sql . $SireRow_value['SireID']; $PatGrandSireR = mysql_query ($PatGrandSireQ, $conn) or die(mysql_error()); $PatGrandSireRow_value = mysql_fetch_assoc ($PatGrandSireR); $PatGrandSireRow_value = array ( 'RegName' => $PatGrandSireRow_value['RegName'], 'SireID' => $PatGrandSireRow_value['SireID'], 'DamID' => $PatGrandSireRow_value['DamID']); //GetPatGrandDam 17 if (is_numeric($SireRow_value['DamID'])) { $PatGrandDamQ = $sql . $SireRow_value['DamID']; $PatGrandDamR = mysql_query ($PatGrandDamQ, $conn) or die(mysql_error()); $PatGrandDamRow_value = mysql_fetch_assoc ($PatGrandDamR); $PatGrandDamRow_value = array ( 'RegName' => $PatGrandDamRow_value['RegName'], 'SireID' => $PatGrandDamRow_value['SireID'], 'DamID' => $PatGrandDamRow_value['DamID']); //Get Pat1GGrandSire-3 if (is_numeric($PatGrandSireRow_value['SireID'])) { $Pat1GGrandSireQ = $sql . $PatGrandSireRow_value['SireID']; $Pat1GGrandSireR = mysql_query ($Pat1GGrandSireQ, $conn) or die(mysql_error()); $Pat1GGrandSireRow_value = mysql_fetch_assoc ($Pat1GGrandSireR); $Pat1GGrandSireRow_value = array ( 'RegName' => $Pat1GGrandSireRow_value['RegName'], 'SireID' => $Pat1GGrandSireRow_value['SireID'], 'DamID' => $Pat1GGrandSireRow_value['DamID']); if (is_numeric($PatGrandSireRow_value['DamID'])) { $Pat1GGrandDamQ = $sql . $PatGrandSireRow_value['DamID']; $Pat1GGrandDamR = mysql_query ($Pat1GGrandDamQ, $conn) or die(mysql_error()); $Pat1GGrandDamRow_value = mysql_fetch_assoc ($Pat1GGrandDamR); $Pat1GGrandDamRow_value = array ( 'RegName' => $Pat1GGrandDamRow_value['RegName'], 'SireID' => $Pat1GGrandDamRow_value['SireID'], 'DamID' => $Pat1GGrandDamRow_value['DamID'], 'Title' => $Pat1GGrandDamRow_value['Title'], 'Title2' => $Pat1GGrandDamRow_value['Title2'], 'Title3' => $Pat1GGrandDamRow_value['Title3'], 'Title4' =>$Pat1GGrandDamRow_value['Title4'], 'Title5' => $Pat1GGrandDamRow_value['Title5'], 'Title6' =>$Pat1GGrandDamRow_value['Title6'], 'Title7' => $Pat1GGrandDamRow_value['Title7'], 'Title8' =>$Pat1GGrandDamRow_value['Title8'], 'Title9' => $Pat1GGrandDamRow_value['Title9'], 'Addl_Titles' => $Pat1GGrandDamRow_value['Addl_Titles']); //Get Pat2GGrandSire-18 if (is_numeric($PatGrandDamRow_value['SireID'])) { $Pat2GGrandSireQ = $sql . $PatGrandDamRow_value['SireID']; $Pat2GGrandSireR = mysql_query ($Pat2GGrandSireQ, $conn) or die(mysql_error()); $Pat2GGrandSireRow_value = mysql_fetch_assoc ($Pat2GGrandSireR); $Pat2GGrandSireRow_value = array ( 'RegName' => $Pat2GGrandSireRow_value['RegName'], 'SireID' => $Pat2GGrandSireRow_value['SireID'], 'DamID' => $Pat2GGrandSireRow_value['DamID'], 'Title' => $Pat2GGrandSireRow_value['Title'], 'Title2' => $Pat2GGrandSireRow_value['Title2'], 'Title3' => $Pat2GGrandSireRow_value['Title3'], 'Title4' => $Pat2GGrandSireRow_value['Title4'], 'Title5' => $Pat2GGrandSireRow_value['Title5'], 'Title6' => $Pat2GGrandSireRow_value['Title6'], 'Title7' => $Pat2GGrandSireRow_value['Title7'], 'Title8' => $Pat2GGrandSireRow_value['Title8'], 'Title9' => $Pat2GGrandSireRow_value['Title9'], 'Addl_Titles' => $Pat2GGrandSireRow_value['Addl_Titles']); //Get Pat2GGrandDaminfo-25 if (is_numeric($PatGrandDamRow_value['DamID'])) { $Pat2GGrandDamQ = $sql . $PatGrandDamRow_value['DamID']; $Pat2GGrandDamR = mysql_query ($Pat2GGrandDamQ, $conn) or die(mysql_error()); $Pat2GGrandDamRow_value = mysql_fetch_assoc ($Pat2GGrandDamR); $Pat2GGrandDamRow_value = array ( 'RegName' => $Pat2GGrandDamRow_value['RegName'], 'SireID' => $Pat2GGrandDamRow_value['SireID'], 'DamID' => $Pat2GGrandDamRow_value['DamID']); Hi guys I am a newbie with PHP and I have been trying to solve this problem for 3 days.. Ive set up a booking form on my website to be sent directly to my email once the client clicked on the send button.. The problem I am having while checking these pages on wamp is that the booking form is ok but when I click on the send button the following message error appears "Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\fluffy_paws\booking_form2.php on line 27" When I check online I have this message "500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed." Are my codes wrong??? My webhosting is Blacknight.com , Im on Windows Vista, my internet is a dongle with O2 ireland Thanks for your help! Hi guys I'm struggling a bit, I need to replace a word that occurs multiple times in text with an array("up","down","forward","backwards") of words. $find = "left"; $replace = array("up","down","forward","backwards"); $text = "left left left left"; echo str_replace($find,$replace,$text); The Output is: array array array array Did try this with a foreach statement as well, but no luck. Is there a better way of doing this? Thanks Greetings, My first post here. I'm learning PHP as rapidly as I can, but I still have some basic questions. OK, I'm trying to run the Gallerific gallery script on my site. The way Gallerific works, it looks at an unordered list to populate the gallery. In each list item, it grabs a main image and a thumbnail image. I have folders that are created dynamically as a user uploads photos. There is a main folder and a "thumbs" sub-folder. That's all taken care of before the script comes into play I need to loop through both the main images and the thumbnails at the same time, and call each one in the list items. I know this code must be wrong, but I'll post it as a starting place. Can someone help me figure out how to do this correctly? Maybe I should not even be using foreach? Code: [Select] <div id="thumbs" class="navigation"> <ul class="thumbs noscript"> <?php foreach($cck->get( 'property_listing_images' )->value as $large){ foreach($cck->getValue( 'property_listing_images' )->value as $thumb1){ ?> <li> <a class="thumb" href="images/<?php echo $large->value; ?>" title="Title X"> <img src="images/<?php echo $thumb1->value; ?>" alt="Title X" /> </a> </li> </ul> <?php } ?> <?php } ?> </div> Thank you ahead of time for your help! Matthew Hi everyone, I am just starting out with php so I am sure this is a really silly question. I have been working through php & mySQL for dummies (latest edition) and each time I read a new chapter I try to implement the tutorial. I have been trying something really simple from the book and have now even tried copying it word for word but it still will not work. I am basically trying to output a list of Cities and States with the following code: <?php $capitals = array ("CA" => "Sacramento", "TX" => "Austin", "OR" => "Salem" ); foreach ($capitals as $state => $city); ksort ($capitals); { echo "$city, $state<br />"; } ?> Instead of getting: Sacramento, CA Salem, OR Austin, TX I just get: Salem, OR I am running XAMPP on Mac OS X 10.6.5. Any ideas or help would be awesome! cant work out this mysql syntax error "operation":"medupdate","medid":"","name":"ibo","medyear":"5","medmonth":"21","medday":"1","recuser":1,"SuccFail":"fail","SuccFailMessage":"error occured You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '''WHERE med_id=' at line 2","ResultData":""} Code: [Select] $sql="update metodology set med_description='".$req['name']."', med_year='".$req['medyear']."', med_month='".$req['medmonth']."', med_day='".$req['medday']."', med_recorddate= now(), med_recorduserid= 1'"; $sql.= " WHERE med_id=".$req['medid']; I've searched but can't seem to find anything I can apply to this situation. Most of the resources are dedicated to dropdown menu's from the same table. I have two tables 'regions' and 'cities' and I am looking to create a menu that lists all the cities within a region then moves on to do the same for the rest of the regions in that state: State1 Region1 City1 City2 City3 Region2 City1 City2 City3 Region3 Etc My tables: States table: stateID, state Regions table: regionID, region, stateID Cities table: cityID, city, regionID I currently have two pages- select region, then select city... I'd like to consolidate to one step after choosing a state. I know I need a nested loop, (while?), and to count the results somehow to retrigger loop; also not sure how to handle two mySQL querries in the nested loop. I'm having trouble wrapping my mind around it. Thank you. I am trying to make a loop simply write "static" code...if that is the correct explanation.... But it seems PHP wants to "process" such things as 'IF' and other Conditions which is defeating the purpose. The problem specifically is that I NEED for a dynamic write to happen based on a variable that will put the following lines that start with IF (! isset // Make sure the checkbox arrays exist if (! isset($_POST['cp_checkbox_one'])) $_POST['cp_checkbox_one'] = array(); if (! isset($_POST['cp_checkbox_two'])) $_POST['cp_checkbox_two'] = array(); if (! isset($_POST['cp_checkbox_three'])) $_POST['cp_checkbox_three'] = array(); // here in the lines below is one way I have tried to make the the LINES ABOVE get written Dynamically // THIS PART returns the values I need, the checkbox names ---- // // foreach($_POST as $meta_key => $meta_value) { // if(cp_str_starts_with($meta_key, 'cp_checkbox')) { echo $meta_key; } // } // So that code WILL RETURN THE VALUES I NEED : // cp_checkbox_one, cp_checkbox_two, cp_checkbox_three // BASED ON THIS I WROTE THE FOLLOWING CODE-- BUT IT DOES NOT WORK AS A REPLACEMENT FOR A LINE // SUCH AS--- if (! isset($_POST['cp_checkbox_one'])) $_POST['cp_checkbox_one'] = array(); // function checkboxloop() { foreach($_POST as $meta_key => $meta_value) { if(cp_str_starts_with($meta_key, 'cp_checkbox')) { if (! isset($_POST[$meta_key])) $_POST[$meta_key] = array(); } } } // HERE I ASK FOR THE FUNCTION BUT WHILE I GET NO ERRORS I GET NO RESULTS // WHICH IS A PROPER SAVE OF UNCHECKED CHECKBOXES ON SUBMIT checkboxloop; I would very much appreciate knowing how to make the code keep looping whatever $meta_key names turn up on this page and then use those names to write the complete lines as STATIC PHP so that the IF conditions don't get "processed" while this function is called. In effect, I want to duplicate the effect of having the code lines WRITTEN, so that they perform exactly as if I had written them as PHP hard-code, as many lines as there will be $meta_keys, but not SEE the code--- just have it valid PHP. This function does NOT make the same thing happen internally. As soon as I replace the function with the HARD CODE PHP then it works...but, I have reached the stage where these lines of code have to happen dynamically. I am baffled how to get this to happen! If I use Echo then I get errors about the "IF". Thank you very much for your help! I am getting the following error when using composer: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? Just started. I am pretty sure composer.json wasn't changed. journalctl doesn't show anything. Maybe Doctrine related, however, nothing seems to help.
Any ideas? [michael@devserver www]$ php -v PHP 7.3.4 (cli) (built: Apr 2 2019 13:48:50) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.4, Copyright (c) 1998-2018 Zend Technologies with DBG v9.1.9, (C) 2000,2018, by Dmitri Dmitrienko [michael@devserver www]$ composer -V Composer version 1.4.2 2017-05-17 08:17:52 [michael@devserver www]$ yum info composer Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror.us.oneandone.net * epel: mirror.rnet.missouri.edu * extras: mirror.us.oneandone.net * remi-php73: mirror.bebout.net * remi-safe: mirror.bebout.net * updates: mirror.us.oneandone.net Installed Packages Name : composer Arch : noarch Version : 1.8.4 Release : 1.el7 Size : 1.8 M Repo : installed From repo : epel Summary : Dependency Manager for PHP URL : https://getcomposer.org/ License : MIT Description : Composer helps you declare, manage and install dependencies of PHP projects, : ensuring you have the right stack everywhere. : : Documentation: https://getcomposer.org/doc/ [michael@devserver www]$ composer update Loading composer repositories with package information Updating dependencies (including require-dev) [ErrorException] "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [-i|--interactive] [--root-reqs] [--] [<packages>]... [michael@devserver www]$
This topic has been moved to Linux. http://www.phpfreaks.com/forums/index.php?topic=318175.0 I'm getting an invalid argument error for my While loop. I can't figure out why. Code: [Select] $sql="SELECT * FROM schools ORDER BY class DESC,sectional ASC,team ASC"; $results = mysql_query($sql); while ($team = mysql_fetch_assoc($results)) { echo $team['school'] . '<br>'; } Here is the error: Quote Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/******/public_html/hoosierhoopsmagazine.com/resources/sectional_assignments.php on line 7 I'm trying to send a submission to the following Craigslist form that uses javascript to trigger an auto submit. The user selects "For Sale" on my form and it will pass the data in a hidden div to the proper selection on the craigslist page. Heres the page it would be passing to. I know I will have to pass it in the URL. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <base href="https://post.craigslist.org"> <title>houston craigslist | choose type</title> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <link type="text/css" rel="stylesheet" media="all" href="/styles/craigslist.css?v=9"> </head> <body id="pp"> <table width="100%" id="header" summary="header"> <tr valign="top"> <td><a href="http://houston.craigslist.org/"><b>houston craigslist</b></a> > choose type<br></td> <td width="10%" class="highlight" style="text-align: right; white-space: nowrap;"> <font size="2" face="sans-serif" color="#7a7a7a">[ logged in as <a href="https://accounts.craigslist.org/login"><b>kennymahaffey@gmail.com</b></a> ] [ <a href="https://accounts.craigslist.org/logout">logout</a> ]</font> <br></td> </tr> </table> <hr> <blockquote> <div class="highlight"> <i>Please post to a single geographic area and category only -- cross-posting to multiple cities or categories is not allowed</i> </div> <h4>What type of posting is this:</h4> <form action="https://post.craigslist.org/k/kInfxI4M4RGIA7PWTF5SWg/HjdlJ" method="POST"> <blockquote> <label> <input type="radio" name="id" value="jo" onclick="form.submit(); return false;">job offered </label> <br> <label> <input type="radio" name="id" value="jw" onclick="form.submit(); return false;">resume / job wanted </label> <br> <br> <label> <input type="radio" name="id" value="ho" onclick="form.submit(); return false;">housing offered </label> <br> <label> <input type="radio" name="id" value="hw" onclick="form.submit(); return false;">housing wanted </label> <br> <br> <label> <input type="radio" name="id" value="fs" onclick="form.submit(); return false;">for sale </label> <i>(please do not post prohibited <sup><a target="_blank" href="http://www.craigslist.org/about/prohibited.items">[?]</a></sup> or recalled <sup><a target="_blank" href="http://www.craigslist.org/about/recalled_items">[?]</a></sup> items)</i> <br> <label> <input type="radio" name="id" value="iw" onclick="form.submit(); return false;">item wanted </label> <br> <br> <label> <input type="radio" name="id" value="go" onclick="form.submit(); return false;">gig offered </label> <i>(I'm hiring for a short-term, small or odd job)</i> <br> <label> <input type="radio" name="id" value="so" onclick="form.submit(); return false;">service offered </label> <br> <br> <label> <input type="radio" name="id" value="p" onclick="form.submit(); return false;">personal / romance </label> <br> <br> <label> <input type="radio" name="id" value="c" onclick="form.submit(); return false;">community </label> <br> <label> <input type="radio" name="id" value="e" onclick="form.submit(); return false;">event </label> <br> <br> </blockquote> <input type="hidden" name="U2FsdGVkX:18yNDg2NDI0O:A8dZroeLa8K5Y677RwK4hzBe2OPdD3XxLUDb5lS9LllELhxNpMqXZIwAWDxJ.7Wo4A" value="U2FsdGVkX18yNDg2NDI0OFjS1qgWn_NKgmgnh5qCZ9aK2m7eOmS-uAAM_Pwu8VHN"> <button type="submit" name="go" value="Continue">Continue</button> </form> </blockquote> I get the following error when I try to pass a value to a methiod in a loop: Warning: Attempt to assign property of non-object in /Users/staceyschaller/Sites/dev_zone/ckwv2/classes/class.php on line 670 This one has me very baffled. It will work the first time, and seems to work every other time, so I have no clue what is wrong. Here is the code: This code is part of my "display" class: function display_partner ($type,$loc,$rand=0,$narrow=0) { $this->partners = new partner($this->cxn); $display = ' <div id="cont_info" class="partner-list"> <div> <h3 class="settings">'.ucfirst($loc).' '.ucfirst($type).last_letter($type).'s</h3> </div> <div class="settings-value" style="height:12px;padding:0;margin:0;text-align:right;padding-right:10px;"> <a href="" class="trunc">Add your organization to this list</a></p> </div> <div style="height:2px;padding:0;margin:0;"> <hr class="account" /> </div> '; $ids = $this->partners->get_partners_list($type,$loc,$rand); for ($b=0;$b<sizeof($ids->id);$b++) { $this->partnerID = $ids->id[$b]; $display .= ($narrow)? $this->card_partner_narr():$this->card_partner(); if ($b!=(sizeof($ids->id)-1)) { $display .= '<hr class="account" />'; } } if (sizeof($ids->id)==0) { $display .= '<div style="color:#999999;display:line;text-align:center;height:20px;">No Partners found for '.ucfirst($loc).' '.ucfirst($type).'</div>'; } $display .= ' </div>'; return $display; } function card_partner () { $this->partners->set_partner_id($this->partnerID); $part_info = $this->partners->get_partner_info(); if ($part_info) { $display .= ' <table class="settings"> <tr> '.$this->show_if($part_info['partLogo']['val'],'<td class="settings-value" rowspan="2"><img src="'.LOGO_FOLDER.$part_info['partLogo']['val'].'" '.resize_img(LOGO_FOLDER.$part_info['partLogo']['val'],175).'alt="'.$part_info['partName']['val'].'" /></td>').' <td class="settings-value" colspan="2"><h5>'.$part_info['partName']['val'].'</h5></td> </tr> <tr> <td class="settings-value"> <span style="color:999999;">'.$part_info['partAddress']['val'].'<br /> '.$part_info['partCity']['val'].', '.$part_info['partST']['val'].' '.$part_info['partZIP']['val'].'<br /> '.$part_info['partPhone']['val'].'</span><br /> <a href="'.$this->form->show_href($part_info['partWeb']['val']).'" target="_blank">'.$part_info['partWeb']['val'].'</a> </td> <td class="settings-value">'.$part_info['partInfo']['val'].'</td> </tr> </table> '; } return $display; } This code is part of my "partners" class: function set_partner_id($partID) { echo '<p>partID: '.$partID.' '.gettype($partID).'<br> $this->partner->id: '.$this->partner->id.'</p>'; $this->partner->id = $partID; ///*** ERROR HAPPENS HERE ***/ echo '<p>id set: '.$this->partner->id.'<br> $this->partner->id: '.$this->partner->id.'</p><hr>'; } function get_partner_id() { return $this->partner->id; } // gets user info at login function get_partner_info() { $this->partner = $this->cxn->proc_info('partner','partID',$this->partner->id);//$this->partner->id return $this->partner; } The following is the output generated: partID: 24 string $this->partner->id: id set: 24 $this->partner->id: 24 partID: 26 string $this->partner->id: Warning: Attempt to assign property of non-object in /Users/staceyschaller/Sites/dev_zone/ckwv2/classes/class.php on line 670 id set: $this->partner->id: partID: 17 string $this->partner->id: id set: 17 $this->partner->id: 17 partID: 25 string $this->partner->id: Warning: Attempt to assign property of non-object in /Users/staceyschaller/Sites/dev_zone/ckwv2/classes/class.php on line 670 id set: $this->partner->id: As you can see, the value passes to $this->set_partner_id($partID) each time. It is formatted as a string. When it assigns the value to $this->partner->id, however, sometimes it works, and sometimes it doesn't. It's probably something obvious, but I've racked my brain to see what it is. Any ideas? |