/    Sign up×
Community /Pin to ProfileBookmark

I’m trying to write a Newsletter, now i want to fetch 5 emails from the database every time i click a button, now i was able to write the code for this but the code for the other 5 i wasnt able too… this is my code … btw Ajax is running the PHP

<?php
$con = mysql_connect(“test1.ndp.net”,”test1_admin”,””);
if (!$con)
die(‘Could not connect: ‘ . mysql_error());

mysql_select_db(“test1_db”, $con);
$result = mysql_query(“SELECT email FROM table1 WHERE Ban = ‘0’”);
$ray = array();
$number = $_GET[‘number’]; //number = 5;

for($counter ; $counter<$number; $counter++) {
$row = mysql_fetch_array($result);
$ray[$counter] = $row[’email’];
}
mysql_close($con);

$string = implode(‘,’,$ray);

echo $string;

?>

I’m able to get the first 5 emails without any problem but the problem is that the second 5 i cant seem to be able to get it… i want to do it like a window of 5 emails every time i click the button i need the php to fetch 5 entries then i want to be able to send the news to the emails then when i click the button again i want to slide the window 5 places and fetch the other 5 new emails etc….

Please Help ?
Thank you for your time

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiJul 16.2009 — If I follow correctly you will need to modify your query. Since the same query is being run every time, you will only ever get the same 5 results. I'd do it using LIMIT, like so:

[code=php]
$start = intval($_GET['number']);
$end = $start + 5;
$sql = "SELECT email FROM table1 WHERE Ban = '0' LIMIT $start, $end";[/code]
Copy linkTweet thisAlerts:
@trickysergeauthorJul 16.2009 — yeah that is what i was asking about, i didnt know that there was a LIMIT thingy for MySql


thanks tons ^_^
×

Success!

Help @trickyserge 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.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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