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:
Did you know?Explore Trending and Topic pages for more stories like this.

<?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

Logic question
im wondering what's the best method to do the above list:

it is for alliance @ MMORPG game

Ignore html and bbcode?
I've created a function to limit the amount of text according to the amount of words.

However

I think i'm using the syntax incorrectly
Hi Everyone!

I'm new to this forum and a newbie with PHP - I'm glad I found this site - I hop

Show message after entering data
Hello Colleagues

I would like to display messages after entering the data example: "
dat

Do not allow posting of whitespace
Currently the script below works if the user does not type a name/message, but if i create a whitesp

Confusing Functions
So, I've been reading up on Functions and I like them! However, I need some help using variables in

http to https
Hi,

Is there any specific method/condition to move an http:// page to https:// ?

Drop Down and text box issue
Is it possible to set a drop down list and text boxes to a certain width?

here is my code

Best way to read this text file.
Hi.I am planning to make a small application in C# to convert the players from Football manager 2010

Not reloading page after php form submit
Hello helpful souls out there. You guys have come through for me in the recent past and I'm hoping s

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