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

Call db table from any PHP file
Hi,

I want to be able to call a database table that will be setup in another file called init

filesize problem
i use ubuntu 9.10 and i have mountet a folder from an windows

/mount/FOLDER
/mount/FOLDER/

Help, Base64 encoding url and decoding server side.
Hello everyone, i have a website with videos and games and also provide an embed code which people c

how to put the 0-100 numbers into 1.txt and 100-200 into 2.txt ?
how to put the 0-100 numbers into 1.txt and 100-200 into 2.txt and so on 200-300 into file 3.txt ?

update sql when refresh - php
hi
I have made a table (attachement)

the users can update the sql database using + or x bu

SCO Unix
I know this might not be the place to ask, but, can anyone tell me if SCO Unix comes with PHP built

Module pool selction screen parameters combination logic
Hi floks,
Am new to the module pool development ,Recently i have created one program based on

Extract text from string
Hi folks,

I have a string that looks like this:

aaaaaaaaaa:
bbbbbbbbbb (ccccccccc)

Aris, Netweaver BPM, Visual composer and X'app
Dear Experts,

Whats the relationship between the following components: Aris, Netweaver BP

SQL Query/echo not working
Hey all,

I'm trying to run (what I thought) was a simple operation and it isn't working. I h

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