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

Save remote XML to local website folder
Hi, I hope you can help me out. I would like to be able to pull an XML file from another site and t

Xacute search within SQL results
I have a query that is pulling data, and I want to return a specific value from the results of that

insert mysql embeded videos as blobs?
Using TinyMCE my client will be able to embed images and flash videos into large columns of text whi

MySQL-PHP Query Results Help
Hello all. I'm hoping to be able to get some help in solving a problem with query/rowcount output. I

list files from folder, only one for each date
I have many files in a folder and wish to only list one of each date

these are the file names

php multiple action on submit
I have a form which says:

<form enctype='multipart/form-data' method='post' action='pr

iMatch stored value with the current value in a loop
Hello,

I have a MySQL db were I store articles in.

I have a form to fill these article

url- go to webpage
i have an input text field and submit button.

how do i make the url entered into the textfiel

Request for tunning the below query
Hi,

Can any one help me on the below query while improving the performance,

single values into sql field
i have a form which i want the user to able to select multiple answers. But i want the answers to be

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