/    Sign up×
Community /Pin to ProfileBookmark

50 pictures per row.

Hey again, i made a new topic since this is a new problem.

this time the problem i have is that the code bellow as before shows pictures on my page. but this page is supposed to show the latest 50, i cant figure out how to make the row of pictures be 5 per row like

[Picture 1][Picture 2][Picture 3][Picture 4][Picture 5]
[Picture 6][Picture 7][Picture 8][Picture 9][Picture 10]
[Picture 11][Picture 12][Picture 13][Picture 14][Picture 15]

i hope someone could help with this.

[CODE]<?
// Definiera konstanter för databasanslutning
$MYSQL_HOST = ‘aaa’;
$MYSQL_USER = ‘aaa’;
$MYSQL_PASSWORD = ‘aaa’;
$MYSQL_DATABASE = ‘aaa’;

// Anslut till databasen
mysql_connect($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD);
mysql_select_db($MYSQL_DATABASE);

// Plocka ut 7 senaste MMS
$res = mysql_query(‘SELECT *,unix_timestamp(tstamp) as utstamp FROM mms
ORDER BY tstamp DESC LIMIT 50’);

echo “<table cellspacing=”3″ cellpadding=”1″ border=”2″><tr>”;

while ($row = mysql_fetch_assoc($res)) {

echo “<td>”;
$row[‘message’] = substr($row[‘message’],strpos($row[‘message’],’ ‘));

if ( file_exists(‘data/’ . $row[‘id’] . ‘.jpeg’) ) {
$row[‘picture’] = ‘data/’ . $row[‘id’] . ‘.jpeg’;
} else $row[‘picture’] = ”;

if ( $row[‘picture’] != ” ) {
echo ‘<a href=”‘.$row[‘picture’].'”OnClick=”window.open(‘.”‘”.’visabild.php?id=’.$row[‘id’].”‘”.’,null,’.”‘”.’width=593,height=721’.”‘”.’); return false;”>’;
echo ‘<img width=”125″ src=”‘ . $row[‘picture’] . ‘”></a>’;
}

echo “</td>”;
}
echo “</tr></table>”;
?>

[/CODE]

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@scragarApr 16.2007 — I've solved this problem before, simply use the modulos division on the number of the photo and divide it by the number on a page, if the answer comes back as zero then start the new row...

[code=php]<?
$per_page = 5;

$MYSQL_HOST = 'aaa';
$MYSQL_USER = 'aaa';
$MYSQL_PASSWORD = 'aaa';
$MYSQL_DATABASE = 'aaa';

// Anslut till databasen
mysql_connect($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD);
mysql_select_db($MYSQL_DATABASE);

// Plocka ut 7 senaste MMS
$res = mysql_query('SELECT *,unix_timestamp(tstamp) as utstamp FROM mms
ORDER BY tstamp DESC LIMIT 50');

echo "<table cellspacing="3" cellpadding="1" border="2">";
$i = 0;
while ($row = mysql_fetch_assoc($res)) {
$i++;

if($i%%per_page == 1){
echo "<tr>";
};
echo "<td>";
$row['message'] = substr($row['message'],strpos($row['message'],' '));

if ( file_exists('data/' . $row['id'] . '.jpeg') ) {
$row['picture'] = 'data/' . $row['id'] . '.jpeg';
} else $row['picture'] = '';

if ( $row['picture'] != '' ) {
echo '<a href="'.$row['picture'].'"OnClick="window.open('."'".'visabild.php?id='.$row['id']."'".',null,'."'".'width=593,height=721'."'".'); return false;">';
echo '<img width="125" src="' . $row['picture'] . '"></a>';
}

echo "</td>";

if($i%%per_page == 0){
echo "</tr>";
};

}
echo "</tr></table>";
?>[/code]
Copy linkTweet thisAlerts:
@izlikauthorApr 16.2007 — Parse error: parse error, unexpected '%' in C:SitesSingle8izlikwebroot50.php on line 67

is recived ?
Copy linkTweet thisAlerts:
@izlikauthorApr 16.2007 — btw if i by the stupid topic name confused you i wanted 5 per "row" not page ?
Copy linkTweet thisAlerts:
@tcaApr 17.2007 — Try this:

[code=php]
<?
$per_page = 5;

$MYSQL_HOST = 'aaa';
$MYSQL_USER = 'aaa';
$MYSQL_PASSWORD = 'aaa';
$MYSQL_DATABASE = 'aaa';

// Anslut till databasen
mysql_connect($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD);
mysql_select_db($MYSQL_DATABASE);

// Plocka ut 7 senaste MMS
$res = mysql_query('SELECT *,unix_timestamp(tstamp) as utstamp FROM mms
ORDER BY tstamp DESC LIMIT 50');

echo "<table cellspacing="3" cellpadding="1" border="2">";

$td = 1; //set $td to 1
echo "<tr>"; //start the first row

while ($row = mysql_fetch_assoc($res)) {
echo "<td>";
$row['message'] = substr($row['message'],strpos($row['message'],' '));

if ( file_exists('data/' . $row['id'] . '.jpeg') ) {
$row['picture'] = 'data/' . $row['id'] . '.jpeg';
} else $row['picture'] = '';

if ( $row['picture'] != '' ) {
echo '<a href="'.$row['picture'].'"OnClick="window.open('."'".'visabild.php?id='.$row['id']."'".',null,'."'".'width=593,height=721'."'".'); return false;">';
echo '<img width="125" src="' . $row['picture'] . '"></a>';
}

echo "</td>"; // close the table cell
$td = $td + 1; // increment $td
if ($td == $per_page) { // just make table cells until $td == 5 then make a new row
echo '</tr><tr>'; // start a new row
$td = 1; // reset $td to 1
}
} // closing } for while loop

if ($td < $per_page) { // if $td is less than 5 after the while loop finishes, make blank cells
while ($td < $per_page) {
echo '<td></td>';
$td = $td + 1;
}
echo '</tr>'; //end the row
}
echo "</table>"; //end the table
?>
[/code]
Copy linkTweet thisAlerts:
@izlikauthorApr 17.2007 — thanks! ?

4 pictures are shown in each row when i added that code, how can i incresse and decrese it ? just so i can learn and not need to ask anymore! ?
Copy linkTweet thisAlerts:
@tcaApr 17.2007 — Ooops! You're right! Change $td = 1 to $td = 0 in both places. Don't know why I did that. :o

Now to decrease or increase change $per_page to number of columns you need.

TC
Copy linkTweet thisAlerts:
@izlikauthorApr 17.2007 — thanks for the help m8! ?
Copy linkTweet thisAlerts:
@izlikauthorApr 18.2007 — i got one more question, i get totaly confused :/ when i try ro wrewrite the code,

what im trying to do with the code above now is that insteed of making it "show" 50 pictures i need only a text saying "click here for a picture" and when a person clicks it the same link as before is opened "visabild" but insteed of a specific picture being showed i need it to search for a random picture in /data/ wich is displayed, basiclly when the text is clicked, the new window pops up and a random picture in the /data/ folder is shown. do you think you could help with that? =) the code above you have seen but the code bellow is what's currently inside visabild.php


<i>
</i>&lt;head&gt;&lt;link href="/comments/style.css" rel="stylesheet" type="text/css" /&gt;&lt;/head&gt; &lt;?php error_reporting(E_ALL ^ E_NOTICE); ?&gt; &lt;center&gt;&lt;img width="350" src="data/&lt;?=$_GET['id']?&gt;.jpeg"&gt;&lt;/center&gt; &lt;br&gt; &lt;?php include 'comments/comments.php';?&gt;
×

Success!

Help @izlik spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...