PHP - Displaying Array Output In A Table
I have a function which finds a list of companies associated with a country from a custom taxonomy. It finds their logo and creates an output which is all logos associated with a country, and the logo has a href to link to a company page. The code for this is: function countryCompanies(){ global $post;
$echo = f_print(array(
The f_print function finds the logos, and their sizes. So the 'mainlogo' type is a pull down of the thumbnail at 200px size.
What I need to do is write CSS and PHP which will display these results in a grid, 4 colums across, and as many down as results from the array. At the moment all I can get is all the results in one column. What tutorials would I need to write appropriate CSS to create this, and then is it as simple as adding the div prior to the echo of the $echo variable? Thanks Similar TutorialsI have a script that is working apart from I can only get json to send 1 result instead of multiple. The values are being correctly processed and inserted into the db, apart from the echo $json. For example, a user will input 3 input elements in a form. item1.item2,item3, Jquery will serialize and then send to the php page using $.ajax. I have created a foreach loop to handle the post, but I can only get 1 result in the echo $json. I would be grateful if someone check my code and show me where I am going wrong?. Many thanks Code: [Select] <?php session_start(); $new = 1; $activity = 'Box Retrieval'; $mobile = 'Submitted from mobile'; $company = $_SESSION['idcode']; $authorised = mysql_real_escape_string($_POST['BRV_brtrvrb']); $service = mysql_real_escape_string($_POST['BRV-id-service-type']); $department = mysql_real_escape_string($_POST['BRV-brtrv-department']); $address = mysql_real_escape_string($_POST['BRV-brtrv-address']); $boxcount = mysql_real_escape_string($_POST['BRV-brtrv-slider']); foreach ($_POST['BRVbrtrv_boxnumber'] as $box) { header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" ); header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" ); header("Cache-Control: no-cache, must-revalidate" ); header("Pragma: no-cache" ); header("Content-type: application/json"); $json = ""; if(empty($service)) { $json .= "{\"ErrorService\": \"ERROR: You mest select a service level\"}"; } else if($department=="Choose Department") { $json .= "{\"ErrorService\": \"ERROR: You must select a department\"}"; } else if($address=="Choose Address") { $json .= "{\"ErrorService\": \"ERROR: You must select a retrieval address\"}"; } else if(empty($box)) { $json .= "{\"ErrorService\": \"ERROR: You must enter a box for retrieval\"}"; } else { $json .= "{\n"; $json .= "\"boxnumber\": \"".$box."\",\n"; $json .= "\"boxcount\": \"".$boxcount."\"\n"; $json .= "}\n"; $query = 'INSERT INTO `act` (`service`, `activity`, `department`, `company`, `address`, `user`, `item`, `destroydate`, `date`, `notes`, `new`) VALUES (\''.$service.'\', \''.$activity.'\', \''.$department.'\', \''.$company.'\', \''.$address.'\', \''.$authorised.'\', \''.strtoupper($box).'\', NULL, NOW(), \''.$mobile.'\', \''.$new.'\');'; mysql_query($query) or die('Error, query failed'); } } echo $json; ?> Hi Guys, I am a complete novice as you will soon notice. Can anyone suggest what I am doing wrong with this code. When I run the query in phpmyadmin it produces the correct answer. However when I try to output on my site with php it returns the result "Array". I am guessing I have oversimplified somewhere, aint got a clue how though Code: [Select] <?php include("configure.php"); // To grab the DB info $dbh = mysql_connect ("localhost", DB_SERVER_USERNAME, DB_SERVER_PASSWORD) or die ('<BR> - Could not connect to the database because: '.mysql_error()); mysql_select_db (DB_DATABASE, $dbh) or die(mysql_error( )); $query = "SELECT `options_values_price` FROM `rain_products_attributes` WHERE `products_id` = 526 AND `options_id` = 3 AND `options_values_id` = 3"; $result = mysql_query($query); if (!$result) { $message = "Error! Invalid Query: ".mysql_error()."\n Original Query: ".$query; die($message); } while($row = mysql_fetch_array($result)) { echo $row; } mysql_close(); ?> I'm writing a script to grab some info from a list of urls in the database, but it just continuously loads and doesn't display anything. Here's the script: <? $username="*****"; $password="*****"; $database="*****"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM dvds"; $result=mysql_query($query); $num=mysql_numrows($result); echo "<b><center>Database Output</center></b><br><br>"; $i=0; while ($i < $num) { $url=mysql_result($result,$i,"imdb_url"); echo "<b>Getting page: $url</b><br>"; //get the page content $imdb_content = get_data($url); //parse for movie details $name = get_match('/<title>(.*)<\/title>/isU',$imdb_content); $director = strip_tags(get_match('/<h5[^>]*>Director:<\/h5>(.*)<\/div>/isU',$imdb_content)); $plot = get_match('/<h5[^>]*>Plot:<\/h5>(.*)<\/div>/isU',$imdb_content); $release_date = get_match('/<h5[^>]*>Release Date:<\/h5>(.*)<\/div>/isU',$imdb_content); $mpaa = get_match('/<a href="\/mpaa">MPAA<\/a>:<\/h5>(.*)<\/div>/isU',$imdb_content); $run_time = get_match('/Runtime:<\/h5>(.*)<\/div>/isU',$imdb_content); //build content $content.= '<h2>Film</h2><p>'.$name.'</p>'; $content.= '<h2>Director</h2><p>'.$director.'</p>'; $content.= '<h2>Plot</h2><p>'.substr($plot,0,strpos($plot,'<a')).'</p>'; $content.= '<h2>Release Date</h2><p>'.substr($release_date,0,strpos($release_date,'<a')).'</p>'; $content.= '<h2>MPAA</h2><p>'.$mpaa.'</p>'; $content.= '<h2>Run Time</h2><p>'.$run_time.'</p>'; $content.= '<h2>Full Details</h2><p><a href="'.$url.'" rel="nofollow">'.$url.'</a></p>'; //display the content echo $content; $i++; } //gets the match content function get_match($regex,$content) { preg_match($regex,$content,$matches); return $matches[1]; } //gets the data from a URL function get_data($url) { $ch = curl_init(); $timeout = 5; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $data = curl_exec($ch); curl_close($ch); return $data; } ?> Hopefully someone better at php can tell me how to fix it! Thanks! Hi friends,
Another security issue but this time its regarding outputting data from a DB to a browser. Please have a look at the code below which displays some output fetched from a DB and sends it to a browser.
1. If I just wish to display this output on a screen and not provide the user with any buttons or hyperlinks to interact with the information, would I still need to sanitize the output before echoing it to the screen ?
2. If I was to make at least one of the fields a hyperlink, so that I could then display some related information on another webpage, what security concerns would I need to address in my code?
3. If I was to add a button against each of these records, on each row, and then select some related information on another webpage after processing the button handler, what would be the security concerns that I should address for the code below.
Thanks very much.
<table> <tr> <th> S.No. </th> <th> Name </th> <th> Age </th> <th> City </th> <th> Cell </th> <th> Email</th> </tr> <?php $cnt = 1; while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { echo "<tr>"; echo "<td>".$cnt++."</td>"; echo "<td>".$row['Name']. "</td>"; echo "<td>".$row['Age']. "</td>"; echo "<td>".$row['City']. "</td>"; echo "<td>".$row['Cell']. "</td>"; echo "<td>".$row['Email']. "</td>"; echo "</tr>"; } ?> </table> Hello all, I have yet again trouble finding a logical solution to my problem. I'm fetching an array which can hold 1 or more values. The problem is, I want these values to ouput in my json_encode function, but this also needs to happen dynamically depending on the amount of values. I can't explain it further, so here's the code so far: Code: (php) [Select] $files = mysql_fetch_array($get_files); $a = count($files); $i = 1; while ($files) { $variablename = 'fileName' . $i; $$variablename = $files['fileName']; $i++; } $output = array( OTHER VALUES , 'fileName1' => $fileName1, 'fileName2' => $fileName2, 'fileName3' => $fileName3, ............); // How do I add the fileNames dynamically depending on how many there are? This got me thinking, I also need to dynamically GET the values with jQuery. How would I do that, when the above eventually works? Thank you. Hello everyone. I need help with the following PHP APP. I am running on (Version PHP 7.2.10) I am trying to have a page table form on table.php pass the input variable of “5-Numbers” to another page called table_results.php I want that variable string of “5-Numbers” to be compared against 4 arrays and output any duplicates found within each of those 4 lists. If nothing is found, I still want some visual output that reads “None found”.
Lets pretend I have the following example .. On table.php, I typed inside my table form the 5-Numbers .. INPUT: 2,15,37,13,28 On table_results.php, the 4 arrays to be compared against my input numbers “ 2,15,37,13,28” are ..
$array_A = array(2,6,8,11,14,18,24); $array_B = array(1,2,9,10,13,14,25,28,); $array_C = array(1,3,7,9,13,15,20,21,24); $array_D = array(4,5,12,22,23,27,28,29);
So my output should read as follows below .. OUTPUT:
TABLE COLUMN 1 COLUMN 2 ROW 1 Matches Found Results .. ROW 2 GROUP A: 2 ROW 3 GROUP B: 2,13,28 ROW 4 GROUP ? 13,15 ROW 5 GROUP ? 28 ROW 6 5#s Input: 2,15,37,13,28
Please let me know if anyone has any suggestions on how to go about it. Thanks. Edited January 1, 2019 by Jayfromsandiego Wanted to include image example Hi all What I am trying to achieve is a for each loop for the following output Code: [Select] Array ( [result] => success [source] => getDirectory [success] => Array ( [0] => /root/mc/world/data/ [1] => /root/mc/world/level.dat [2] => /root/mc/world/level.dat_old [3] => /root/mc/world/players/ [4] => /root/mc/world/players/herghost.dat [5] => /root/mc/world/region/ [6] => /root/mc/world/region/r.-1.0.mcr [7] => /root/mc/world/region/r.0.0.mcr [8] => /root/mc/world/session.lock [9] => /root/mc/world/uid.dat ) ) How would I go about saving each path from the [success] output? Basically I wish to loop through the array and delete the files. Many Thanks I'm kind of a beginner, but I really need this script and I'm not sure how quite to do it as needed... With some html forms I need it so you can type a name in then click submit, then (with php) it will save that text into a text file or something. Later, when I hit a different button it will randomly display one of those texts/names from before. Hi,I
I'm trying to setup Paypal Pro on a website - have everything working - but need to grab the 4th & 6th key values from the results given from the Paypal response and having difficulty with the task.
See the code that prints the response and the response sent from Paypal below - I need to grab the values for [TRXRESULT] and [TRXRESPMSG]
echo('<pre>'); print_r($PayFlow->getResponse()); echo('</pre>');and here's the response I get from Paypal on script execution - this is an example of a failed transaction: Paypal Response Array ( [RESULT] => 36 [RPREF] => RPC5B24581A2 [RESPMSG] => Transaction failed: Fail to obtain approval for the online transaction [TRXRESULT] => 23 [TRXPNREF] => EUJPC36F2092 [TRXRESPMSG] => Invalid account number: Unsupported Credit Card type )Again, I want to grab the values from [TRXRESULT] and [TRXRESPMSG] and assign them to local variables so i can work with them within the local php script. Example: $trxresult and $trxrespmsg Here's part of the class (file name is Class.Payflow.php find on Github) that pertains to this snippet of code in question: Class.Payflow.php /** * @uses Gets the response from Paypal. * @access Public * @param None. * @return Array/String - Returns an array of Paypal's response or empty string if not return. * @example $PayFlow->getResponse(); */ public function getResponse() { if($this->response) { return $this->response; } else { return ''; } }Thanks in advance for help w/this one! Hi all I am having massive problems comparing the out put of array, basically my end result is to choose a selected option on a drop down in a form. I am trying to compare the output of ['allow-nether'] which is either true or false in my file. Here is what I have tried //code to get file contents Code: [Select] $file_handle = fopen("saves/server.properties", "rb"); $vars = array(); while (!feof($file_handle) ) { $line_of_text = fgets($file_handle); $parts = explode('=', $line_of_text); //if date not required if ( !isset($parts[1]) ) { continue; } $vars[$parts[0]] = $parts[1]; } Code: [Select] <?php //allow nether =false in file echo "1 " .$vars['allow-nether']; if ( $vars['allow-nether'] == true ) { echo '<br>2 selected="selected"';} if ( $vars['allow-nether'] == false ) { echo '<br>3 selected="selected"';} if ( $vars['allow-nether'] == "true" ) { echo '<br>4 selected="selected"';} if ( $vars['allow-nether'] == "false" ) { echo '<br>5 selected="selected"';} if ( $vars['allow-nether'] === true ) { echo '<br>6 selected="selected"';} if ( $vars['allow-nether'] === false ) { echo '<br>7 selected="selected"';} if ( $vars['allow-nether'] === "true" ) { echo '<br>8 selected="selected"';} if ( $vars['allow-nether'] === "false" ) { echo '<br>9 selected="selected"';} ?> which outputs: Code: [Select] 1 false 2 selected="selected" and if I set the file to allow-nether=true Code: [Select] <?php //allow nether =true in file echo "1 " .$vars['allow-nether']; if ( $vars['allow-nether'] == true ) { echo '<br>2 selected="selected"';} if ( $vars['allow-nether'] == false ) { echo '<br>3 selected="selected"';} if ( $vars['allow-nether'] == "true" ) { echo '<br>4 selected="selected"';} if ( $vars['allow-nether'] == "false" ) { echo '<br>5 selected="selected"';} if ( $vars['allow-nether'] === true ) { echo '<br>6 selected="selected"';} if ( $vars['allow-nether'] === false ) { echo '<br>7 selected="selected"';} if ( $vars['allow-nether'] === "true" ) { echo '<br>8 selected="selected"';} if ( $vars['allow-nether'] === "false" ) { echo '<br>9 selected="selected"';} ?> Gives: Code: [Select] 1 true 2 selected="selected" What am I doing wrong? I have an array and I would like to insert commas and the word 'and' to make a sentence using an array. For example... $sports = array(baseball, soccer, tennis); Ted played baseball, soccer and tennis or Ted played baseball, soccer, boxing and tennis What's the best way to do this? The below is outputting: Array Fatal error: Unsupported operand types in /home/zyquo/public_html/area51entertainment.co/maintenance/home.php on line 28 So clearly $project_row_num is coming out as an array, and the multiplication is failing because its got a string not a number. I just don't see why it's getting an array out of $project_row_num. <?php $num_projects=15; $scroller_projects=""; require_once 'db_select.php'; $project_query_num="SELECT COUNT(*) FROM $tbl_name"; $project_result_num=mysql_query($project_query_num); $project_row_num=mysql_fetch_assoc($project_result_num); echo $project_row_num; //if($project_row_num <= $num_projects){ $project_query="SELECT * FROM $tbl_name"; $project_result=mysql_query($project_query); /*} else{ $project_query="SELECT * FROM $tbl_name WHERE project_release_date BETWEEN $start_date AND $end_date LIMIT 0,$num_projects"; $project_result=mysql_query($project_query); }*/ $i=1; while($project_row=mysql_fetch_array($project_result)){ extract($project_row); $scroller_projects.='<div class="project_entry" tabindex="'.$i.'" onclick="sndReq(\''.$project_id.'\');">Test</div>'; $i++; } if($project_row_num==""){ $films_row_num=$num_projects; } $scroller_width=$project_row_num*114; $content=' <div class="video_scroller_wrapper"> <div class="video" id="tabs"> </div> <div class="recentfilms_wrapper"> <div class="left_arrow"><img src="arrow_left.png" alt="Left" title="" class="arrow_left" onclick="jumpLeft(\'recentfilms\')" onmouseover="startScrollLeft(\'recentfilms\')" onmouseout="stopScroll()" /></div> <div id="recentfilms"> <div id="scroller" style="width: '.$scroller_width.'px;"> '.$scroller_projects.' </div> </div> <div class="right_arrow"><img src="arrow_right.png" alt="Left" title="" class="arrow_right" onclick="jumpRight(\'recentfilms\')" onmouseover="startScrollRight(\'recentfilms\')" onmouseout="stopScroll()" /></div> </div> </div> <div class="news_wrapper"> <div class="news"> <div class="news_title"><span class="category_title_text">Latest News</span></div> <div class="news_text"> <iframe src="http://www.indiegogo.com/project/widget/75876?a=9030" style="width: 224px; height: 429px; position: relative; left: 3px; top: 15px; border: 0px; overflow: hidden;"></iframe> </div> </div> </div> '; ?> I came up with this but it outputs the value 3 times... (because there are 3 variables) ie mathsmathsmaths How do I fix this or do it the correct way? Thanks Code: [Select] $subject = "maths"; $phone = "1235"; $colour = "red"; $all_vars = compact("subject", "phone", "colour"); get_value($subject); function get_value($variable){ global $all_vars; foreach($all_vars as $key=>$value){ if ($key = $variable) { echo $key; } } } Hi, got a problem with my arrays, every string gets duplicated 11 times instead of just one time. How to fix this? Hi, Stuck again with the Joomla/K2 coding. Trying to output this field in a 2 column table but failing badly. Any help or ideas would be greatly appreciated. <?php if($this->item->params->get('catItemExtraFields') && count($this->item->extra_fields)): ?> <!-- Item extra fields --> <div class="catItemExtraFields"> <h4><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h4> <ul> <?php foreach ($this->item->extra_fields as $key=>$extraField): ?> <?php if($extraField->value): ?> <li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>"> <?php if ($extraField->name =='Closing date') : ?> <span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span> <span class="catItemDateCreated"><?php echo JHTML::_('date', $this->item->publish_down ); ?></span> <?php else :?> <span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span> <span class="catItemExtraFieldsValue"><?php echo $extraField->value; ?></span> <?php endif; ?> </li> <?php endif; ?> <?php endforeach; ?> </ul> <div class="clr"></div> </div> <?php endif; ?> Hi Guys, I have a query and a while loop output that I am sending to a webpage in a table format but I need some help in how best to do this so that the table columns line up with each other. Right now the column width seems to change depending on the data in the row. The code is quite simple: <?php include("lib/config.php"); $query = "SELECT * FROM staff_member"; $result = mysql_query($query); ?> <html> <style type="text/css"> <!-- @import url(style/style.css); --> </style> <head> </head> <body> <h2 align="center"> Full Staff list with Dependants</font></h2> <?php while($row = mysql_fetch_object($result)) { echo "<table id=sample> <th>Title</th> <th>First Name</th> <th>Initial</th> <th>Last</th> <th>Agency</th> <th>Street</th> <th>Address</th> <th>Parish</th> <th>Country</th> <th>Office Tel#</th> <th>Home Tel#</th> <th>Office Mobile#</th> <th>Personal Mobile#</th> <th>Zone</th> <th>Status</th> <th>Location</th> <th>Updated by</th> <tr> <td>" .$row->title ."</td> <td>" .$row->first ."</td> <td>" .$row->initial ."</td> <td>" .$row->last ."</td> <td>" .$row->agency ."</td> <td>" .$row->street ."</td> <td>" .$row->adress ."</td> <td>" .$row->parish ."</td> <td>" .$row->country ."</td> <td>" .$row->officetel ."</td> <td>" .$row->hometel ."</td> <td>" .$row->officemobile ."</td> <td>" .$row->personalmobile ."</td> <td>" .$row->zone ."</td> <td>" .$row->status ."</td> <td>" .$row->location ."</td> <td>" .$row->updater ."</td> </tr>"; echo "</table> </br>"; }//close $row while ?> </body> </html> Any help appreciated! Hi, I need a quick tip. I want this script to produce an output of "Table created" if it succesfully creates a table. <?php $con = mysql_connect("localhost","****","****"); if (!$con) { die('Could not connect: ' . mysql_error()); } // Create table mysql_select_db("my_db", $con); $sql = "CREATE TABLE People ( FirstName varchar(15), LastName varchar(15), Age int )"; // Execute query mysql_query($sql,$con); mysql_close($con); ?> I tried to do it on my own, but I guess I'm still completely new to php I tried: <?php $con = mysql_connect("localhost","****","****"); if (!$con) { die('Could not connect: ' . mysql_error()); } // Create table if (mysql_select_db("my_db", $con)) { echo "Table created"; } else { echo "Error creating Table: " . mysql_error(); } $sql = "CREATE TABLE People ( FirstName varchar(15), LastName varchar(15), Age int )" // Execute query mysql_query($sql,$con); mysql_close($con); ?> It gave me an error with the last two lines mysql_query($sql,$con); mysql_close($con); I removed them and it really did give the output "Table created" yet it didn't create the table in the database. I'm having a feeling that I need to add an "if" statement, something of the sort. if (sql(CREATE TABLE Persons)) But I'm also getting the feeling something there is wrong, I still haven't tried it. Help? I'm trying to create a website, that echo's out a bunch of groups, where each group contains a group of checkboxes, containing A value, and a label for the checkbox, the way it is created right now, is foreach that echo's out a bunch of php arrays, which was easier than the static way before - But still, it's static in some way, or not very user friendly at the moment.. My problem is that I really want to write it in a database when I have the option. Is there anyone that can give some tips how to do? At the moment, my foreach looks like this: Code: [Select] echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'">'; /* NEXT WE CREATE OUR FOREACH LOOPS TO ECHO THE HTML FOR LOOKS AND CHECKBOXES */ $totalID=0; // this is a counter we use to build our check box names foreach ($items as $list){ $totalID++; // add one to the checkbox name counter echo "<h2>{$list['title']}</h2>\n"; // and echo out our section header foreach ($list['items'] as $cbox){ // now for each item in the list, call it $cbox // $cbox now holds the item name, and point value echo "<label class='checkbox'><input type='checkbox' name='totals[$totalID][]' value='{$cbox[1]}'> {$cbox[0]}</label>\n"; } } echo "</form>"; And my array is something like this: Code: [Select] $items['computers']['title']='Computer Brand'; $items['computers']['items'][]=array('Apple iMac',1); $items['computers']['items'][]=array('Apple Macbook',.5); $items['phones']['title']='Phone Brand'; $items['phones']['items'][]=array('iPhone',1); $items['phones']['items'][]=array('HTC',1); As said, I can write this, but takes time. I want to get it into a database, that data above, but I'm having problems about echo'ing it out, I really can't see how I should do. My current database looks like this: Thank you! 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 Here is my function which almost works as expected: <?php function find_value($array,$value) { for($i=1;$i<sizeof($array);$i++) { if($array[$i] == $value) { echo "$i . $array[$i]<br />"; return; } } } ?> And I call the function like so: <?php $names = array('Jason','Mike','Joe'); $name = 'Joe'; find_value($names,$name); ?> And the output is: 2 . Joe According to my understanding of Arrays, Joe would be index 3 BECAUSE my counter starts at 1 in my for loop??? Why is the result like this? What am I not understanding here? |