mark103 Posted April 11, 2013 Share Posted April 11, 2013 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 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_HOST, DB_USER, DB_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: <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 Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 11, 2013 Share Posted April 11, 2013 Uhm. Change the parts of your code that echo the <td>s to <span>s Quote Link to comment Share on other sites More sharing options...
mark103 Posted April 11, 2013 Author Share Posted April 11, 2013 well i got all the data in one <span> tag, i want to split them up to output them in each different <span> tags. Any idea how i can do this? Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 11, 2013 Share Posted April 11, 2013 I just told you how. Quote Link to comment Share on other sites More sharing options...
mark103 Posted April 11, 2013 Author Share Posted April 11, 2013 (edited) No you didn't, you only told me to do something like this: echo "<span id='text1'>".$row['mydata']."</span>"; all of the data are joined in one tag. I cannot make them get separate via split them up to ouput in each different tag. Please read my first post again before you say something. Edited April 11, 2013 by mark103 Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 11, 2013 Share Posted April 11, 2013 Maybe you should explain what you actually want. You need to read the link in my signature on asking good questions, because so far you are just wasting time. Quote Link to comment Share on other sites More sharing options...
mark103 Posted April 11, 2013 Author Share Posted April 11, 2013 I want to put the data into an array before outputting it. Any idea? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.