Forum Moderators: coopster
I am creating a CMS system for a client and the webpage is all positioned absolutly.
The client will be adding jobs on this like a job board and i want to make php add a new page whenever the amount of jobs is about to go over the web page height.
(e.g web page height is 660px and the amount of jobs exceeds this)
and also add a next button to the next page of results.
Hope this makes sense
I am not sure you need to make another page. Do you just want "paging"? Meaning the next/previous/first/last type links so you can go through your results?
that would work, unless you actually want a permanent page, though you should then generate these pages in advance
the steps involved would be something like
get results
figure out how many pages to make
while there are more results
-open file pointer
-add header to file
-add next bunch of results to file
-add footer to file
-close file
you would have to add in dynamic next links but that's pretty easy, you've already figured out how many pages there are and just build the set of links to the other pages
you could probably have some type of sitemap or index that had a link to every page, actually a db would be good.
the issue with this approach is that you need to make the destination directory writable, this is always a security issue
I have created an insert script that inserts data to mysql and then i created the page which displays all the data in custom boxes and now all i need is when you insert new data it creates a new web page with the rest of that specific data.
e.g i insert data for a finance manager now i want a link that will go from the data display page to the full info page on just the finance manager.
Basically the link to the job page will be something like job.php?id=2
then on job.php code like
if(isset($_GET['id']) && ctype_digit($_GET['id'])){
$id = $_GET['id'];
//check this id exists in db
}else{
$id = 0;
}if($id == 0){
echo "no such job";
}else{
//show correct job
}
job_id (PRIMARY KEY INT)
job_title (varchar 255)
job_description(text)
application_date_ends(datetime)
$q = @mysql_query("SELECT job_id,job_title FROM job ORDER by application_date_ends ");
while($r = @myqsl_fetch_array($q)){
echo "<p><a href=\"www.example.com/job/job-info.php?id=".$r['job_id']."\">".$r['job_title']."</a></p>";
}
The above is without any pagination work done to it but there are tutorial on the net on how to do this.
Next on your job-info.php page you would have something like
if(isset($_GET['id']) && ctype_digit($_GET['id'])){
$id = $_GET['id'];
$q = @mysql_query("SELECT 1 FROM job WHERE job_id = $id");
if(@mysql_num_rows($q) == 1){ // we have a match
$id= $id;
}else{
$id = 0;
}
}else{
$id = 0;
} if($id == 0){
echo "<p>You have selected an invalid job. Please return to the job index</p>";
}else{
$q = @mysql_query("SELECT * FROM job WHERE job_id = $id");
//show results from DB including description and date this time
}
[edited by: dreamcatcher at 3:02 pm (utc) on June 24, 2009]
[edit reason] use example.com. Thanks. [/edit]
Im sure i'm missing something but i cant for the life of me think what, i know it's a small thing.
<?php
$mysqli = mysqli_connect("#*$!x.#*$!x.co.uk", "#*$!#*$!#*$!2", "#*$!#*$!xx", "#*$!#*$!#*$!x");
if (mysqli_connect_errno()) {
printf("Connect Failed: %s\n", mysqli_connect_error());
exit();
} else {
if(isset($_GET['id']) && ctype_digit($_GET['id'])){
$id = $_GET['id'];
//check this id exists in db
}else{
$id = 0;
}
if($id == 0){
echo "no such job";
}else{
//show correct job
echo "<div id='border'>";
echo "<div class='bg'><div class='subject'><b>Ref: ".$id." - </b> ".$title."</div> <div class='salary'>".$salary."</div> </div>";
echo "<div class='body'>".$short."</div>";
echo "<div class'info'><a href='template/job-info.php?id=$id'>More information</a></div>";
echo "<div class='bg'><div class='footer'><a href='mailto:info@example.com'>Click to respond</a></div> </div>";
echo "</div><br>";
}
}
?>
[edited by: dreamcatcher at 3:02 pm (utc) on June 24, 2009]
[edit reason] use example.com. Thanks. [/edit]
<?php
$mysqli = mysqli_connect("#*$!#*$!xx", "#*$!#*$!#*$!x", "#*$!#*$!#*$!", "#*$!#*$!#*$!x");
if (mysqli_connect_errno()) {
printf("Connect Failed: %s\n", mysqli_connect_error());
exit();
} else {
if(isset($_GET['id']) && ctype_digit($_GET['id'])){
$id = $_GET['id'];
$mysqli = @mysql_query("SELECT 1 FROM job_board WHERE id = $id");
if(@mysql_num_rows($mysqli) == 1){ // we have a match
$id = $id;
}else{
$id = 0;
}
}else{
$id = 0;
}
}
if($id == 0){
echo "<p>You have selected an invalid job. Please return to the job index</p>";
}else{
$mysqli = @mysql_query("SELECT * FROM job_board WHERE id = $id");
//show results from DB including description and date this time
}
?>
I don't know where i would be going wrong, i know that the main data shouldn't be coming up because i haven't asked for it but at least i should be getting is a blank screen and not the custom error.
if (mysqli_connect_errno()) {
printf("Connect Failed: %s\n", mysqli_connect_error());
exit();
} else {
$sql = "SELECT * FROM job_board";
$res = mysqli_query($mysqli, $sql);
if($res) {
while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
$id = $newArray['id'];
$title = $newArray['title'];
$short = $newArray['short'];
$salary = $newArray['salary'];
$end_date = $newArray['end_date'];
echo "<div id='border'>";
echo "<div class='bg'><div class='subject'><b>Ref: ".$id." - </b> ".$title."</div> <div class='salary'>".$salary."</div> </div>";
echo "<div class='body'>".$short."</div>";
echo "<div class'info'><a href=\"template/job-info.php?id=".$id."\">More information</a></div>";
echo "<div class='bg'><div class='footer'><a href='mailto:info@example.com'>Click to respond</a></div> </div>";
echo "</div><br>";
}
} else {
printf("Could not retrieve records: %s\n", mysqli_error($mysqli));
}
mysqli_free_result($res);
mysqli_close($mysqli);
}
this lists all the jobs from the mysql database, this works.
then the one above was supposed to display the specific data of a job after clicking on it in the "jop-info.php"
[edited by: dreamcatcher at 3:01 pm (utc) on June 24, 2009]
[edit reason] use example.com. Thanks. [/edit]