Jump to content

stan801003

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

stan801003's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. In case anybody wants to know the answer i forgot to add the max results part to the first query, so it's all working now
  2. Ok i have put together a mysql join query with a sub query to allow me to get all the information i need from 4 database tables. Now i have managed to get this to work fine, it returns all the information i need perfectly. The problem i am having is with the pagination. I have a script that i use for everything and it works great however i can not get it to work with this query. When the page is called it displays all of the information as should be and places the individual page numbers at the bottom of the screen but still display all of the rows within the database. I would be very grateful for any advice or guidance, Stan if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } // Define the number of results per page $max_results = 1; // Figure out the limit for the query based // on the current page number. $from = (($page * $max_results) - $max_results); // Perform MySQL query on only the current page number's results $candidate_id =3; $sql = "SELECT joborder.title, joborder.site_id, candidate_joborder.date_submitted, candidate_joborder.status,candidate_joborder_status.short_description, candidate_joborder.site_id FROM joborder JOIN candidate_joborder ON joborder.joborder_id = candidate_joborder.joborder_id JOIN candidate_joborder_status ON candidate_joborder_status.candidate_joborder_status_id = candidate_joborder.status WHERE candidate_id = '$candidate_id' ORDER BY title"; $result = mysql_query($sql) or die(mysql_error()); //Iterate through each factory if ($result) { while($row = mysql_fetch_array($result)) { //Now create a second query to get details for this factory $sql = "select name from site where site_id=" . $row['site_id']; $result2 = mysql_query($sql) or die(mysql_error()); $row2 = mysql_fetch_array($result2); //Generate <set name='..' value='..' /> mysql_free_result($result2); </td> </tr> </table> <table width="100%" border="0"> <tr> <td width="115" bgcolor="#E2E6EF"><?php echo $row['title']; ?> </td> <td width="121" bgcolor="#E2E6EF"><?php echo $row2['name']; ?> </td> <td width="155" bgcolor="#E2E6EF"><?php echo $row['short_description']; ?> </td> <td width="134" bgcolor="#E2E6EF"><?php echo $row['date_submitted']; ?> </td> </tr> </table> <table width="100%" border="0"> <tr> } } // Figure out the total number of results in DB: $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM joborder JOIN candidate_joborder ON joborder.joborder_id = candidate_joborder.joborder_id JOIN candidate_joborder_status ON candidate_joborder_status.candidate_joborder_status_id = candidate_joborder.status WHERE candidate_id = '$candidate_id' ORDER BY title"),0); // Figure out the total number of pages. Always round up using ceil() $total_pages = ceil($total_results / $max_results); // Page Number Hyperlinks // Previous Link if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev&candidate_id=$candidate_id\"><<Back</a> "; } // Page Numbers for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "<strong><font size=2 face=calibri color=#336699>Page $i of $total_pages Total Pages</font></strong>"; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i&candidate_id=$candidate_id\">[ $i ]</a> "; } if(($i + 30) % 30 == 0) { echo '</td></tr><tr><td colspan=4 align=center>'; } } // Next Link if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next&candidate_id=$candidate_id\">Next>></a>"; } echo "</center>";
  3. Hi, the paging is for the result pages of a search query, i wanted to show five results per page, and the number of viewable pages along the bottom.  This script returns the first results page and shows the pages along the bottom of the page, but it does not link to the next results page.  No matter what i do, it only ever seems to return one page of results.  Be it 1 result or ten, but never links to the second page. I have tried a number of different things, including a whole new script, but the same thing keeps happening.
  4. Hi, I have download a paging script, but whilst it works, it only returns the first five records.  Whilst this is the number that is set to show, the other records from the database do not roll over on to the next page.  Can anybody please pointme in the right direction. [code=php:0] if(!isset($start)) {                        // This variable is set to zero for the first page $start = 0; } $eu = ($start -0);                $limit = 5;                                // No of records to be shown per page. $this = $eu + $limit; $back = $eu - $limit; $next = $eu + $limit; /////////////// WE have to find out the number of records in our table. We will use this to break the pages/////// $query2=" SELECT * FROM vacancies  "; $result2=mysql_query($query2); echo mysql_error(); $nume=mysql_num_rows($result2); /////// The variable nume above will store the total number of records in the table//// /////////// Now let us print the table headers //////////////// $bgcolor="#f1f1f1"; echo "<TABLE width=50% align=center  cellpadding=0 cellspacing=0> <tr>"; echo "<td  bgcolor='dfdfdf' >&nbsp;<font face='arial,verdana,helvetica' color='#000000' size='4'>ID</font></td>"; echo "<td  bgcolor='dfdfdf' >&nbsp;<font face='arial,verdana,helvetica' color='#000000' size='4'>Name</font></td>"; echo "<td  bgcolor='dfdfdf' >&nbsp;<font face='arial,verdana,helvetica' color='#000000' size='4'>Class</font></td>"; echo "<td  bgcolor='dfdfdf'>&nbsp;<font face='arial,verdana,helvetica' color='#000000' size='4'>Mark</font></td></tr>"; ////////////// Now let us start executing the query with variables $eu and $limit  set at the top of the page/////////// $query=" SELECT * FROM vacancies  limit $eu, $limit "; $result=mysql_query($query); echo mysql_error(); //////////////// Now we will display the returned records in side the rows of the table///////// while($noticia = mysql_fetch_array($result)) { if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';} else{$bgcolor='#f1f1f1';} echo "<tr >"; echo "<td align=left bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='2'>$noticia[id]</font></td>"; echo "<td align=left bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='2'>$noticia[jobtitle]</font></td>"; echo "<td align=left bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='2'>$noticia[location]</font></td>"; echo "<td align=left bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='2'>$noticia[salary]</font></td>"; echo "</tr>"; } echo "</table>"; ////////////////////////////// End of displaying the table with records //////////////////////// ///// Variables set for advance paging/////////// $p_limit=8; // This should be more than $limit and set to a value for whick links to be breaked if(!isset($p_f)){$p_f=0;} $p_fwd=$p_f+$p_limit; $p_back=$p_f-$p_limit; //////////// End of variables for advance paging /////////////// /////////////// Start the buttom links with Prev and next link with page numbers ///////////////// echo "<table align = 'center' width='50%'><tr><td  align='left' width='20%'>"; if($p_f<>0){print "<a href='$page_name?start=$p_back&p_f=$p_back'><font face='Verdana' size='2'>PREV $p_limit</font></a>"; } echo "</td><td  align='left' width='10%'>"; //// if our variable $back is equal to 0 or more then only we will display the link to move back //////// if($back >=0 and ($back >=$p_f)) { print "<a href='$page_name?start=$back&p_f=$p_f'><font face='Verdana' size='2'>PREV</font></a>"; } //////////////// Let us display the page links at  center. We will not display the current page as a link /////////// echo "</td><td align=center width='30%'>"; for($i=$p_f;$i < $nume and $i<($p_f+$p_limit);$i=$i+$limit){ if($i <> $eu){ $i2=$i+$p_f; echo " <a href='$page_name?start=$i&p_f=$p_f'><font face='Verdana' size='2'>$i</font></a> "; } else { echo "<font face='Verdana' size='4' color=red>$i</font>";}        /// Current page is not displayed as link and given font color red } echo "</td><td  align='right' width='10%'>"; ///////////// If we are not in the last page then Next link will be displayed. Here we check that ///// if($this < $nume and $this <($p_f+$p_limit)) { print "<a href='$page_name?start=$next&p_f=$p_f'><font face='Verdana' size='2'>NEXT</font></a>";} echo "</td><td  align='right' width='20%'>"; if($p_fwd < $nume){ print "<a href='$page_name?start=$p_fwd&p_f=$p_fwd'><font face='Verdana' size='2'>NEXT $p_limit</font></a>"; } echo "</td></tr></table>"; [/code]
  5. I modified a script i downloaded to work in my web pages, the problem is, the results no longer show since i have modified the select query.  With the original script it just selected all entries from the database.  I have since tried to change the queryy to select the category and location from the index page.  However it does not show the results.  The original query still works on another page but where i have tried to update this script the query no longer works.  I would be grateful of any suggestions or pointers.  Thanks <? $db_addr = 'localhost'; // address of MySQL server. $db_user = ''; // Username to access server. $db_pass = ''; // Password access server. $db_name = ''; // Name of database to connect to. $connect = @mysql_connect("$db_addr", "$db_user", "$db_pass"); if (!($connect)) // If no connect, error and exit(). { echo("<p>Unable to connect to the database server.</p>"); exit(); } if (!(@mysql_select_db($db_name))) // If can't connect to database, error and exit(). { echo("<p>Unable to locate the $db_name database.</p>"); exit(); } $category = $_POST["category"] ; $location = $_POST["location"] ; if (!($limit)){ $limit = 10;} // Default results per-page. if (!($page)){ $page = 0;} // Default page value. $numresults = mysql_query("SELECT * FROM vacancies WHERE category = '$category' AND location = '$location' LIKE '%". $query ."%'"); // the query. $numrows = mysql_num_rows($numresults); // Number of rows returned from above query. if ($numrows == 0){ echo("No results found matching your query - $query"); // bah, modify the "Not Found" error for your needs. exit();} $pages = intval($numrows/$limit); // Number of results pages. // $pages now contains int of pages, unless there is a remainder from division. if ($numrows%$limit) { $pages++;} // has remainder so add one page $current = ($page/$limit) + 1; // Current page number. if (($pages < 1) || ($pages == 0)) { $total = 1;} // If $pages is less than one or equal to 0, total pages is 1. else { $total = $pages;} // Else total pages is $pages value. $first = $page + 1; // The first result. if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) { $last = $page + $limit;} //If not last results page, last result equals $page plus $limit. else{ $last = $numrows;} // If last results page, last result equals total number of results. //escape from PHP mode. ?> <title>Search Results for <?=$query?></title> <center><h2>Search Results for <?=$query?></h2></center> <table width="100%" border="0"> <tr>   <td width="50%" align="left"> Results <b><?=$first?></b> - <b><?=$last?></b> of <b><?=$numrows?></b>   </td>   <td width="50%" align="right"> Page <b><?=$current?></b> of <b><?=$total?></b>   </td> </tr> <tr>   <td colspan="2" align="right">&nbsp;   </td> </tr> <tr>   <td colspan="2" align="right"> Results per-page: <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=5">5</a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=10">10</a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=20">20</a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=50">50</a>   </td> </tr> </table> <? //Go back into PHP mode. // Now we can display results. $results = mysql_query("SELECT * FROM vacancies WHERE category = '$category' AND location = '$location' LIKE '%". $query ."%' ORDER BY jobtitle ASC LIMIT $page, $limit"); while ($data = mysql_fetch_array($results)) {$ ?> <p><a href="<?=$data["jobtitle"]?>" title="<?=$data["location"]?>"><?=$data["salary"]?></a> - <?=$data["date"]?></p> <? } ?> <p align="center"> <? if ($page != 0) { // Don't show back link if current page is first page. $back_page = $page - $limit; echo("<a href=\"$PHP_SELF?query=$query&page=$back_page&limit=$limit\">back</a>    \n");} for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it. { $ppage = $limit*($i - 1); if ($ppage == $page){ echo("<b>$i</b> \n");} // If current page don't give link, just text. else{ echo("<a href=\"$PHP_SELF?query=$query&page=$ppage&limit=$limit\">$i</a> \n");} } if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link. $next_page = $page + $limit; echo("    <a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\">next</a>\n");} ?>
  6. Hi, Can anybody give me some ideas please.  I have been working on a script where a search query returns  the results of a search.  To save space the table only shows a couple of the fields.  what i am trying to achieve is that one of the fields provides a link which when clicked will display all of that entries in that row of the database.  I have been playing around with href, but i can not get it to link to a row, as it just keeps coming up with a 404 error. Any suggestions or ideas would be appreciated thanks.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.