Formatting Data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
after_shox
Forum Newbie
Posts: 13
Joined: Wed Mar 10, 2004 11:53 am

Formatting Data

Post by after_shox »

I am building up a query with php that gets data from mysql and displays it in some nice preformated html tables i have made. It works good but i want to be able to position the boxes ( tables ) exactly where i want them. Im currently using a while loop and an echo statement to print out all of the rows into the boxes but this just prints them one after the other in a big long line. So im thinking im not doing it the right way. Any help appreciated :)
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Well instead of looping through it, how about just using the array and echo()'ing out the values?
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

or do some math and do a </tr><tr> every few loops
after_shox
Forum Newbie
Posts: 13
Joined: Wed Mar 10, 2004 11:53 am

Post by after_shox »

"Well instead of looping through it, how about just using the array and echo()'ing out the values?"

Do you mean i can call individual rows from the array ? Didnt know i could do that. Can you point me in the right direction ?
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

erm my guess if I am thinking the way sami described it:

Code: Select all

<?php
$sql = "SECECT * FROM table_name";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$user = $row["user"];

// now user would be a row in your table inside your database

?>
after_shox
Forum Newbie
Posts: 13
Joined: Wed Mar 10, 2004 11:53 am

Post by after_shox »

No that would just do the same. Can i select an individual record from the query that is returned and then call it from wherever i want ? Eg if i get 10 rows of data from the mysql table can i echo row 7 wherever i want ?
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

oh sorry for the misunderstanding.

There are a few approaches, but save yourself the time.

Add a "id" column toy our table and set it as Primary key and auto_inc.

that way when a new row of data comes into the table, it will add one from the previous row, n call it like so:

Code: Select all

<?php
$sql = "SELECT FROM table_name WHERE id='$id'";
?>
Thats the way most people do it, MySQL is awesome, use it to its full capabilites.
Post Reply