php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75110 Dont iterate foreach
Submitted: 2017-08-23 18:05 UTC Modified: 2017-08-23 18:29 UTC
From: porfi_miramontes at hotmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.0Git-2017-08-23 (snap) OS: ubuntu16.04.1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: porfi_miramontes at hotmail dot com
New email:
PHP Version: OS:

 

 [2017-08-23 18:05 UTC] porfi_miramontes at hotmail dot com
Description:
------------
Dont print values from array obtained from database use foreach loop

Test script:
---------------
<?php
try {
 	$base=new PDO('mysql:host=localhost;dbname=mydatabase','root','12345678');
 	$base->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
 	$base->exec("SET CHARACTER SET UTF8");

 	$reg=$base->query("SELECT * FROM articles WHERE client='Myclient' ORDER BY article_state desc limit 1,2")->fetchAll(PDO::FETCH_OBJ);
	foreach($reg as $articles=>$value)
        {

	 echo $value;
 
         }

     } 

 catch (Exception $e) 
 {
 	die ("Error ".$e->getMessage());
 	echo "Line error : ".$e->getLine();

 }








?>

Expected result:
----------------
Myarticle1,Desc1,Desc2
Myarticle2,Desc1,Desc2
Myarticle3,Desc1,Desc2
.
.
.
.
.
.



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-08-23 18:14 UTC] subjective@php.net
You do not access the actual fields, but the record array/object. Here is no automatic conversion of an array/object to CSV, look up fputcsv().
 [2017-08-23 18:29 UTC] subjective@php.net
-Status: Open +Status: Not a bug
 [2017-08-23 18:29 UTC] subjective@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 16:01:29 2024 UTC