Select multiple fields

Discussion in 'PHP' started by dtm32236, Aug 27, 2008.

  1. #1
    Hey guys,

    I have a database that I can't edit... a screenshot of it is attached.

    This db has a unique 'subscriber_id' for each person, and it stores their first name under 'field_id' 1 and the last name under 'field_id' 2.... if I'm saying that correctly. The attached image should help explain that.

    I want to query this database so that it outputs the first name and last name, then a <br>

    So far I have the following code (very simple):

    <?php
                    $con = mysql_connect("localhost","xxx","xxx");
                    if (!$con)
                      {
                      die('Could not connect: ' . mysql_error());
                      }
                    
                    mysql_select_db("pintmeis_pmsignup", $con);
                    
                    $result = mysql_query("SELECT `pm_subscriber_data`.* FROM pm_subscriber_data WHERE field_id='1'");
                    
                    while($row = mysql_fetch_array($result))
                      {
                      echo $row['value'];
                      echo "<br />";
                      }
                    
                    mysql_close($con);
                  ?>
    PHP:
    And this correctly displays the first name. But I have no idea how to make it display the last name.

    I tried this (and other variations of it):
    WHERE field_id='1' OR field_id='2'
    but this outputs the first name and last name on separate lines, and it orders the names wrong in many cases.

    I'm at a loss here... any help would be much appreciated.

    Thanks so much!

    I have this code executed on this page if it helps:
    http://www.pintmeisters.com/subscribers.php
     

    Attached Files:

    • ss1.jpg
      ss1.jpg
      File size:
      30.5 KB
      Views:
      37
    dtm32236, Aug 27, 2008 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    I can't view the image due dp forum error or something!?

    If you can show me the table format (fields) i can help you! :)
     
    EricBruggema, Aug 27, 2008 IP
  3. dtm32236

    dtm32236 Guest

    Messages:
    320
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks EricBruggema,

    I've got it all figured out, except for one thing. I have this code now, and it's working good, but it doesn't put spaces between the first and last name:

    $result = mysql_query("SELECT `pm_subscriber_data`.* FROM pm_subscriber_data WHERE field_id IN (1, 2) ORDER BY subscriber_id ASC, field_id ASC");
    
    				$tags = array(1=>'<li>%s', 2=>'%s</li>');
    				
    				echo "<ol style='margin-left:25px;'>";
    				while($row = mysql_fetch_array($result)){
    					printf($tags[$row['field_id']], $row['value']);
    				}
    				echo "</ol>";
    PHP:
    I don't even know if getting spaces is possible w this code (i'm obviously not great with PHP), but this is how it looks now:
    http://www.pintmeisters.com/subscribers.php
     
    dtm32236, Aug 27, 2008 IP
  4. dtm32236

    dtm32236 Guest

    Messages:
    320
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Nevermind. I got it all figured out.

    Thanks a lot for the effort though - I really appreciate it!
     
    dtm32236, Aug 27, 2008 IP