Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-20-2007, 02:08 AM   #1 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
PHP Display Data

Hi Everyone, hows it going?

I'm currently using the following code, inoder to create a table like structure on a page:

.cell
{
left: 0px;
top: 0px;
width: 100px;
height: 100px;
position: relative;
margin-left: 10px;
margin-bottom: 10px;
float: left;
}

how do i display all the first names and last names, stored in the database, inside different boxes, like a table? See below

Code:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM person");

while($row = mysql_fetch_array($result))
  {
  echo $row['FirstName'] . " " . $row['LastName'];
  echo "<br />";
  }

mysql_close($con);
?>
| FIRSTNAME | LASTNAME |
| Brian | Tims |
| Stuart | Holmes |

Many Thanks,
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 03-20-2007, 06:39 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,695
redhead is on a distinguished road
Have you tried
PHP Code:
echo "<table> <tr><td>Firstname</td><td>Lastname</td></tr>";
while(
$row mysql_fetch_array($result))
  {
  echo 
"<tr><td>" $row['FirstName'] . "</td><td> " $row['LastName'] . "</td></tr>";
  }
echo 
"</table>"
??

And please dont post two threads about the same thing, edit your previus post to reflect the code, or add a reply to the thread containing your code.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 03-20-2007, 07:20 AM   #3 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
PHP Display Data

Redhead,

I'm trying to use CSS instead of tables, do you know how to display the data within the database inside separate divs, using the CSS declaration i gave you earlier?

For a diagram on what I'm trying to achieve, CLICK HERE

Sorry for duplicating posts!!!

Many Thanks,
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 03-20-2007, 12:34 PM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,471
sde is on a distinguished road
i think this would work
HTML Code:
<div>
  <div style="float:left;">firstname</div>
  <div>lastname</div>
</div>
<div>
  <div style="float:left;">firstname</div>
  <div>lastname</div>
</div>
__________________
Mike
sde is offline   Reply With Quote
Old 03-20-2007, 01:51 PM   #5 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
PHP Display Data

SDE,

Using the code at the below link, how do I load all data from the database, but only display one piece of information i.e. Firstname or Lastname per div, in order to create a tabular structure, as shown in the diagram linked below.

Many Thanks,
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 03-20-2007, 03:03 PM   #6 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 660
DJMaze is on a distinguished road
You ever heard of "display: table-cell"?
http://www.w3schools.com/css/pr_class_display.asp
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 03-20-2007, 04:44 PM   #7 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,471
sde is on a distinguished road
that's cool, i didn't know about that.

Salch, u got a problem with your layout. if you stretch it out, it's going to to display more than 2 columns. example:

first | last | first|
last

however, if you wanted to use that HTML for your display output, your php would look something like this:
PHP Code:
while($row mysql_fetch_array($result))
  {
  echo 
"<div class=\"But\">"$row['FirstName'] . "</div><div class=\"But\">"$row['LastName'] . "</div>\n";
  } 
__________________
Mike
sde is offline   Reply With Quote
Old 03-20-2007, 04:51 PM   #8 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,471
sde is on a distinguished road
Quote:
Originally Posted by DJMaze View Post
You ever heard of "display: table-cell"?
http://www.w3schools.com/css/pr_class_display.asp
djm, renders nicely in FF, .. any way to be able to use that with IE?
Code:
<style>
.cell {
  display: table-cell;
  width: 150px;
  border: 1px solid red;
  padding: 10px;
  margin: 0px;
}

.cell_left {
  float:left;
}
</style>

<div>
  <div class="cell">First</div>
  <div class="cell">Last</div>
</div>
<div>
  <div class="cell">First</div>
  <div class="cell">Last</div>
</div>
<div>
  <div class="cell">First</div>
  <div class="cell">Last</div>
</div>
__________________
Mike
sde is offline   Reply With Quote
Old 03-21-2007, 12:24 AM   #9 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
Xampp - Apache

I'm trying to create a web-based application, using Xampp - Apache Server.
My creation along with the server will be run on a standalone pc.

Does anybody know if it is at all possible to lock people out of the HTDOCS folder, in order to avoid people from steeling my .html and .php code?

Many Thanks,
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 03-21-2007, 05:16 AM   #10 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 660
DJMaze is on a distinguished road
Quote:
Originally Posted by sde View Post
djm, renders nicely in FF, .. any way to be able to use that with IE?
As with many web-standards...... NO
But as always, there are people listed at google who do create workarounds

Mostly i just generate CSS thru php and:
PHP Code:
if (MSIE)  {
    echo 
'
/* stupid IE never heard of standards */
    .table { display: block; width: 200px; }
    .table-cell { display: block; width: 80px; float: left; }
'
;
} else {
    
/* you have a cool browser */
    
echo '
    .table { display: table; }
    .table div { display: table-cell; }
'
;

__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending arbitrary PHP data to HTML forms saul PHP 12 03-14-2005 08:27 AM
Control table display with php & Postgresql? tomycon PHP 2 07-17-2002 07:16 AM
Passing form data to PHP with Javascript bdl PHP 5 07-03-2002 10:18 AM


All times are GMT -8. The time now is 04:08 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting