listing all variables values

Discussion in 'PHP' started by ahdflash, Aug 9, 2008.

  1. #1
    I have a long list of variables and I want to list all the values in order (the name and its number) for example

    $name='John';
    $number='1234';
    $link='http://link.com';
    Code (markup):

    <a href="<?php echo $link ?>" class="name"><?php echo $name ?></a> <div class="number"><?php echo $number ?></div>
    Code (markup):
    is there any way to do that?
     
    ahdflash, Aug 9, 2008 IP
  2. payu

    payu Peon

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    how exactly is your list of variables ?
     
    payu, Aug 9, 2008 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    How exactly does your list look like? It can't be like that:
    
    $name='John';
    $number='1234';
    $link='http://link.com';
    
    PHP:
    ... since you'd just be redefining the existing variables. Are you using an array? (You should!)... be more specific.
     
    nico_swd, Aug 9, 2008 IP
  4. ahdflash

    ahdflash Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    How its supposed be listed?
    Its like a database for contact...

    any idea ?
     
    ahdflash, Aug 9, 2008 IP
  5. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #5
    
    <?php
    
    $name='John';
    $number='1234';
    $link='http://link.com';
    
    $list = array(John, 1234, http://link.com);
    
    ?>
    
    
    $list <br><br>
    Hello $name your pin number is $number here is the link to where you enter you pin number - $link
    
    
    PHP:
     
    jpinheiro, Aug 9, 2008 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Post that list please. Or at least a bit more of what you've posted already.

    Is it LIKE a database, or IS it a database?


    You really have to be more specific about what you already have and what you want to accomplish.
     
    nico_swd, Aug 9, 2008 IP
  7. ahdflash

    ahdflash Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    sorry nico_swd but I don't have the list right now.
    I'm making a website to list all employees names and numbers each employee has a variables for his name and phone number.

    I want to list all of the the data in one page.

    
    Name: john
    Phone: 1234
    
    name: sara
    Phone:4321
    Code (markup):
    Is there a way to do it without making a variable for every employee :confused:
     
    ahdflash, Aug 9, 2008 IP
  8. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #8
    
    <?php
    
    
    $employee[0] = "John Smith, 555-555-5555";
    $employee[1] = "John Smith, 555-555-5555";
    $employee[2] = "John Smith, 555-555-5555";
    $employee[3] = "John Smith, 555-555-5555";
    $employee[4] = "John Smith, 555-555-5555";
    
    echo "Employee 1 "
    . $employee[0]; 
    echo "<br />Employee 2 " 
    . $employee[1];
    echo "<br />Employee 3 " 
    . $employee[2];
    echo "<br />Employee 4 " 
    . $employee[3];
    echo "<br />Employee 5 " 
    . $employee[4];
    
    ?>
    
    PHP:
     
    jpinheiro, Aug 9, 2008 IP
  9. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #9
    ---
    ---
    ---
    Ok i Made a Mistake this is how you do it

    heres an example: http://cynscriptz.com/employee.php

    
    
    <?php
    
    
    $employee[0] = "John Smith, 555-555-5555";
    $employee[1] = "John Smith, 555-555-5555";
    $employee[2] = "John Smith, 555-555-5555";
    $employee[3] = "John Smith, 555-555-5555";
    $employee[4] = "John Smith, 555-555-5555";
    
    echo "Employee 1 "
    . $employee[0]; 
    echo "<br />Employee 2 " 
    . $employee[1];
    echo "<br />Employee 3 " 
    . $employee[2];
    echo "<br />Employee 4 " 
    . $employee[3];
    echo "<br />Employee 5 " 
    . $employee[4];
    
    ?>
    
    
    PHP:
     
    jpinheiro, Aug 9, 2008 IP
  10. ahdflash

    ahdflash Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Thanks epsition
    Problem solved :)
     
    ahdflash, Aug 9, 2008 IP
  11. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #11
    No Problem :D im sorta new to PHP trying to learn XD

    nico_swd is the best guy to ask for php help but he wont just give you a soloution he will make you learn how to do it :D
     
    jpinheiro, Aug 9, 2008 IP
  12. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #12
    Lol, oh I do when I feel like it's appropriate. I'm just under the impression that some people don't even try to solve their own problems. (That isn't directed at ahdflash, just generally saying).
     
    nico_swd, Aug 9, 2008 IP
  13. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #13
    Btw, this can be much simplified:
    ... to:

    
    <?php
    
    $employee[0] = "John Smith, 555-555-5555";
    $employee[1] = "John Smith, 555-555-5555";
    $employee[2] = "John Smith, 555-555-5555";
    $employee[3] = "John Smith, 555-555-5555";
    $employee[4] = "John Smith, 555-555-5555";
    
    foreach ($employee AS $key => $person)
    {
        $key++;
        echo "Employee {$key}: {$person}<br />\n";
    }
    ?>
    
    PHP:
    ... this way you can add as many as you want, and you just have to add them to the array and not the list as well.
     
    nico_swd, Aug 9, 2008 IP
  14. ahdflash

    ahdflash Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Thanks guys.

    Sorry nico_swd I should make it clear form the beginning.
    I'm just a beginner ;)
     
    ahdflash, Aug 9, 2008 IP
  15. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #15
    thats cool i love php :D

    I need to finish my php 5 for dummies book XD lol
     
    jpinheiro, Aug 9, 2008 IP