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!
I just can't get it work. Tried very many different versions but just can't get it to work with my php code. Always get a single line. Can anyone see what I am doing wrong?
It's probably my fault, pretty new at PHP, I may have also mixed up my columns vs rows in my original question.
Seeing a lot on how things are related to each other with your php example.
What I have is a database that has 1000's of artist and 1000's of images. I want to have a page that pulls all the images of a selected artist and displays them in 4 columns and however many rows that are needed. Some artists only have 1 image while others have 200. Anyway I can do that?
<html>
<head>
<title>A Better Example</title>
</head>
<body>
<?php
// Establishes a database connection
require_once 'db_pconnect.php';
// Sets the database record to start at
$db_row_start = 0;
// Sets the maximum number of images to return per page
$db_row_get = 24;
// Forms a query that returns more than one record
$query = 'SELECT * FROM `image` ORDER BY `title` '
. 'LIMIT '.$db_row_start.','.$db_row_get;
// Executes the query and assigns the returned resource to $result
if ($result = mysql_query($query))
{
// Sets the number of cells to display in each HTML table row
$cells_wide = 4;
// Opens a new HTML table
?><table cellspacing="0" cellpadding="3" border="1"><?php
// Opens the first HTML row
?><tr><?php
// Initializes the current cell number
$c = 0;
// Loops through each database table row
while ($row = mysql_fetch_assoc($result))
{
/*
* Determines if the current cell is the first cell of a
* table row but not the first cell of the first row
*/
if (0 < $c && 0 == $c % $cells_wide)
{
// Closes the previous HTML table row and opens a new row
?></tr><tr><?php
}
// Assigns each field to a variable of the same name (Not a good idea)
extract($row);
// Opens a new HTML table cell
?><td><?php
// Writes the contents of the current cell
echo "<div>$imgid</div><div>$title</div>";
// Closes the current HTML table cell
?></td><?php
// Increments the current cell number
$c++;
}
/*
* May require a way to insert cleanup <td>s if the total number of cells
* is not evenly divisible by the number of cells per row.
*/
// Closes the last HTML table row (or the first if there are no records)
?></tr><?php
// Closes the HTML table
?></table><?php
}
// What to do if myqsl_query() returns FALSE instead of a resource
else
{
/*
* Says "Query failed." followed by an error description.
* Don't echo mysql_error() on public sites.
*/
?><p>Query failed.</p><p><?php echo mysql_error(); ?></p><?php
}
?>
</body>
</html>
Edit: This post was recovered from search engine cache.