PHP - Array Print
Probably a simple solution, just one I'm not sure how to do it.
I need the array to print out like this Code: [Select] array( 'name'=>'Store 1', 'address'=>'LA1' ), Right now, I got it to look like this Thanks in advance Code: [Select] Array ( [name] => 'Albertville Farmers Market', [address] => '116 Main Street Albertville, Alabama 35950' ) , Array ( [name] => 'Alexander City Downtown Market', [address] => 'Braod Street Alexander City, Alabama 35010' ) , How can I go about accomplishing this? Here is my code Code: [Select] $stores = array('name'=>"'$MktName',",'address'=>"'$address'"); echo "<pre>"; print_r($stores); echo "</pre>"; Similar TutorialsHi all This is probably the easiest question ever , but I am not familiar with arrays , so hope somebody can help me User post this checkbox form (array): <input type="checkbox" name="type[0][]" value="1" > <input type="checkbox" name="type[0][]" value="2" > <input type="checkbox" name="type[0][]" value="3" > I need to get all checked values and print them ... How can I do this? I tried the code below, but it only returns me one value Code: [Select] $values = array($_POST["type"]); foreach ($values as $item){ echo $item; } Any help??? Thanks!! What I'm trying to achieve is to get a set of data from a database and then cycle through the array and add the contents of each row to a variable. I'm trying to use $i to cycle through the array but at the moment it's just printing the first character of each set. Any help would be great. $fav_products_sql = "select fav_products.product_id, fav_products.product_order, product_list.product_name from fav_products, product_list where fav_products.product_id = product_list.id"; $fav_products_rs = mysql_query($fav_products_sql, $conn); $fav_products = mysql_fetch_array ($fav_products_rs); while ($i < 11) { $_SESSION['fav_products'] = "<li>" . $fav_products['product_order']['$i'] . ": " . $fav_products['product_name']['$i'] . "</li>"; $i++; } You can ignore my previous thread: Xpath help. I made it needlessly complicated! Here's my problem: My array $selected contains: Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [buildingName] => EiffelTower [code] => lM [type] => building ) [requiredLevel] => 5 [cost] => 5000 [built] => 03/31/1889 [storageType => SimpleXMLElement Object ( [@attributes] => Array ( [itemClass] => EiffelTower_construct ) ) [defaultItem] => SimpleXMLElement Object ( [@attributes] => Array ( [amount] => 1 [name] => iron ) ) [finishedReward] => iron [image] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [loadClass] => mc [name] => construct_0 [url] => /buildings/eiffel_tower.swf ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [loadClass] => mc [name] => construct_1 [url] => /buildings/eiffel_tower.swf ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [loadClass] => mc [name] => built_0 [url] => /buildings/eiffel_tower.swf ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => icon [url] => buildings/eiffel_tower.png ) ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => startIcon [url] => /buildings/eiffel_tower.png ) ) [5] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => halfIcon [url] => /buildings/eiffel_tower.png ) ) [6] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => completeIcon [url] => /buildings/eiffel_tower.png ) ) ) [constructionUI] => /buildings/Construct_eiffel_tower.swf [countryCard] => france ) ) I have the following code: echo "<td>".$selected[0]['name']."</td>"; echo "<td>".$selected[0]['code']."</td>"; echo "<td>".$selected[0]['type']."</td>"; echo "<td>".$selected['requiredLevel']."</td>"; This line of that code does not work: echo "<td>".$selected['requiredLevel']."</td>"; I've tried: echo "<td>".$selected[0]['requiredLevel']."</td>"; which also does not work. Can anyone help me figure out why?[/code] If I wanted to print a string that contains a variable that also contains an array, how would I do so? I want to put the resulting echo into a log file. Example: “These are the books: $userArray and these are the pages: $pagesArray”; With just an array, I can use print_r($array, true) to get an array formatted for use in a string (which works well for my purposes) but this doesn’t work with two arrays unless I do this manually. (Such as setting the $user_array = print_r($userArray). But I want to write a function that will take a string, potentially containing arrays (as variables), and interpolate/make them legible for humans. (Some of the arrays are also multidimensional.) But it looks like I can't even concatenate a string and an array. $string = $string . $array. gives an error, array to string conversion. I don’t understand PHP very well so please explain what is going on here. and the best way to record something like the Example above. Dear all, Kindly help with this code I have written, it is not returning the array I created. It is a very small script but I have been looking for a very long time but I couldn't see why it went wrong. $duration = 2; $start='01-01-2019'; $month =date('n', strtotime($start)); $year =date('Y', strtotime($start)); $mon = 12-$month+1; $remainingMonth = $duration*12; $years_arr = array("$year"); $residue_arr = array("$remainingMonth"); $years_arr = process($remainingMonth,$year,$mon,$years_arr,$residue_arr); print_r($years_arr); //<output function process($remainingMonth,$year,$mon,$years_arr,$residue_arr){ $residue = $remainingMonth - $mon;//$D$18-D20 if($residue != 0){ $new_year = $year+1; array_push($years_arr, $new_year); array_push($residue_arr, $residue); if($residue > 12 ){ $mon = 12; } else { $mon = $residue; } echo "<br>"; process($residue,$new_year,$mon,$years_arr,$residue_arr); } else { print_r($years_arr); return $years_arr; } }//end of process(..) The objective is to add a year to the $years_arr array and then print it put, yet I notice that nothing get's printed out. Please assist, if you need more info from my side, please do ask. Thank you very much in advance. I am trying to break down an array to make it easier to read. An array that looks like Array (
=> 0 [1] => 0 [2] => 0 [3] => 0012844 1 [4] => 37 [5] => 1 etc...) I want to display it like:
Code: [Select] [0] => 0 [1] => 0 [2] => 0 etc... how can this be accomplished. Hi the above title explains it all.How to output a post array which has been given input using forms.I know you can do it my echo but what about print() Thanks Hello, Having a bit of a tough time understanding what is going on in my brain! I'm basically pulling some data from an API using CuRL, which is working fine. The structure of the data is: [data][tickets] - tickets being an array of support tickets in the system, which then contains ticketNumber, title, content. I want to display these values in a list, I have this code currently: if ($err) { echo "cURL Error #:" . $err; } else { $return = json_decode($response, true); foreach($return as $key) { echo $key["tickets"][1]['ticketNumber']." - "; echo $key["tickets"][1]['title']." - "; echo $key["tickets"][1]['content']; } } Which obviously returns the ticketNumber, title & content of the first support ticket in the array, but I want to loop through and display that information for each ticket! Can anyone advise as to where I am going wrong? I think I need to utilise the ["tickets"][x] but not sure how!
Thanks in advance! Steve [ Newbie Alert ] Hi i have an array of 39 arrays. Only 5 are shown below so that you have an idea before i ask my question. <? array(39) { [0]=> array(3) { [0]=> string(18) "unit name 1" [1]=> string(9) "category name 1" [2]=> string(20) "Course 1" } [1]=> array(3) { [0]=> string(54) "unit name 2" [1]=> string(15) "category name 2" [2]=> string(20) "Course 1" } [2]=> array(3) { [0]=> string(29) "unit name 3" [1]=> string(15) "category name 2" [2]=> string(20) "Course 1" } [3]=> array(3) { [0]=> string(64) "unit name 4" [1]=> string(30) "category name 3" [2]=> string(20) "Course 2" } [4]=> array(3) { [0]=> string(57) "unit name 5" [1]=> string(24) "category name 1" [2]=> string(20) "Course 1" } [5]=> array(3) { [0]=> string(50) "unit name 6" [1]=> string(24) "category name 4" [2]=> string(20) "Course 2" } } i want a php solution to print category names in table headers , unit names in table rows and course name(s) in table caption.I have tried foreach loop but how to remove duplicate entries as you can see category name 1 and 2 will become two separate headers instead of one and same is the case with Course 1 and 2. i have googled but could'nt find any solution. i don't want to remove duplicate entries , all i want to display them once in a table as described above. Hello, I am fairly new to PHP and I found some php code to print an array of numbers that create a combination - however, its slams all the numbers together without a space or a comma separator. How can I separate the numbers in this array with the given code? Ive attached a photo of the code.
Hello, How to customize print page in php ? I had a page, but I need to print it like an invoice look page. Thanks in advance Code: [Select] $query ="SELECT oneID FROM table WHERE table.PersonID = 'game.PlayerA'" ; $result = mysql_query($query); $row = mysql_fetch_array($result); $oneID = $row[0]; [code] If I then echo "$oneID" why does it not print anything? $result echos resource7 Hello.
i am totally new to php and just started to learn now. i just dont understand why the following code is not printing the username that i enter on the page.
Please note that the code itself is saved with the name "basicForm.php".
Thanks.
<html> This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=346728.0 Hi, I am trying to get the form field to echo a php variable. The problem is that the form is 'Printed' via php. print "<td width=\"300\" valign=\"top\"><input type=\"text\" name=\"usr\" value=\"i.e. JBloggs \" onfocus=\"if(!this._haschanged){this.value=''};this._haschanged=true;\" tabindex=\"1\"></td>"; Instead of the value being i.e. JBloggs have it echo the $name variable. Any input would be appreciated. I am trying to get the code at the bottom of the script to print just once during the loop but it either doesn't print at all or repeats with the loop im am using if (!$i++) to print once and i works the first time i use it. foreach($uploadFilename as $key => $myvar) { if (!$i++) print "<!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\"> <head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <title>Upload Complete....</title> </head> <body> <body onload=\"document.forms.formname.submit);\"> <form id=\"formname\" name=\"form1\" method=\"post\" action=\"reg5.php\">\n"; echo "<input type=\"hidden\" name=\"image$key\" value=\""; echo end(explode('/',$myvar)); echo "\">\n"; if (!$i++) print "</form> </body> </html>\n"; } Hello guys and gals, I am pretty green to PHP! I have an empty array that that I am trying to put images into. The thing is I have a certain file name in the folder, I want to exclude that file. This is what I have tried, any advice would be appreciated! Code: [Select] $thumbImg[] = array(); foreach (glob($DImg) as $PImg) { if (!is_file("thumbnail.jpg")) { $thumbImg[] = "<img src=\"pathtoimage\">"; } } Later on the page I am printing it out with this. It is still including the thumbnail.jpg image. Thank you in advance!! Code: [Select] for ($i=0; $i<count($thumbImg); $i++) print $thumbImg[$i]; Hi all this might be a bit of a novice question, but if anyone knows the following i would be pleased and my eyes will too I am looking for a way to print on paper or pdf (en print the pdf in the end) all the stringfunctions on php.net (http://www.php.net/manual/en/ref.strings.php) If anyone knows a way to do so i would love to hear it, because after a few days behind a computer my eyes are about to go on strike. Im trying to print several image url's and names from an sql database into 3 columns, Aiming to get it to go 1,2,3 4,5,6 7,8,9 etc etc. but for some reason myne is going 1,3,5 2,4,6 etc. Dont bother mentioning that my loops do nothing, i realised that about 10 minutes ago, Any help would be appreciated. <?php include 'config.php'; mysql_connect($host, $user, $pass) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); $result = mysql_query("SELECT * FROM tracks"); echo '<div id="left_wrapper">'; for ($i=0;$i<mysql_num_rows($result);$i+=3) { $row = mysql_fetch_array($result); $id = $row['id'] + 1; echo "<img src='Thumbnails/" . $id .".gif'></img><br>"; echo $row['name']. "<br>"; } echo "</div>"; echo '<div id="middle_wrapper">'; for ($i=1;$i<mysql_num_rows($result);$i+=3) { $row = mysql_fetch_array($result); $id = $row['id'] + 1; echo "<img src='Thumbnails/" . $id .".gif'></img><br>"; echo $row['name']. "<br>"; } echo "</div>"; echo '<div id="right_wrapper">'; for ($i=2;$i<mysql_num_rows($result);$i+=3) { $row = mysql_fetch_array($result); $id = $row['id'] + 1; echo "<img src='Thumbnails/" . $id .".gif'></img><br>"; echo $row['name']. "<br>"; } echo "</div>"; ?> i know each of those loops does nothing, But you can see where they are meant to do, Each div is aligned to different positions, first loop is left, 2nd is center, 3rd is right. |