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

    Join Date
    Nov 2006
    Posts
    167
    Rep Power
    21

    Output the data into each different tags


    Hi guys,

    I have stored data in a MySQL database and I've output it in PHP. I want to know how I can output the data in different <span id="text1">` tags from `<tr><td>` tags.


    PHP Code:
        <?php
          define
    ('DB_HOST''localhost');
          
    define('DB_USER''myusername');
          
    define('DB_PASSWORD''mypassword');
          
    define('DB_DATABASE''mydbname');   
       
          
    $errmsg_arr = array();
          
    $errflag false;
          
    $link mysql_connect(DB_HOSTDB_USERDB_PASSWORD);
       
           if(!
    $link)
          {
            die(
    'Failed to connect to server: ' mysql_error());
          }
          
    $db mysql_select_db(DB_DATABASE);
       
          if(!
    $db)
          {
            die(
    "Unable to select database");
          }
       
       
          if(
    $errflag)
          {
            
    $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
            echo 
    implode('<br />',$errmsg_arr);
          }
          else
          {
            
    $qrytable1="SELECT id, mydata FROM mydb ";
            
    $result1=mysql_query($qrytable1) or die('Error:<br />' $qry '<br />' mysql_error());
       
             while (
    $row mysql_fetch_array($result1))
            {
              echo 
    "<tr><td>".$row['mydata']."</td></tr>";
            }
          }
        
    ?>
    On my PHP page it show something like this:


    PHP Code:
        <tr><td>my data 1</td></tr><tr><td>my data 2</td></tr><tr><td>my data 3</td></tr><tr><td>my data 4</td></tr
    How can I split the output the data into an array before I could output them in different <span id="text1">` tags from `<tr><td>` tags?

    any advice would be much appreicated.

    thanks in advance
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,466
    Rep Power
    594
    This is a duplicate of your previous post. You could have just edited it to fix the formatting. My other responses to the previous post still apply.
    1) DO NOT use the deprecated MySQL extensions. Switch to PDO.
    2) It is not clear what you mean by split into an array. Please provide an example of what you want the HTML to look like rather than what it currently is.

    Comments on this post

    • Jacques1 agrees : We need an autoresponder for every post containing "mysql_...()".
    Last edited by gw1500se; April 11th, 2013 at 06:58 AM.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo