Forum Thread
  Posts  
A question on PHP and mysql (Forums : Coding & Scripting : A question on PHP and mysql) Locked
Thread Options
PsychoFarmer
PsychoFarmer modDB King
Apr 4 2004 Anchor

i currently have my gallery section throwing the links all in a line. however, i want it to insert a line break after every 5 links.

i would want it to look like

| link | link | link | link | link |
| link | link | link | link | link |
| link | link | link | link | link |

that ^

the only problem is im not quite sure how to go about doing that. the code i have now is...

<?php
$title = "Gallery";
$update = "29 Dec 2003";
include ("head.php");

echo ("<h2>The Minions of Evil</h2> |");

// this should fetch all of the images in the gallery, evil then good:

$egallery_r = mysql_query ("SELECT * FROM `gallery` ORDER BY `id` ASC");
$egallery = mysql_fetch_object ($egallery_r);
$ggallery_r = mysql_query ("SELECT * FROM `gallery` ORDER BY `id` ASC");
$ggallery = mysql_fetch_object ($ggallery_r);

// time to actually get the info, first the evil

while ($egallery = mysql_fetch_object ($egallery_r)) {
$info = $egallery->title;
$url = $egallery->id;
$catagory = $egallery->catagory;

if ($catagory == "evil") {
echo ("
<a href="images/gallery/$url.jpg" target="new">$info</a> |
");
}
}


echo ("<h2>The Vanquishers of Darkness</h2>| ");

// now the good

while ($ggallery = mysql_fetch_object ($ggallery_r)) {
$info = $ggallery->title;
$url = $ggallery->id;
$catagory = $ggallery->catagory;

if ($catagory == "good") {
echo ("
<a href="images/gallery/$url.jpg" target="new">$info</a> |
");
}
}


include ("foot.php");
?>

any help?

- Edited By PsychoFarmer On Sat 3rd, Apr 2004 @ 10:58:05pm

--

___________________________
Today seems like a good day to burn a bridge or two
I am the freakiest man in the world!!!!
I beg to differ, on the contrary, I agree with every word that you say

User Posted Image

Apr 4 2004 Anchor

Just have it while through results while x is below or equal to 5.

Then in the while loop add one to xx ($x++) and if($x > 6) echo </-br-/>; reset $x

--

Why wont it save me?

PsychoFarmer
PsychoFarmer modDB King
Apr 4 2004 Anchor

so add the while loop inside of the current while loop?

--

___________________________
Today seems like a good day to burn a bridge or two
I am the freakiest man in the world!!!!
I beg to differ, on the contrary, I agree with every word that you say

User Posted Image

Apr 4 2004 Anchor

*looks at post* not what I said.

Something roughly like this

$x = 0;

while ($x &lt; 6)
{if($x = 5)
{echo &quot;&lt;/tr&gt;&lt;tr&gt;&quot;;//end of row, new row time
$x = 0;}}//set x back to normal

--

Why wont it save me?

PsychoFarmer
PsychoFarmer modDB King
Apr 5 2004 Anchor

but i want more than 5 there... i just want it formatted in blocks of 5

im thinking that ill just have it do an if statement

how would i have to tell if x is a multiple of 5 though?

--

___________________________
Today seems like a good day to burn a bridge or two
I am the freakiest man in the world!!!!
I beg to differ, on the contrary, I agree with every word that you say

User Posted Image

Apr 5 2004 Anchor

Thats why $x is reset.

Notice;

if x is 5
echo html stuff
set x back to 0.

Also you need to run this while in your main while for results you know.

--

Why wont it save me?

PsychoFarmer
PsychoFarmer modDB King
Apr 5 2004 Anchor

PsychoFarmer wrote: so add the while loop inside of the current while loop?

azz0r wrote: Also you need to run this while in your main while for results you know.

:?

--

___________________________
Today seems like a good day to burn a bridge or two
I am the freakiest man in the world!!!!
I beg to differ, on the contrary, I agree with every word that you say

User Posted Image

Apr 5 2004 Anchor

Why the question mark, you answered your question.

--

Why wont it save me?

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.