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

uploading video files into mysql in php
hi,
I have the video files which i have to upload into mysql db. along with creating thumbnails f

Connecion issue
Hi,

For some reason, I keep getting this error when trying to connect:

Warning: mysql_

How to Handle more than one submit button in single form?
Hi
I have one PHP file which contains one Form. In this form there are two Submit type Buttons

. and .. appearing instead of pictures
First of all, thanks very much for providing this forum. It is very much appreciated!

My son

Multiple Options for a Single Page
For this example I want to use the Handlers option which is under Fed Admin and all the related codi

storing video files into mysql in php
hi

i have my video files in my folder ,
i have to store the path of the videos into db an

Preg_match with an array
is there an away to use preg_match with an array?

i want to check a string with an array to s

Display certain image depending on time of year
Hi, I am new to these forums and would really appreciate some advice on a piece of coding I have don

Parse error: syntax error, unexpected T_ELSEIF in /home/......html/item.php on l
I do not know what is wrong with this. Hope some one can help. I do nto want to post the entire site

Getting Subdomain Name With PHP?
I want to grab the subdomain name with PHP so I can generate database queries.

for example my

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