PHP - Problem Assigning A Block Of Html/css With A Foreach Function To A Variable?
hey guys,
I'm quite new to PHP and i was wondering if someone would be able to help me out with this. The code i have checks the database to see if a user has provided a Vimeo ID. If they haven't, $video_check will equal a line of html that says the user hasn't added any videos to their portfolio. If the a vimeo ID is present, i want $video_check to equal a bunch of html and css with a foreach function inside that is used to display the users videos from vimeo. The foreach function works fine when its not assigned to the $video_check variable. How do i structure it so that it displays correctly? If you click on videos on this page you might get a better idea of what i'm talking about. http://www.myfilmportfolio.ie/profile.php?id=33 and here is the code i'm having the problem with: /////// check if user has provided vimeo id ////////////////////////// $vimeoID = $row["vimeoID"]; $video_check=''; if (empty($vimeoID)){ $video_check = '<h3>'.$firstname .' has not added any videos to their portfolio</h3>'; } else{ $video_check = '<div id="stats"> <div style="clear: both;"></div> </div> <div id="wrapper"> <div id="embed"></div> <div id="thumbs"> <ul> <?php foreach ($videos->video as $video): ?> <li> <h4><?=$video->title?></h4> <a href="<?php echo $video->url ?>"> <img src="<?php echo $video->thumbnail_medium ?>" class="thumb" /></a> <p><?=$video->description?></p> <br /> </li> <?php endforeach ?> </ul> </div> </div>'; } if anyone could help me out id really appreciate it. Cheers, G Similar TutorialsAlright the issue that I am having is that I need to get multiple lines into a variable to output later in the code. my $pieces variable is not returning anything, much less missing parts of it, but even the text code is not returning.
foreach($packages as $pack) { $weight+=$pack->weight; $items_no++; $singleweight=$pack->weight; $length=$pack->length; $height=$pack->height; $width=$pack->width; $pieces .= '<piece actual_weight="'.$singleweight.'" length="'.$length.'" height="'.$height.'" width="'.$width.'">'; } if(!empty($post_code) && $weight>0 && $items_no>0) { $data='?shipment='.urlencode('<shipment weight_system="IMPERIAL" shipper_number="'.$this->shipper_number.'" destination_postal_code="'.$post_code.'" service_type="'.$service.'">'.$pieces.'</shipment>').'&token='.$this->token; // $woocommerce->add_message('Items No:'.$items_no.'- Postalcode:'.$post_code.'- '); $resp=file_get_contents($this->canpar_url.$data,false,$context);If I do this in another method that only requires a single line (getting the total weight and number of items) it works fine, but this does not return the proper shipping cost for low weight items. On a site where higher weight items is shipped the plugin works fine. However I need to modify it to work based on dimensions. The result I am looking for is something like this: https://www.canpar.com/XML/RatingXML.jsp?shipment= <shipment weight_system="IMPERIAL" shipper_number="42500047" destination_postal_code="M1M1M1" service_type="1"> <piece actual_wieght="7" length="24" height="24" width="24"/> <piece actual_wieght="5" length="10" height="12" width="14"/> </shipment> &token=WZHBRS4KQYNAusing an output system I can output weight, packs, length, width, height but it does not return anything for $pieces and obviously shipping costs because I am getting an invalid xml response. $woocommerce->add_message('Weight: '.$weight.' Packs: '.$items_no.' Shipping cost : '.$atts['total_charge'].' Pieces: '.$item_box.' Length: '.$length.' Width: '.$width.' Height: '.$height); I wonder whether someone can help me please. I've put together the script below, which allows users to view their saved images in the original folder structure that they were saved in. Code: [Select] <?php session_start(); $_SESSION['username']=$_POST['username']; $_SESSION['locationid']=$_POST['locationid']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <?php $galleryPath = 'UploadedFiles/' . $_SESSION['username'] . '/' . $_SESSION['locationid'] . '/'; $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR; $descriptions = new DOMDocument('1.0'); $descriptions->load($absGalleryPath . 'files.xml'); $items = array(); for ($i = 0; $i < $descriptions->documentElement->childNodes->length; $i++) { $xmlFile = $descriptions->documentElement->childNodes->item($i); $path = $xmlFile->getAttribute('name'); $path = explode('/', $path); $t = &$items; for ($j = 0; $j < count($path); $j++) { if (empty($t[$path[$j]])) { $t[$path[$j]] = array(); } $t = &$t[$path[$j]]; } $t['/src/'] = $xmlFile->getAttribute('source'); $t['description'] = $xmlFile->getAttribute('description'); $t['size'] = $xmlFile->getAttribute('size'); } $basePath = empty($_GET['path']) ? '' : $_GET['path']; if ($basePath) { $basePath = explode('/', $basePath); for ($j = 0; $j < count($basePath); $j++) { $items = &$items[$basePath[$j]]; } } $files = array(); $dirs = array(); function urlpartencode(&$item, $index) { $item = rawurlencode($item); } foreach ($items as $key => $value) { if (isset($value['/src/'])) { $value['/src/'] = explode('/', $value['/src/']); array_walk($value['/src/'], 'urlpartencode'); $value['/src/'] = implode('/', $value['/src/']); $files[] = array( 'name' => $key, 'src' => $value['/src/'], 'description' => htmlentities($value['description'], ENT_COMPAT, 'UTF-8'), 'size' => htmlentities($value['size'], ENT_COMPAT, 'UTF-8') ); } else { $dirs[] = $key; } } $basePath = empty($_GET['path']) ? '' : $_GET['path']; $up = dirname($basePath); if ($up == '.') { $up = ''; } sort($files); sort($dirs); ?> <head> <title>View Image Folders</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link href="Styles/style.css" rel="stylesheet" type="text/css" /> <script src="Libraries/jquery/jquery-1.4.3.min.js" type="text/javascript"></script> <style type="text/css"> <!-- .style1 { font-size: 14px; margin-top: 5px; margin-right: -50px; } --> </style> <body style="font-family: Calibri; color: #505050; margin-right: 160px; margin-left: -180px;"> <div align="right" class="style1"> <a href = "index.php" /> Add Images <a/> → <a href = "javascript:document.imagefolders.submit()"> View All Images </a> </div> <form id="imagefolders" name="imagefolders" class="page" action="gallery.php" method="post"> <div id="container"> </div> <div id="center"> <div class="aB"> <div class="aB-B"> <?php if ('Uploaded files' != $current['title']) :?> <?php endif;?> <div class="demo"> <input name="username" type="hidden" id="username" value="IRHM73" /> <input name="locationid" type="hidden" id="locationid" value="1" /> <div class="inner"> <div class="container"> <div class="gallery"> <table class="gallery-link-table" cellpadding="0" cellspacing="0"> <thead> <tr class="head"> <th class="col-name"> Name </th> <th class="col-size"> Size </th> <th class="col-description"> Description </th> </tr> </thead> <tbody> <tr class="directory odd"> <td class="col-name"> <a href="?path=<?php echo rawurlencode($up); ?>">..</a> </td> <td class="col-size"> </td> <td class="col-description"> </td> </tr> <?php $i = 1; ?> <?php foreach ($dirs as $dir) : ?> <tr class="directory <?php $i++; echo ($i % 2 == 0 ? 'even' : 'odd'); ?>"> <td><a href="?path=<?php echo rawurlencode(($basePath ? $basePath . '/' : '') . $dir); ?>"><?php echo htmlentities($dir, ENT_COMPAT, 'UTF-8'); ?></a></td> <td>Folder</td> <td></td> </tr> <?php endforeach; ?> <?php foreach ($files as $file) : ?> <tr class="<?php $i++; echo ($i % 2 == 0 ? 'even' : 'odd'); ?>"> <td><a target="_blank" href="<?php echo $galleryPath . $file['src']; ?>"><?php echo htmlentities($file['name'], ENT_COMPAT, 'UTF-8'); ?></a></td> <td><?php echo htmlentities($file['size'], ENT_COMPAT, 'UTF-8'); ?></td> <td><?php echo htmlentities($file['description'], ENT_COMPAT, 'UTF-8'); ?></td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> </div> </div> </div> </div> </form> </body> </html> I can create the list of correct folders for the user and location, but when I click the folder name to drill down to the indvidual images I receive the following error: Quote Warning: DOMDocument::load() [domdocument.load]: I/O warning : failed to load external entity "/homepages/2/d333603417/htdocs/development/UploadedFiles/files.xml" in /homepages/2/d333603417/htdocs/development/imagefolders.php on line 17 Warning: Invalid argument supplied for foreach() in /homepages/2/d333603417/htdocs/development/imagefolders.php on line 54 Line 17 is this line: Quote $descriptions->load($absGalleryPath . 'files.xml') and line 54 is: Quote foreach ($items as $key => $value) { I know that in their own right, the piece of code which loads 'files.xml' and the code which loads the folders and images work, but it's combining them that creates the issue. I've done some research online, and I think the issue is to do with 'Session' variables and the 'foreach' array, but I'm not sure how to solve the problem. I just wondered whether someone could perhaps have a look at this please and let me know where I'm going wrong. Many thanks and regards hi there, i'm trying to put a message in the footer of a page which welcomes a person who is logged in with his/her name, using sessions of course; when i place this: Code: [Select] $username = $_SESSION['valid_user']; in the footer before the echo: Code: [Select] echo "You are logged in as $username"; but the session is also needed before the footer to use the username for other things , such as -checking his credit- so if place in footer the footer shows name in browser but checking credit would not happen as the assignment is at the buttom. IF i place the assignment above at the top of the file: everything works for the user and checking credit ..etc...but the footer is not there... cud not put this any clearer..sorry...hope if someone cud help...thanks Hi all, I can't seem to designate an array key by using a variable and I was wondering if this is possible. I'm looking to do something like this: Code: [Select] <?php $key = "apple"; $arr = array($key => "fruit"); ?> Any suggestions would be appreciated! hi, i am updating records from database using ajax and javascript on php page. The result is displayed inside a div (<div id="show"></div>). Now i want to assign the content of the above div(say y) to php variable for further calculations. How can i assign the value displayed in div tag to a php variable? Thanks. Hi folks, I was wondering how to do this. I want the if statement to detect if the query string has any of these values. so im trying to assign them all to the same variable. However, this code wont work. Whats the trick here? <?php $primary=$_GET['intro']; $primary=$_GET['port']; $primary=$_GET['about']; $primary=$_GET['contact']; if(isset($primary)){ echo "<img src='graphics/left-a.png'>";} else {echo "<img src='graphics/leftb.png'>";}?> Hi, I have just started creating my first class in php. I'm trying to assign $_SERVER['REMOTE_ADDR']; to a protected variable but I keep getting an error message. I'm still trying to get my head around oop php. My current code is "protected $user_ip = $_SERVER['REMOTE_ADDR'];" and the error message is "Parse error: syntax error, unexpected T_VARIABLE". Hello, I am creating a class which contains one private function that deals with connecting to a SQL Server and executing the sql that is passed in to that function. I have defined a class variable which is assigned the value of sqlsrv_query like so. $this->QueryResult = sqlsrv_query($conn,$sql); I have placed private $QueryResult at the top of my class. The other public methods call this private function to assign the result set to the class variable, the private method returns and then the public methods loop through the results array like so. while($row = sqlsrv_fetch_array($this->QueryResult)) .. but the while loop never gets entered. If I declare everything in the same method then it works, however there are going to be several public methods that will use this private method and I don't want to duplicate all the database coding. Hope someone can help Hello Everyone, I am new to forum and could use some help with some php code that isn't working. I am very new to php/html/javascript and all of what I have learned, I learned from forums like this one so first....thank you! I am trying to assign a value from a php variable to the value of my form element. I'm sure there must be a way to do this but I can't seem to get the syntax right. here is my code... first I set the value of $loginname elsewhere in the script like so... <?php $loginname =strtolower(htmlspecialchars(strip_tags($_GET["loginname"]))); ?> This part works fine.. Then I try to set the value of my hidden text field inside the form to the value of $loginname to be passed to a javascript program. Everything works except that the value passed ends up being <?echo and not the expected user name inside of $loginname. <?php echo '<form name ="currentactivity" Id="currentactivity" action="<?php'.htmlspecialchars($_SERVER['PHP_SELF']).'?>" method="post">'; echo '<fieldset><legend><b>Your Current Activity Information</b></legend>'; echo '<input type="text" name="loginnm" style="visibility: hidden" value="<?php echo $loginname;?>">'; echo "<label for='myactivities'>Activity Name:</label>"; echo "<select name='myactivities' Id='myactivities' onchange=\"showdetails(this.form)\" value=''>"; echo "<option value = 'Select an activity'>Select an activity</option>"; for ($i = 1; $i <=$rowcount; $i++) { echo"<option value=$row[activity_name]>$row[activity_name] </option>"; $row = mysql_fetch_array($result); } echo "</select>"; echo '</fieldset>'; echo '</form>'; ?> Please note..the rest of the code is working perfectly, it is just this one value I can't seem to get. Any help you can give will be greatly appreciated. Okay, really newbie question, but for this code... Code: [Select] <!-- Gender --> <label for="gender">Gender:</label> <select id="gender" name="gender"> <option value="">--</option> <option value="F">Female</option> <option value="M">Male</option> </select> 1.) How do I assign a variable to this? 2.) How do I make this "sticky"? Here is how I have usually done other form types... Code: [Select] <!-- First Name --> <label for="firstName">First Name:</label> <input id="firstName" name="firstName" type="text" maxlength="30" value="<?php if(isset($firstName)){echo htmlentities($firstName, ENT_QUOTES);} ?>" /><!-- Sticky Field --> <?php if (!empty($errors['firstName'])){ echo '<span class="error">' . $errors['firstName'] . '</span>'; } ?> Oh, by the way, at the top of my PHP file I have this code... Code: [Select] if ($_SERVER['REQUEST_METHOD']=='POST'){ // Form was Submitted (Post). // Initialize Errors Array. $errors = array(); // Trim all form data. $trimmed = array_map('trim', $_POST); Thanks, Debbie I am facing problem to execute query by assigning NULL value to a variable and then executing query.In MySQL DB four fields Mobile,landline, pincode,dob are set as integer and date(for dob) respectively.The default is set as NULL and NULL option is selected as yes.All these fields are not mandatory.The problem is that when I edit the form my keeping the value as empty in DB these are saved as 0, 0 , 0 & 0000-00-00 inspite of Null. I have tried everything but still the defect persist. Please help me to come out of the problem The code, I have used: <?php //require_once 'includes/config.php'; $dbusername = $_POST['email']; $dbfirstname = $_POST['first_name']; $dblastname = $_POST['last_name']; //$dbmobile_number = $_POST['mobile']; if (isset($_POST['mobile'])) { $dbmobile_number = $_POST['mobile']; } else { $dbmobile_number = "NULL"; } $dblandline_number = $_POST['landline']; $dbdob = $_POST['dob']; if(isset($_POST['is_email'])) { $dbSubscribe_Email_Alert = '1'; } else { $dbSubscribe_Email_Alert = '0'; } if(isset($_POST['is_sms'])) { $dbSubscribe_SMS = 0; } else { $dbSubscribe_SMS = 0; } $dbAddress_firstname = $_POST['shipping_first_name']; $dbAddress_lastname = $_POST['shipping_last_name']; $dbAddress = $_POST['shipping_address']; $dbcity = $_POST['shipping_city']; $dbpincode = $_POST['shipping_pincode']; $dbstate = $_POST['shipping_state']; $dbcountry = $_POST['shipping_country']; echo "Welcome".$dbusername; //if($_POST['btnSave']) //if ($_POST['btnSave']) //{ //echo "Inside query loop"; $connect = mysql_connect("localhost","root","") or die("Couldn't connect!"); mysql_select_db("salebees") or die ("Couldn't find DB"); //$query = mysql_query("SELECT * FROM users WHERE username='$username'"); $query = mysql_query("update users set firstname = '$dbfirstname', lastname = '$dblastname', mobile_number = '$dbmobile_number', landline_number = '$dblandline_number', dob = '$dbdob', Subscribe_Email_Alert = '$dbSubscribe_Email_Alert', Subscribe_SMS = '$dbSubscribe_SMS', Address_firstname = '$dbAddress_firstname', Address_lastname = '$dbAddress_lastname', Address = '$dbAddress', city = '$dbcity', pincode = '$dbpincode', state = '$dbstate', country = '$dbcountry' where username = '$dbusername' "); header("location:my_account.php"); //} //else //{ //die(); //} ?> I have two tables in my MySQL database: 1. user user_id | firstname | lastname | nickname etc. and 2. con (for contribution) con_id | user_id (foreign key) | name | contribution | category etc. Here's how I wanted to solve the problem of assigning the foreign key to the 2nd table (I'm a beginner so bear with me. ) When logging in, I assigned the user_id to the session variable like this: // do the while loop while ($assoc = mysqli_fetch_assoc($rows)) { // assign database COLUMNS to the variables $dbuser_id = $assoc['user_id']; $dbuser_name = $assoc['nickname']; $dbuser_password = $assoc['password']; etc..................... // set a session after login $_SESSION['user'] = $dbuser_name . $dbuser_id; This prints out the user_id just like I wanted to: echo "Your user_id is: " . $_SESSION['user_id'] = $dbuser_id; Gives: Code: [Select] Your user_id is: 35 ... and this is how the assignment of the foreign key looks like WHILE posting the contribution: $user_id = $_SESSION['user'] = $dbuser_id; if (!empty($knuffix_name) && !empty($knuffix_category) && !empty($knuffix_contribution)) { // Write the data into the database $query = sprintf("INSERT INTO con (con_id, user_id, name, contribution, category, contributed_date) VALUES (' ', '$user_id', '%s', '%s', '%s', now())", mysqli_real_escape_string($dbc, $knuffix_name), mysqli_real_escape_string($dbc, $knuffix_contribution), mysqli_real_escape_string($dbc, $knuffix_category)); When I now do a contribution through the input areas, nothing gets inserted into the database and I automatically get logged out. Obviously it's not working as I thought it would and I'd like to know why is that? Notice that if I take the user_id part OUT, it's working again, so the rest of the code must be right then. Another question I have is: Is this common practice to solve this problem of assigning a foreign key, or is there a better way of doing it? 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? Guys/Gals; This below block outputs a very simple progress bar, i'm curious if anyone would see a solution to perform a task when this bar reaches the end as you can see it's set to countinue until width<400 when that 400 is true I and in essence the process is done (even though nothing in reality) i want to display countinue but only when it's done echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' bgcolor='#666666'><tr><td width='506' height='52' valign='top'><script type='text/javascript'>function progress(){if(document.images['bar'].width<400){document.images['bar'].width+=5;document.images['bar'].height=5; }else{clearInterval(ID);}}var ID;window.onload=function(){ID=setInterval('progress();',$cpuspeed);}</script><img src='images/white.gif' name='bar'/><br /><font color='#ffffff'>Cracking....</font></td></tr></table>"; any dideas This is more of a technical question that i could not find the answer to pn the php.net manual pages. take the folowing example code: foreach ($array as $key => $value){ $tempvariable = some_property_of($value); } unset($tempvariable); is that unset statement needed? Does PHP automatically destroy the variables once the foreach loop is left? Hello, i have the code below and i need to have all results in a variable as a string, inside the loop they are displayed how i want but outside will echo the last result. Thank You. Code: [Select] foreach($_POST as $key=>$value){ if (is_numeric($value)) { $valoare = "$value,"; } } echo $valoare; I've made this code for a very simple registration form practice:
//assign form variables $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $username = $_POST['username']; function clean_names($dirty_name) { strip_tags($dirty_name); str_replace(' ', '', $dirty_name); ucfirst(strtolower($dirty_name)); //return $dirty_name; } $names = array($firstname, $lastname, $username); if(isset($_POST['register_button'])) { // WHY IS THIS FUNC CALL NOT WORKING?? foreach($names as $name) { clean_names($name); } echo "First Name: " . $firstname . "<br>"; echo "Last Name: " . $lastname . "<br>"; echo "Username: " . $username . "<br>"; }
The values are returned but they haven't been put through the clean_names function. I think this is the right place to post this but please move if needed as this is my first time on this site. You can also contact me through AIM: MadLittleMods@gmail.com Okay so I have a multidimensional array that is giving me an error when I put it in a function: ERROR: Warning: Invalid argument supplied for foreach().. line 123 LINE 123: foreach ( $affiliates as $affiliate ) This does work when in one file test2.php which is attached to this post... Here is my whole function: // affiliate content function start: function affiliates_content() { global $context, $settings, $options, $scripturl, $txt; foreach ( $affiliates as $affiliate ) { echo ' <table> <tr> <td> <a href="',$affiliate[href],'"><img src="',$affiliate[image],'"></a> </td> <td> ',$affiliate[title],' <br> <small><a href="',$affiliate[href],'">',$affiliate[href],'</a></small> </td> </tr> </table> <br> '; } } // affiliate content function end Here is my whole array which is located on another file (subs.php - smf) // affiliates array for affiliates page $affiliates = array( array( "title" => "aff_blah1", "image" => "http://aff_blah1.net/images/aff_blah1.png", "href" => "http://aff_blah1.net/" ), array( "title" => "aff_blah2", "image" => "http://aff_blah2.net/images/aff_blah2.png", "href" => "http://aff_blah2.net/" ), array( "title" => "aff_blah3", "image" => "http://aff_blah3.net/images/aff_blah3.png", "href" => "http://aff_blah3.net/" ), ); // affiliates array end Does anyone know how to fix this problem? ok. say i have a list with a foreach loop in it. like this: Code: [Select] echo' <ul>'; $link = Link::find_all(); foreach($link as $links){ $name = $links->name; echo' <li>'.$name.'</li>'; } echo' </ul>'; now. say that i want to put this part : Code: [Select] $link = Link::find_all(); foreach($link as $links){ $name = $links->name; into a function so i can reuse the code... like this: FUNCTION Code: [Select] function(find_li){ $link = Link::find_all(); foreach($link as $links){ $name = $links->name; } Code: [Select] echo' <ul>'; find_li(); echo' <li>'.$name.'</li>'; } echo' </ul>'; the problem is the foreach } its not inside the function so the function will not work. but it needs to be after the </li> so that i get all the results in the <li> so is there a way to put the function before the <li> and the } after the </li> |