Jump to content
Larry Ullman's Book Forums

Displaying Records In A Table (Three Records Per Row)


Recommended Posts

I am using the scripts in the 2nd edition and am trying to call records from the mysql dbase and arrange them into a table with three records to each row.

 

I hope it is possible but all the suggestions I have found so far dont work. (maybe because the suggestions are for more advanced versions of php?).

 

I can display records one row at a time (and am even using the pagination script to paginate every 6 records) however every time I try and get three records on the same row I fail.

 

The following is from a script that is working great (used to be script 13.6 ) - but only shows one record per row. Does anyone know how this can become three records per row?..I only really need to have three images per row as this is a gallery (and each images was to act as a link to a page of its own where it could be viewed on its own as much bigger).

 

Sorry for long-winded request.

 

Thanks

 

 

 


echo '<table border="0" width="94%" cellspacing="13" cellpadding="10" align="center">
<tr>
</tr>';
// Display all the URLs.
$result = mysql_query ($query);
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
// Display each record.
echo " <tr>
<td rowspan=\"4\" align=\"left\"><img src=\"Uploads/{$row['image_name']}\"width=\"250\" $image[3] alt=\"{$row['print_name']}\" /></td>
<td align=\"left\">Title : <font=\"Agency FB\" size=\"+1\"><b><a href=\"view_print.php?pid={$row['print_id']}\">{$row['print_name']}</a></b></font></td></tr>
<tr><td align=\"left\">Description : " . stripslashes($row['description']) . "</td></tr>
<tr><td align=\"left\">Price : £{$row['price']}</td></tr>
<tr><td align=\"left\">Status : {$row['type']}</td>
</tr>\n";

} // End of while loop.

echo '</table>'; // Close the table.
mysql_close(); // Close the database connection.

Link to comment
Share on other sites

I am grateful for your replies Antonio and Margaux -

 

Antonio - could I humbly ask you to show me how you would switch from the table to divs? The two records I need here are the image 'image_name' and the link

<a href=\"view_print.php?pid={$row['print_id']}\">{$row['print_name']}</a>

to the bigger picture in another page?

Link to comment
Share on other sites

I have managed to get the Images as links to their own pages OK.

However I am having problems getting three images in a row - this code still has them in a single column down the page , however everything else seems to be working now. I have added div tags but they dont seem to make a difference?

 

 

 

echo '<DIV width=\"30%\"; float:left;'>

// Display all the Paintings.

$result = mysql_query ($query);

while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {

 

// Display each record.

echo "

 

<a href=\"view_print.php?pid={$row['print_id']}\"><br><br>

<img src=\"Uploads/{$row['image_name']}\"width=\"250\" $image[3] alt=\"{$row['print_name']}\" /></a>

\n";

 

 

} // End of while loop.

echo '</DIV>'; // Close the div.

 

All I want to do is get three paintings (icons?) in a row, then go on to the second row ets.. any suggestions are most welcome.

Link to comment
Share on other sites

Thanks Rob but I am not getting there. Appreciate the advice though. This is the code I have now - you see the div tags are around every link + Image. The links work - they go to the pages theyre supposed to.

 

The div tags dont unfortunately - I still have a column of images down the LHS of the page. Any advice?

 

// Display all the Paintings.

$result = mysql_query ($query);

while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {

// Display each record.

echo "<DIV width=\"33%\"; float:left;'><a href=\"view_print.php?pid={$row['print_id']}\"></DIV><br><br>

<DIV width=\"33%\"; float:left;'><img src=\"Uploads/{$row['image_name']}\"height=\"130\" $image[0] alt=\"{$row['print_name']}\" /></a></DIV>

\n";

} // End of while loop.

mysql_close(); // Close the database connection.

Link to comment
Share on other sites

This is really basic HTML CSS, wildman. If you're not comfortable with it I would recommend you pick up a good book or follow an online tutorial to learn the basics.

 

As for your question, one div element should go around <a href="... > <img src="... > </a>, but you're not even doing inline css styling correctly:

 

<div style="width: 33%; float: left;">

Link to comment
Share on other sites

I guess courtesy demands I should offer you an answer Rob.

 

No I dont know a lot about a lot of things. Thats perhaps why I am asking for help. I have worked hard on Larry's Book and have been able to make some websites that I am proud of.

 

As you will see from my newbie status I do not make a habit of asking experts difficult (to me ) questions. I only had one question and I thought it was reasonable to ask it. I was even hoping someone might suggest to me the code I needed - which incidentally doesnt seem so bad - I would then have thanked them and left you - clearly someone who is irritated by my basic knowledge - in peace,.I am not particularly interested in becoming an advanced member like youself.

 

I guess my prospects of receiving further assistance from this forum has been compromised now that you have had your say.

Link to comment
Share on other sites

The thing is, no-one will code a working solution for you. We are providing you some steps on the way to do what you want, thought.

 

A tip. Strip out all HTML from the code her. Then start playing with getting the divs right. Search on an article on float in CSS if you get problems with the styling.

 

Don't try to get everything done at once. Make it work step by step.

 

Writing on mobile now. Formatting my computer at the moment. I'll provide some code later if no-one else does it.

Link to comment
Share on other sites

Try something like this

// Display all the Paintings.
$result = mysql_query ($query);
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
// Display each record.
echo "<div class=\"prints\"><a href=\"view_print.php?pid={$row['print_id']}\">
<img src=\"Uploads/{$row['image_name']}\"height=\"130\" $image[0] alt=\"{$row['print_name']}\" /></a></div>
\n";
} // End of while loop.
mysql_close(); // Close the database connection.

The above code outputs your html, then you need to style it to make it look nice. You should avoid mixing html and css in code as you originally did for a number of reasons which you can read about. Presumably you have an external stylesheet? Add the following to that file, though you may need to adjust the margins and padding.

.prints {
width:33%;
float:left;
padding:10px;
}

 

If you dont have an external filesheet, you should. But if this is just practice you can add the styling to the head section of your page - just surround the css code with <style></style> tags.

 

rob is right - this thread is for php and you're asking questions about basic html and css. Ask away, just do it in the right place.There are loads of resources on and offline that will teach you what you need to know. One book that looks pretty good is HTML5 and CSS3, published by the same publishers that Larry uses. Its good as it will intro you to HTML and CSS and then show you some HTML5 and CSS3 additions. Spend some time learning the basics and you'll save yourself alot of time in the long run. Oh, and NEVER use all caps for your html tags.

Link to comment
Share on other sites

Thanks Margaux, It sounds like sound advice and I will do as you suggest on both the book and the code.

 

To answer your question - yes I do have an external style sheet.

 

Please notice though that what I originally asked was based on the book code, - I did not imagine I would end up looking at div tags & html/css.

Link to comment
Share on other sites

It's kind of the name of the game, unfortunately. PHP is mostly used for web development, and therefor it kind of requires knowledge on HTML and CSS. The main goal is of course to create a dynamic website, and a website needs HTML and CSS. Luckily for you, learning HTML and CSS is relativly easy compared to learning to code. If I where you, I'd focus on getting the coding part right, then start playing with html later.

 

I would just download a page template you like. That way, you can focus on PHP and still get a good enough visual impression.

 

I guess Rob was a little hard on you because it did not seem like you were trying that hard. If you are really stuck, you will get help with "dumb questions" here anyway. It's a good community. ;)

 

Good luck.

Link to comment
Share on other sites

 Share

×
×
  • Create New...