/    Sign up×
Community /Pin to ProfileBookmark

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.

[code=php]
<?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>”;
}
}
?>
[/code]

On my PHP page it show something like this:

[code=php]
<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>[/code]

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

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@coding123Apr 12.2013 — Hello,

You can switch in your while statement this:

echo "<tr><td>".$row['mydata']."</td></tr>";

with this:

echo "<span class='text1'>".$row['mydata']."</span>";

You would also need to remove <table></table> tags, since they are no longer needed.
×

Success!

Help @mark107 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...