Page 1 of 1

Formatting Data

Posted: Tue Mar 23, 2004 2:59 pm
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 :)

Posted: Tue Mar 23, 2004 3:52 pm
by m3mn0n
Well instead of looping through it, how about just using the array and echo()'ing out the values?

Posted: Tue Mar 23, 2004 4:00 pm
by magicrobotmonkey
or do some math and do a </tr><tr> every few loops

Posted: Tue Mar 23, 2004 4:17 pm
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 ?

Posted: Tue Mar 23, 2004 5:00 pm
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

?>

Posted: Wed Mar 24, 2004 12:33 pm
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 ?

Posted: Wed Mar 24, 2004 4:18 pm
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.