[PHP/MySQL] Loading data into tables from mysql
Okay so i've been trying to do this for a while but it still confuses the hell out of me
How would i load data from mysql say name, description and image and then display it in a table but be able to have the tables side by side rather than having one on top of the other and also have a limit on how many it shows like display 6 results (like bellow)?
i want it to be like this..
image1 | image2 | image3
name1 | name2 | name3
desc1 | desc2 | desc3
___________________
image4 | image5 | image6
name4 | name5 | name6
desc4 | desc5 | desc6
___________________
would it be a php array?
Re: loading data into tables from mysql?
I dont completely understand what you need, but maybe this'll work:
[preview on http://floris-web.no-ip.org/test.php also added an <u> tag there]
PHP Code:
<?php
//Fill in those
$db = 'test';
$dbuser = '';
$dbpass = '';
$host = '';
mysql_connect($host,$dbuser,$dbpass);
mysql_select_db($db);
$result = mysql_query("SELECT * FROM `table_name_here` LIMIT 6");
echo "<table cellspacing='5' style='border: 1px #000000 solid'>";
echo "<tr><th>Image</th><th>Name</th><th>Description</th></tr>";
while($row = mysql_fetch_array( $result )) {
echo "<tr><td>";
echo "<img src='" . $row['image'] . "' />"; //In your DB, put 'image' to e.x '/images/abc.gif'
echo "</td><td>";
echo $row['name'];
echo "</td><td>";
echo $row['desc'];
echo "</td></tr>";
echo "</table>";
}
?>
I hope you know it well enough to modify it for your DB/Table
Re: [PHP/MySQL] Loading data into tables from mysql
similar to that only i'd need the culumns to dow down rather than across, and be able to have 3 set of results in 3 columns going across
1st column | second column | Third Column
image | image2 | image 3
name | name 2 | name 3
desc | desc2 | desc 3
| represents a split in the table
Re: [PHP/MySQL] Loading data into tables from mysql
Look what its now, is that what you meant ?
Re: [PHP/MySQL] Loading data into tables from mysql
yeah but i'd need 3 of them tables side by side displaying diffrent results, not just one table
Re: [PHP/MySQL] Loading data into tables from mysql
Re: [PHP/MySQL] Loading data into tables from mysql
PHP Code:
$db = 'test';
$user = '';
$pass = '';
$host = '';
mysql_connect($host, $user, $pass);
mysql_select_db($db);
$result = mysql_query("SELECT * FROM table LIMIT 6");
if(mysql_num_rows($result) < 1) {
echo "Table is empty.";
} else {
echo "<table cellspacing ='10' border ='0'>
";
while($row = mysql_fetch_row($result)) {
if($i == 3) {
echo "
<tr>
";
$i = 0;
}
echo "<td>$row[something]</td>";
$i ++;
}
echo "</table>";
}
?>
This should work, if I didn't make any errors.
Also, EliteGM work on your coding style, it's absolutely horrible and unreadable.
Re: [PHP/MySQL] Loading data into tables from mysql
Lol i know i suck at standards =p
Re: [PHP/MySQL] Loading data into tables from mysql
hey pieman, i just tried it out and it's giving me this error, Parse error: syntax error, unexpected '}' in C:\Web\Apache2\htdocs\holo\t.php on line 31, i did try and move things about a bit to try and fix it but nothing seemed to work..
Re: [PHP/MySQL] Loading data into tables from mysql
Yeah, I forgot an ";" Try again, I edited it. It should work now.
Re: [PHP/MySQL] Loading data into tables from mysql
hey, just checking is if($i == 3) { meant to limit how many tables show, like 3 per line?
cause i've been changing the value and it's not been doing nothing
thanks for the code btw (Y)
Re: [PHP/MySQL] Loading data into tables from mysql
Quote:
Originally Posted by
kreechin
hey, just checking is if($i == 3) { meant to limit how many tables show, like 3 per line?
cause i've been changing the value and it's not been doing nothing
thanks for the code btw (Y)
Yup, if you for example change the 3 to a 2 then it'll do 2 tables per line.