Displaying data from MySql a different way


Posted on 16th Feb 2014 07:03 pm by admin

Hi all,
I'm pretty new to php and MySql and have hit a problem.

I am able to display data in a table using the following code:

<?php
$database="MYDATABASE";
mysql_connect ("localhost", "MYUSERNAME", "MYPASSWORD");
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query( "SELECT field1, field2, field3 FROM staff WHERE `group` = 'group1' ORDER BY `role` " )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<P>";
print "<table width=200 border=1>n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>n";
foreach ($get_info as $field)
print "t<td><font face=arial size=1/>$field</font></td>n";
print "</tr>n";
}
print "</table>n";
?>

However, I would like to display the results using the following format:

<div id="info"><!--this is a div contanier for info"-->
<h1> field1 </h1>
<img src="field2" class="floatLeft" /><p>field3</p>
</div><!--close info div-->

Obviously, if there was more than one row of results, it would repeat the above format for each row.

Any help would be greatly appreciated
Thanks

No comments posted yet

Your Answer:

Login to answer
308 Like 43 Dislike
Previous forums Next forums
Other forums

question about stripslashes and real_escape_string
im cleaning up an old app that I wrote fixing some of the vulernabilities from attacks.

I hav

Need help to identify this error please
:confused:Can anyone help me tell what this error message means? Maybe tell me where to look to fix

echo $rows help
Hi all,

Hopefully something simple that I don't know!

I have this:

Code: [Selec

Undefined variable: adHTML
Hello:

While checking my site error logs, I've noticed one repetitive error that fills the lo

TimeZoneOffset
Hello,

Please i need your help. I have a system that users can use to punch in and out. This

Multithreading in Oracle (Java, SQLJ, Pro*C,??) on 10g
I am investigating how to run a Java stored procedure in multithread mode.
I know that if I chang

XML Grouping
I'm using xml_parse_into_struct to get all my elements, but now I need to group them. For example, h

Ajax Error since Upgrading to 3.5
Ever since upgrading my site to .NET 3.5 (I needed LINQ), I've been getting this annoying error on o

Pls help with PHP
Pls can anyone direct me on how to create a user account for a customer. For example i want know if

redirect standard error and assert (how to?)
How do you redirect standard error and assert?

---

(Why? I am creating an web app and

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash