Thread: Query print

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    8
    Rep Power
    0

    Query print


    I want to print all fields or chosen fields in a row with or without <br/>. What should the while loop contain and print syntax?

    PHP Code:
    <?php
    ini_set
    ('display_errors',1);
    ini_set('display_startup_errors',1);
    error_reporting(-1);
    include_once(
    'includes/connect.php');
    $que 1;
    $query $db->query("SELECT * FROM `members` WHERE `members` . `index` = $que");

    $fields $query->fetchAll(PDO::FETCH_ASSOC);
     echo 
    '<pre>'print_r($fieldstrue), '</pre>';
    }
    ?>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,493
    Rep Power
    594
    Print where? You do realize that PHP is server side and cannot do anything on the client side, right?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4123
    I think he means print as in print to screen (with print or echo command)

    Anyway, use foreach:

    PHP Code:
    foreach($rows as $row) {
         echo 
    "row ".$row.":<br />\n";
         foreach(
    $row as $key => $val) {
              echo 
    $key." = ".$val."<br />\n";
         }

    Hopefully you can see where you could expand your output to be conditional, put in extra html, etc etc
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    8
    Rep Power
    0
    This is part of a survey and I want to print out the results of each voter in an easy to read format for the surveyor.This is on a server but I cant provide a link.
  8. #5
  9. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4123
    show us the print_r result and how you would like it formatting...we'll show you how
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    8
    Rep Power
    0
    I can do the HTML CSS etc but I need a printout such as this.

    Voter ID 9003256
    Name John Doe
    Address 123 Main St
    Phone 5553123698
    .
    .
    .
  12. #7
  13. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    Originally Posted by Northie
    show us the print_r result and how you would like it formatting...we'll show you how
    He was talking to you.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    8
    Rep Power
    0
    Originally Posted by ManiacDan
    Originally Posted by Northie
    show us the print_r result and how you would like it formatting...we'll show you how
    He was talking to you.
    __________________

    ???? Who is that directed to? Why all the confusion?
    Last edited by ManiacDan; October 1st, 2013 at 02:52 PM. Reason: formatting
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    8
    Rep Power
    0
    Voter ID 9003256
    Name John Doe
    Address 123 Main St
    Phone 5553123698
    .
    .
    .
  18. #10
  19. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    for the third time now:
    show us the print_r result
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    8
    Rep Power
    0
    Sorry I have 40 projects going at the same time I got it thanks..


    PHP Code:
    $que 1;
    $query $db->query("SELECT `index`, `votNumber`, `first_last`, `phone` FROM `members` WHERE  `index` = $que");


    while(
    $rows $query->fetch(PDO::FETCH_ASSOC)){
        echo 
    "<p> ID ".$rows['index']."</p>";
        echo 
    "<p>Voter ID ".$rows['votNumber']."</p>";
        echo 
    "<p> Name ".$rows['first_last']."</p>";
        echo 
    "<p>Phone ".$rows['phone']."</p>";


IMN logo majestic logo threadwatch logo seochat tools logo