PHP - Printing Opposite Results From The Same Query (or Printing Outside A While Loop?)
I have 64 rows of players and want each User to be able to choose to bookmark an player, as well as unbookmark it too. I have a bookmark table set up, and each time a User decides to bookmark(+) or unbookmark(-) an player a row is created in the data table. (Matching the player ID and User ID) That's working fine. A query reads the most recent row for each player to determine if there is a + or - button next to each player. Testing the query and adding some dummy data, that part of it works too. However, the issue is the initial state, which I want to be a +. Once I go live, the table will be empty, nothing for the query to return/produce. How do I create an initial state of a + with no rows and have it not used or swapped out when Users start clicking + or -?
$query = "SELECT b.id, bookmark,playerID,userID,p.id FROM a_player_bookmark b LEFT JOIN a_players p ON '". $id ."' = playerID WHERE userID = '". $userID ."'&&'". $id ."' = playerID ORDER BY b.id desc LIMIT 1 "; $results = mysqli_query($con,$query); echo mysqli_error($con); while($row = mysqli_fetch_assoc($results)) { echo $row['bookmark']; if($row['bookmark'] == 0) { echo '-'; // this is where a form goes to remove a bookmark } else { echo '+'; // this is where a form goes to add a bookmark } } I tried to get it with CASE, but I don't think that's the right path. I also looked at UNION. I was able to get it to produce an initial state of +, but it still printed the already made up sample data too (so I have three instances of ++ or +-). (Players 2, 4 and 4)
Here is the what the UNION query looked like: $query = "(SELECT b.id, bookmark,playerID,userID,p.id FROM a_player_bookmark b LEFT JOIN a_players p ON '". $id ."' = playerID WHERE userID = '". $userID ."'&&'". $id ."' = playerID ORDER BY b.id desc LIMIT 1) UNION (SELECT b.id, bookmark,playerID,userID,p.id FROM a_player_bookmark b LEFT JOIN a_players p ON '". $id ."' = playerID WHERE userID = '". $userID ."' ORDER BY p.id desc LIMIT 1) ";
Similar TutorialsThe following generic code prints out a given table in my database, by first getting the fieldnames and putting them as the title of each column, and then getting the values. How do I change it so that if the name of the field is "password", the value will echo "----" instead of the password? $sql = "SELECT * FROM $tablename"; $result = mysql_query($sql) or die("Query failed : " . mysql_error()); $row = 1; ?> <table width="90%" border="1"><?php //the MYSQL_ASSOC gets field names instead of numbers while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($row == 1) { ?><tr><?php foreach ($line as $col_key => $col_value) { ?><th><?php echo $col_key;?></th><?php } ?></tr><?php } ?><tr><?php foreach ($line as $col_value) { ?><td><?php echo $col_value;?></td><?php } ?></tr><?php $row++; Hi I have a problem that I must admit I have come across before but I can't remember the fix. When I do a simple select query then print it out using a while statement, I can't get it to print out the first record of my results. I am sure this is to do with the execute statement but I can't get it to work properly. I currently have test data in so I know this should bring out 6 records but it only lists 5 hi everyone I have a small user & business Directory and for it, I use a .htaccess ReWrite. My .htaccess file looks like Code: [Select] RewriteEngine On RewriteRule ^([^/.]+)$ index.php?q=$1 [QSA,L] so basically when I run Code: [Select] http://localhost/Johnsons/ then it treats that like Code: [Select] http://localhost/index.php?q=Johnsons I then do a PHP Query to find the result, I use the following; print "You looked up $_GET['q']"; $result = mysql_query("SELECT `name` FROM `directory` WHERE `name` = '".$_GET['q']."'"); while($row = mysql_fetch_array($result)) { print $row['name']; } this all works fine. The problem I now have is that I have been sent some new data in a SQL database import file and it contains entries such as Dugāriy T-ī-Corā but when I try and run http://localhost/Dugāriy/ or http://localhost/T-ī-Corā/ it does not return the correct value and instead it either misses characters or it exchanges one character for another, (ā is swapped "a" as an example). It seems this is due to a mix of Special Characters & Accents within words such as ā ū ī I have tried altering the META charset tag without any luck, I have also tried print utf8_encode($_GET['q']); print urlencode($_GET['q']); but nothing seems to work. Any idea on how I can solve this? Thanks very much J I have the following php script and get data from a database and prints in on a page however it does not print a carriage return. Why can this be? The script: <?php include "database.inc"; mysql_select_db("php", $connection); $result = mysql_query("SELECT * FROM orders", $connection); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { foreach ($row as $attribute) print "($attribute)"; print "\n"; } ?> Hi there, I'm new in PHP, my output is in at table, I designed it already, now I want to print it..how can I do that ? do i need JS ? hello all, i know that php is server side. if i have a printer attached to the server, can i have users press a button and have it print there? I have a directory that I would like to allow users to print to PDF format for download. How can I do this and where do I start? I've got a database file from sqlite, there is a multidimensional array in it with 10 metals. I just want two print out each element in a table It won't get all the separate data inside a HEREDOC foreach ($product_prices as $metal => $prices) "<tr><td>$metal</td><td align = 'right'>". round($prices[wire][28]*$l_conv*$w_conv,4). "<tr><td>$metal</td><td align = 'right'>". round($prices[wire][36]*$l_conv*$w_conv,4). "<tr><td>$metal</td><td align = 'right'>". round($prices[wire][45]*$l_conv*$w_conv,4). "<tr><td>$metal</td><td align = 'right'>". round($prices[dust][100]*$l_conv*$w_conv,4). "<tr><td>$metal</td><td align = 'right'>". round($prices[dust][10]*$l_conv*$w_conv,4). "<tr><td>$metal</td><td align = 'right'>". round($prices[dust][1]*$l_conv*$w_conv,4). "</td></tr>"; Hello,
I am trying to print the invoice in pdf, using fpdf. i am not getting how to do it. I am able to display line items , but its not in proper format. I tried changing X, Y positions, but its not going into my head . Also i want to display Logo and address in left side, invoice number and order date in right side.
Here is the code i have done so far... Please please help me in this
<?php require('includes/fpdf/fpdf.php'); //Connect to your database include("connect/DB_Connect.php"); $id = $_GET['id']; //Select the Products you want to show in your PDF file $result=mysql_query("select invoice_no, order_no, order_date, completion_date, artwork, customer_po, order_quantity, comments, order_amount from invoice where invoice_no='".$id."' ") or die(mysql_error()); $number_of_products = mysql_numrows($result); //Initialize the 3 columns and the total $column_order_date = ""; $column_order_no = ""; $column_artwork = ""; $column_cpo = ""; $column_order_quantity = ""; $column_order_amount = ""; $column_comments = ""; $total = 0; //For each row, add the field to the corresponding column while($row = mysql_fetch_array($result)) { $order_date = $row["order_date"]; $order_no = $row["order_no"]; $artwork = $row['artwork']; $cpo = $row['customer_po']; $oquantity = $row['order_quantity']; $oamount = $row['order_amount']; $comments = $row['comments']; //$price_to_show = number_format($row["Price"],',','.','.'); $column_order_date = $column_order_date.$order_date."\n"; $column_order_no = $column_order_no.$order_no."\n"; $column_artwork = $column_artwork.$artwork."\n"; $column_cpo = $column_cpo.$cpo."\n"; $column_order_quantity = $column_order_quantity.$oquantity."\n"; $column_order_amount = $column_order_amount.$oamount."\n"; $column_comments = $column_comments.$comments."\n"; //Sum all the Prices (TOTAL) $total = $total+$oamount; } mysql_close(); //Create a new PDF file $pdf=new FPDF(); $pdf->AddPage(); //Fields Name position $Y_Fields_Name_position = 20; //Table position, under Fields Name $Y_Table_Position = 26; //First create each Field Name //Gray color filling each Field Name box $pdf->SetFillColor(232,232,232); //Bold Font for Field Name $pdf->SetFont('Arial','B',12); $pdf->SetY($Y_Fields_Name_position); $pdf->SetX(5); $pdf->Cell(25,6,'Order Date',1,0,'L',1); $pdf->SetX(30); $pdf->Cell(50,6,'Graphixide Order No',1,0,'L',1); $pdf->SetX(75); $pdf->Cell(40,6,'Artwork',1,0,'L',1); $pdf->SetX(110); $pdf->Cell(20,6,'PO #',1,0,'L',1); $pdf->SetX(130); $pdf->Cell(20,6,'Quantity',1,0,'L',1); $pdf->SetX(150); $pdf->Cell(25,6,'Amount',1,0,'L',1); $pdf->SetX(175); $pdf->Cell(25,6,'Comments',1,0,'L',1); //Now show the 3 columns $pdf->SetFont('Arial','',12); $pdf->SetY($Y_Table_Position); $pdf->SetX(5); $pdf->MultiCell(25,6,$column_order_date,1); $pdf->SetY($Y_Table_Position); $pdf->SetX(30); $pdf->MultiCell(80,6,$column_order_no,1); $pdf->SetY($Y_Table_Position); $pdf->SetX(75); $pdf->MultiCell(40,6,$column_artwork,1); $pdf->SetY($Y_Table_Position); $pdf->SetX(110); $pdf->MultiCell(20,9,$column_cpo,1); $pdf->SetY($Y_Table_Position); $pdf->SetX(130); $pdf->MultiCell(20,6,$column_order_quantity,1); $pdf->SetY($Y_Table_Position); $pdf->SetX(150); $pdf->MultiCell(75,6,$column_order_amount,1); $pdf->SetY($Y_Table_Position); $pdf->SetX(175); $pdf->MultiCell(25,10,$column_comments,1); $pdf->SetY($Y_Table_Position); $pdf->SetX(150); $pdf->MultiCell(130,6,'$ '.$total,1,'R'); //Create lines (boxes) for each ROW (Product) //If you don't use the following code, you don't create the lines separating each row $i = 0; while ($i < $number_of_products) { $pdf->SetX(45); $pdf->MultiCell(120,6,'',1); $i = $i +1; } $pdf->Output(); ?>Here is the output of this code ss.PNG 32.3KB 7 downloads Hi, I really need to find a way to print the code below in php. Code: [Select] <script> $(document).ready(function() { $.sticky('The page has loaded!'); }); </script> i tried Code: [Select] print"<script> $(document).ready(function() { $.sticky('The page has loaded!'); });"; </script> any help would be great. Hello, I need help with this issue, I am displaying <a href='index.php?cat=h & r'>text</a> when I do print $_GET['cat'] it only displays h, why ? Thanks hi i have this code here and i was wondering how i could make it print out the values from my database using a drop down menu. i no this is probably very basic but im a real novice at php and sql. <?php mysql_connect('localhost', 'root', ''); mysql_select_db('charity_data'); $result = mysql_query('select * from donations'); ?> <select name="selectname"> <?php $i = 0; while ($i < mysql_num_fields($result)){ $fieldname = mysql_field_name($result, $i); echo '<option value="'.$fieldname.'">'.$fieldname.'</option>'; $i++; } ?> </select> Hi All, I am trying to generate a PDF report using the below code. the report is being generated perfectly. The problem that I face is that, while printing the report the browser disregards the "IF" condition that I have given in the code. Explanation : ----------------- It prints all the data in the MySQL database wherein I wanted the data to be printed only on a certain condition. How do I achieve this? Quote <?php mysql_connect('localhost','user','pass'); mysql_select_db('vaccine'); $array = mysql_query("SELECT cattle_n FROM vactbl"); $num_rows = mysql_num_rows($array); $array = mysql_query("SELECT * FROM vactbl"); $num_rows = mysql_num_rows($array); while($info = mysql_fetch_array( $array )) { $mas_date = $info['masdt']; $mas_time = strtotime($mas_date); $two_week = strtotime("+2 week"); $rpt_date = abs($two_week - $mas_time); if ($rpt_date >= 7776000) { require('mysql_table.php'); class PDF extends PDF_MySQL_Table { function Header() { //Title $this->SetFont('Arial','B',40); $this->Cell(0,6,'Cattle List',0,1,'C'); $this->Ln(10); //Ensure table header is output parent::Header(); } } //Connect to database $pdf=new PDF(); $pdf->AddPage(); //First table: put all columns automatically //$pdf->Table('select * from cattle_det order by no'); //$pdf->AddPage(); //Second table: specify 3 columns $pdf->AddCol('cattle_n',20,'Cattle','C'); $pdf->AddCol('masdt',40,'Mastitis Date', 'C'); $pdf->AddCol('fmdt',40,'FM Date','C'); $pdf->AddCol('onedt',40,'Vaccine1 Date','C'); $pdf->AddCol('twodt',40,'Vaccine2 Date','C'); $prop=array('HeaderColor'=>array(255,150,100), 'color1'=>array(210,245,255), 'color2'=>array(255,255,210), 'padding'=>2); $pdf->Table('select cattle_n, masdt, fmdt, onedt, twodt from vactbl order by cattle_n limit 0,10',$prop); $pdf->Output(); } else {} } ?> Here is my code...
<?php $to = "email@email.com"; //obviously not real $from = "noreply@domain.com"; //obviously not real $firstName = $_REQUEST['firstName']; $headers = "From: $from"; $subject = "Product Sheet Request"; /* $fields = array(); $fields{"firstName"} = "firstName"; $fields{"lastName"} = "lastName"; $fields{"email"} = "email"; $fields{"phone"} = "phone"; $fields{"affiliation"} = "affiliation"; $fields{"interest"} = "interest"; $fields{"productSheets"} = "productSheets"; $fields{"referredBy"} = "referredBy"; $fields{"additional"} = "additional"; */ $firstName = $_REQUEST['firstName']; $lastName = $_REQUEST['lastName']; $email = $_REQUEST['email']; $phone = $_REQUEST['phone']; $affiliation = $_REQUEST['affiliation']; $interest = $_REQUEST['interest']; if($interest == 'inclusion'){ $interest = 'Evaluating for inclusion in product'; } elseif($interest == 'general'){ $interest = 'Interested in the technology generally'; } elseif($interest == 'research'){ $interest = 'Performing market research'; } elseif($interest == 'solutions'){ $interest = 'Looking for competitive solutions'; } $referredBy = $_REQUEST['referredBy']; $additional = $_REQUEST['additional']; $productSheets[] = $_REQUEST['productSheets']; $sheets = print_r($productSheets); /* $body = "A user has requested product sheet(s). Please review their information and respond:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } */ $body = "A user has requested product sheet(s). Please review their information and respond:\n First Name: ".$firstName."\r Last Name: ".$lastName."\r Email: ".$email."\r Phone Number: ".$phone."\r Affiliation: ".$affiliation."\r Reason for Interest: ".$interest."\r Referred By: ".$referredBy."\r Additional Questions/Comments: ".$additional."\r Product Sheet(s) Requested: ".$sheets."\n "; $send = mail($to, $subject, $body, $headers); ?>I'm not quite sure how to display the values of the $productSheets array in the email message. Everytime it either outputs "Array" or "1". The $productSheets array is from a checkbox on a form. Everything else is working as expected. Hi there! I found this code to parse a MySQL query to PDF, but it's for small address labels and I was wondering how to make it for 4x6 labels? <?php define('FPDF_FONTPATH','/home/directory/public_html/sub/font/'); require_once('fpdf.php'); //Connect to your database mysql_connect("localhost", "db_user","db_pw") or die ("Could not connect to database"); mysql_select_db("database_name") or die ("Could not select database"); $query = "SELECT employee_name, street_address, City, state, zip_code FROM employees ORDER BY `employee_name` "; $result = mysql_query($query) or die('Error, query failed'); $num_rows = mysql_num_rows($result); function PrintAddressLabels($result){ $pdf=new FPDF(); $pdf->Open(); $pdf->AddPage(); $pdf->SetFont('Arial','B',14); $pdf->SetMargins(0,0); $pdf->SetAutoPageBreak(false); $x = 0; $y = 0; $i=0; while (TRUE) { if ($row=$result[$i]) { //positions set above $LabelText = sprintf("%s\n%s %s\n%s, %s, %s", $row['employee_name'], $row['street_address'], $row['City'], $row['state'], $row['zip_code']); Avery5160($x,$y,&$pdf,$LabelText); $y++; // next row if ($y == 10 ) { // end of page wrap to next column $x++; $y = 0; if ($x == 3 ) { // end of page $x = 0; $y = 0; $pdf->AddPage(); } } $i++; //counter through result } else { // Error quit printing break; } { $pdf->Output('mailing_labels.pdf','D'); } ?> Does anyone know where I can find some good resources/tutorials that covers how to use the PDF stuff with PHP or know how I can change this up to match for 4x6 at all? Any help or info is greatly appreciated! Thanks! Hi, I want to echo an image depending on a value. This is the code I'm using Code: [Select] <?php if ($row_cliente_RS['estadofactura_titulo']) == 'yes' echo '<img src="img/pagada.jpg" width="70" height="15">'; ?>...but nothing echoes. What am I doing wrong? Thanks is there a way to make a link or button that will print the current page, but only page 1, landscape with no headers or footers? or print between two tags? thanks Hi, I'm a PHP novice and trying to print out elements of what appears to be a multi-dimensional array, but I can't figure it out. I'm able to use print_r() to dump the array. Array ( [0] => 18485 [1] => Array ( [1] => Array ( [isPublished] => 1 [dateAdded] => 2019-07-18T16:13:28+00:00 [dateModified] => 2020-01-29T18:37:45+00:00 [createdBy] => [createdByUser] => Support [modifiedBy] => [modifiedByUser] => [id] => 1 [points] => 0 [color] => [fields] => Array ( [core] => Array ( [points] => Array ( [id] => 9 [label] => Points [alias] => points [type] => number [group] => core [object] => lead [is_fixed] => 1 [default_value] => 0 [properties] => a:0:{} [value] => 0 [normalizedValue] => 0 ) [last_active] => Array ( [id] => 19 [label] => Date Last Active [alias] => last_active [type] => datetime [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => 2020-01-29 18:37:47 [normalizedValue] => 2020-01-29 18:37:47 ) [title] => Array ( [id] => 1 [label] => Title [alias] => title [type] => lookup [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:1:{s:4:"list";a:3:{i:0;s:2:"Mr";i:1;s:3:"Mrs";i:2;s:4:"Miss";}} [value] => [normalizedValue] => ) [firstname] => Array ( [id] => 2 [label] => First Name [alias] => firstname [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => Andy [normalizedValue] => Andy ) [lastname] => Array ( [id] => 3 [label] => Last Name [alias] => lastname [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => Towne [normalizedValue] => Towne ) [company] => Array ( [id] => 4 [label] => Primary company [alias] => company [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [position] => Array ( [id] => 5 [label] => Position [alias] => position [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [email] => Array ( [id] => 6 [label] => Email [alias] => email [type] => email [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => andy.towne@example.com [normalizedValue] => andy.towne@example.com ) [phone] => Array ( [id] => 8 [label] => Phone [alias] => phone [type] => tel [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [mobile] => Array ( [id] => 7 [label] => Mobile [alias] => mobile [type] => tel [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [address1] => Array ( [id] => 11 [label] => Address Line 1 [alias] => address1 [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [address2] => Array ( [id] => 12 [label] => Address Line 2 [alias] => address2 [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [city] => Array ( [id] => 13 [label] => City [alias] => city [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => Boston [normalizedValue] => Boston ) [state] => Array ( [id] => 14 [label] => State [alias] => state [type] => region [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => Massachusetts [normalizedValue] => Massachusetts ) [zipcode] => Array ( [id] => 15 [label] => Zip Code [alias] => zipcode [type] => text [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [timezone] => Array ( [id] => 18 [label] => lead.field.timezone [alias] => timezone [type] => timezone [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => America/New_York [normalizedValue] => America/New_York ) [country] => Array ( [id] => 16 [label] => Country [alias] => country [type] => country [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => United States [normalizedValue] => United States ) [fax] => Array ( [id] => 10 [label] => Fax [alias] => fax [type] => tel [group] => core [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [preferred_locale] => Array ( [id] => 17 [label] => Preferred Locale [alias] => preferred_locale [type] => locale [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [attribution_date] => Array ( [id] => 20 [label] => Attribution Date [alias] => attribution_date [type] => datetime [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [attribution] => Array ( [id] => 21 [label] => Attribution [alias] => attribution [type] => number [group] => core [object] => lead [is_fixed] => 1 [default_value] => [properties] => a:2:{s:9:"roundmode";i:4;s:9:"precision";i:2;} [value] => [normalizedValue] => ) [website] => Array ( [id] => 22 [label] => Website [alias] => website [type] => url [group] => core [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [number_of_email_users] => Array ( [id] => 45 [label] => Number of Email Users [alias] => number_of_email_users [type] => number [group] => core [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:2:{s:9:"roundmode";s:1:"3";s:9:"precision";s:0:"";} [value] => [normalizedValue] => ) ) [social] => Array ( [facebook] => Array ( [id] => 23 [label] => Facebook [alias] => facebook [type] => text [group] => social [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [foursquare] => Array ( [id] => 24 [label] => Foursquare [alias] => foursquare [type] => text [group] => social [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [instagram] => Array ( [id] => 26 [label] => Instagram [alias] => instagram [type] => text [group] => social [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [linkedin] => Array ( [id] => 27 [label] => LinkedIn [alias] => linkedin [type] => text [group] => social [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [skype] => Array ( [id] => 28 [label] => Skype [alias] => skype [type] => text [group] => social [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) [twitter] => Array ( [id] => 29 [label] => Twitter [alias] => twitter [type] => text [group] => social [object] => lead [is_fixed] => 0 [default_value] => [properties] => a:0:{} [value] => [normalizedValue] => ) ) [personal] => Array ( ) [professional] => Array ( ) [all] => Array ( [id] => 1 [points] => 0 [last_active] => 2020-01-29 18:37:47 [title] => [firstname] => Andy [lastname] => Towne [company] => [position] => [email] => andy.towne@example.com [phone] => [mobile] => [address1] => [address2] => [city] => Boston [state] => Massachusetts [zipcode] => [timezone] => America/New_York [country] => United States [fax] => [preferred_locale] => [attribution_date] => [attribution] => [website] => [number_of_email_users] => [facebook] => [foursquare] => [instagram] => [linkedin] => [skype] => [twitter] => ) ) [lastActive] => 2020-01-29T18:37:47+00:00 [owner] => [ipAddresses] => Array ( [0] => Array ( [ipAddress] => 104.247.39.34 [id] => 5043 [ipDetails] => Array ( [city] => Boston [region] => Massachusetts [zipcode] => [country] => United States [latitude] => 42.36 [longitude] => -71.0545 [isp] => [organization] => [timezone] => America/New_York [extra] => ) ) [1] => Array ( [ipAddress] => 74.125.210.26 [id] => 6162 [ipDetails] => Array ( [city] => Hayward [region] => California [zipcode] => [country] => United States [latitude] => 37.6736 [longitude] => -122.0944 [isp] => [organization] => [timezone] => America/Los_Angeles [extra] => ) ) [2] => Array ( [ipAddress] => 73.126.166.11 [id] => 3069 [ipDetails] => Array ( [city] => Everett [region] => Massachusetts [zipcode] => [country] => United States [latitude] => 42.415 [longitude] => -71.0527 [isp] => [organization] => [timezone] => America/New_York [extra] => ) ) ) [tags] => Array ( ) [utmtags] => Array ( ) [stage] => [dateIdentified] => 2019-07-18T16:13:28+00:00 [preferredProfileImage] => gravatar [doNotContact] => Array ( ) [frequencyRules] => Array ( ) ) ) ) This output was produced using print_r($array);
I'm trying to access our contacts using the vendor's PHP API, but I'm not much of a PHP programmer. The array is stored in $contacts, using the vendor's getList() function. I believe I'm able to download the whole list of contacts in an array, but I can't iterate through it. I'd like to print out the elements of the array in CSV format.
$contacts = $contactApi->getList($searchFilter, $start, $limit, $orderBy, $orderByDir, $publishedOnly, $minimal); I've also tried something like this:
foreach ($contacts as $contact) {
Hey, I made a simple form: Code: [Select] <html> <body> <form action="action.php" method="POST"> <input type="text" name="text" /> <br> <input type="submit value="submit" /> </form> </body> </html> The action.php is as follows: <?php $text = $_POST['text']; header('location:next/index.php'); next/index.php is as follows: <?php include_once('../index.html'); echo "Hello, your text was " . $text . "!"; ?> Problem: Where the $text variable is located in next/index.php there is a blank space. The php includes the first index.html correctly without errors, but it seems like it doesn't store the variable. Thanks in advance I am trying to print out information from a list. I thought I had this figured out but realized It was just printing out the same information over and over. This is from a Joomla website and I am using the J2store extension, just to give you the information from where this is coming from. So this is suppose to print out all the attributes from a single order. Each item in the order has any number of attributes that make it up. I am using it as an assembly site. So each assembly will have different attributes that make it up. (Hope that explains it good enough.) <?php JModelLegacy::addIncludePath(JPATH_SITE.'/components/com_j2store/models'); $model = JModelLegacy::getInstance( 'OrderItemAttributes', 'J2StoreModel' ); ?> <?php foreach (@$items as $item) : ?> <?php //these are just printed to show the 5 different items in the same order echo $item->order_id; echo '<br />'; echo $item->orderitem_id; echo '<br />'; echo $item->orderitem_name; echo '<br />'; $model->setState( 'filter_orderitemid', $item->orderitem_id); $attributes = $model->getList(); foreach($attributes as $attribute) { if(!empty($attribute->orderitemattribute_value)) { echo $attribute->orderitemattribute_name.' : '.$attribute->orderitemattribute_value; echo '<br />'; } } echo '<br />'; ?> <?php endforeach; ?>This ends up printing out this: -------------------------------------------------------- 1402100770 49 16" Box to Stud Bracket with Open Back Box + Modular Duplex BRACKET : B-Line BB7-16 BOX : Crouse Hinds TP40DPF Mud Ring (Choose an Option) : 3/4'' Rise Single Gang MC Cable (Choose an Option) : 12/2 (black,white,green) x 25' L Device (Choose an Option) : Hubbell 20A SnapConnect Duplex with Connector Device Color (Choose an Option) : White MC Connector (x2) : Crouse Hinds 38MCQ 12/2 Anti-Short (x2) : 12/2 Anti Short 11" Cable Tie (x2) : 11'' Cable Tie 4 Port Wago (x3) : Ideal Model 88 Device Protector Plate : B-Line BPR1 1402100770 52 3/4" Conduit Masonry Stub BRACKET : B-Line BB7-16 BOX : Crouse Hinds TP40DPF Mud Ring (Choose an Option) : 3/4'' Rise Single Gang MC Cable (Choose an Option) : 12/2 (black,white,green) x 25' L Device (Choose an Option) : Hubbell 20A SnapConnect Duplex with Connector Device Color (Choose an Option) : White MC Connector (x2) : Crouse Hinds 38MCQ 12/2 Anti-Short (x2) : 12/2 Anti Short 11" Cable Tie (x2) : 11'' Cable Tie 4 Port Wago (x3) : Ideal Model 88 Device Protector Plate : B-Line BPR1 1402100770 53 3/4" Conduit Masonry Stub BRACKET : B-Line BB7-16 BOX : Crouse Hinds TP40DPF Mud Ring (Choose an Option) : 3/4'' Rise Single Gang MC Cable (Choose an Option) : 12/2 (black,white,green) x 25' L Device (Choose an Option) : Hubbell 20A SnapConnect Duplex with Connector Device Color (Choose an Option) : White MC Connector (x2) : Crouse Hinds 38MCQ 12/2 Anti-Short (x2) : 12/2 Anti Short 11" Cable Tie (x2) : 11'' Cable Tie 4 Port Wago (x3) : Ideal Model 88 Device Protector Plate : B-Line BPR1 1402100770 51 MC Cable Whip Assembly BRACKET : B-Line BB7-16 BOX : Crouse Hinds TP40DPF Mud Ring (Choose an Option) : 3/4'' Rise Single Gang MC Cable (Choose an Option) : 12/2 (black,white,green) x 25' L Device (Choose an Option) : Hubbell 20A SnapConnect Duplex with Connector Device Color (Choose an Option) : White MC Connector (x2) : Crouse Hinds 38MCQ 12/2 Anti-Short (x2) : 12/2 Anti Short 11" Cable Tie (x2) : 11'' Cable Tie 4 Port Wago (x3) : Ideal Model 88 Device Protector Plate : B-Line BPR1 1402100770 50 Span Bracket with 4 SQ. Deep 1/2''-3/4'' KO's + Modular 2 Single BRACKET : B-Line BB7-16 BOX : Crouse Hinds TP40DPF Mud Ring (Choose an Option) : 3/4'' Rise Single Gang MC Cable (Choose an Option) : 12/2 (black,white,green) x 25' L Device (Choose an Option) : Hubbell 20A SnapConnect Duplex with Connector Device Color (Choose an Option) : White MC Connector (x2) : Crouse Hinds 38MCQ 12/2 Anti-Short (x2) : 12/2 Anti Short 11" Cable Tie (x2) : 11'' Cable Tie 4 Port Wago (x3) : Ideal Model 88 Device Protector Plate : B-Line BPR1 -------------------------------------------------------- The number '1402100770' is the order number. Which in that order there were 5 items purchased. The numbers for the orderitem_id are the correct numbers for the order number. The name is also the correct for the items that were in the order. The problem is when the attributes print out. It prints the same attributes for all 5 items purchased. It seems to be printing the first items attributes for all the items in the order. I can't figure out why the orderitem_id and orderitem_name all prints out correctly but when it prints of the attributes it just prints the same attributes for all the items in the order. |