Jump to content

MDanz

Members
  • Posts

    728
  • Joined

  • Last visited

Everything posted by MDanz

  1. ok i've managed to get some progress.. now it displays 5 results but no links to the next page of results <?php mysql_connect("localhost", "Master", "password"); mysql_select_db("Ustack"); $button = $_GET['submit']; $search = $_GET['search']; if(!$button){ echo "<br>You didn't submit a keyword"; }else{ if(!isset($search) || strlen($search)<=2){ echo "<br><font color=white><br>search term too short</font>"; }else{ echo "<br><br><font color=white><br>you searched for <b>$search</b></font><hr size='1'>"; } //explode our search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each){ //construct query $x++; if($x==1){ $construct .= " `keywords` LIKE '%$search_each%'"; }else{ // these both need spaces. $construct .= " OR `keywords` LIKE '%$search_each%'"; } $construct = "SELECT * FROM `Stacks` WHERE $construct"; } // How many items to show per page $limit = 5; $page = $_GET['page']; if($page){ $start = ($page - 1) * $limit; }else{ $start = 0; } $construct = $construct.' LIMIT '.$start.' , '.$limit; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); echo mysql_error(); if ($foundnum==0){ echo "<br><br><font color=white>No Stacks Found</font>"; }else{ echo "<font color=white>$foundnum <img src='http://www.u-stack.com/mini%20stack.jpg'> Found!</font><hr size='1'><p>"; echo '<table '.$margin.'>'; //here you do your loop like while ($runrows = mysql_fetch_assoc($run)){ //get data <== all thi is very not needed. $id = $runrows['id']; $name = $runrows['name']; $image = $runrows['image']; $hyperlink = $runrows['hyperlink']; $currency = $runrows['currency']; $info = $runrows['info']; $type = $runrows['type']; $rating = $runrows['rating']; echo '<td><tr>'; echo "<a href='$hyperlink'><img src='http://www.u-stack.com/Stack.jpg'></a>"; echo "</tr><font color=white><strong> $name - $info - $rating <a href='rate.php?id=$id'><img src='http://www.u-stack.com/rate.jpg'></a></center><br><br><hr size='1'></strong></font></td>"; } echo '</table>'; } // How many adjacent pages should be shown on each side? $adjacents = 3; // Your file name (the name of this file) $targetpage = "search.php"; if ($page == 0){ $page = 1; } $prev = $page - 1; $next = $page + 1; $lastpage = ceil($foundnum/$limit); $lpm1 = $lastpage - 1; $pagination = ""; if($lastpage > 1){ $pagination .= "<div class=\"pagination\">"; // Previous if ($page > 1){ $pagination .= "<a href=\"$targetpage?page=$prev\">« previous</a>"; }else{ $pagination .= "<span class=\"disabled\">« previous</span>"; } // Pages if ($lastpage < 7 + ($adjacents * 2)){ for ($counter = 1; $counter <= $lastpage; $counter++){ if ($counter == $page){ $pagination .= "<span class=\"current\">$counter</span>"; }else{ $pagination .= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } } }elseif($lastpage > 5 + ($adjacents * 2)){ if($page < 1 + ($adjacents * 2)){ for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++){ if ($counter == $page){ $pagination .= "<span class=\"current\">$counter</span>"; }else{ $pagination .= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } } } } $pagination .= "..."; $pagination .= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; $pagination .= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>"; }elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)){ $pagination .= "<a href=\"$targetpage?page=1\">1</a>"; $pagination .= "<a href=\"$targetpage?page=2\">2</a>"; $pagination .= "..."; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++){ if ($counter == $page){ $pagination .= "<span class=\"current\">$counter</span>"; }else{ $pagination .= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } } $pagination .= "..."; $pagination .= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; $pagination .= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>"; }else{ $pagination .= "<a href=\"$targetpage?page=1\">1</a>"; $pagination .= "<a href=\"$targetpage?page=2\">2</a>"; $pagination .= "..."; for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++){ if ($counter == $page){ $pagination .= "<span class=\"current\">$counter</span>"; }else{ $pagination .= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } } } // Next if ($page < $counter - 1){ $pagination .= "<a href=\"$targetpage?page=$next\">next »</a>"; }else{ $pagination .= "<span class=\"disabled\">next »</span>"; $pagination .= "</div>\n"; } } ?>
  2. Hello, i have a pagination problem. //echo out $construct $construct = "SELECT * FROM Stacks WHERE $construct LIMIT $start, $limit"; } $run = mysql_query($construct); $foundnum = mysql_num_rows($run); I'm trying to apply pagination to this. But i keep getting this error message Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/ustackc1/public_html/search.php on line 112 .. line 112 is this ... $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "<br><br><font color=white>No Stacks Found</font>"; else { echo "<font color=white>$foundnum <img src='http://www.u-stack.com/mini%20stack.jpg'> Found!</font><hr size='1'><p>"; echo '<table '.$margin.'>'; //here you do your loop like while ($runrows = mysql_fetch_assoc($run)) { //get data $id = $runrows['id']; $name = $runrows['name']; $image = $runrows['image']; $hyperlink = $runrows['hyperlink']; $currency = $runrows['currency']; $info = $runrows['info']; $type = $runrows['type']; $rating = $runrows['rating']; echo '<td><tr>'; echo "<a href='$hyperlink'><img src='http://www.u-stack.com/Stack.jpg'></a>"; echo "</tr><font color=white><strong> $name - $info - $rating <a href='rate.php?id=$id'><img src='http://www.u-stack.com/rate.jpg'></a></center><br><br><hr size='1'></strong></font></td>"; } echo '</table>'; } // How many adjacent pages should be shown on each side? $adjacents = 3; // Your file name (the name of this file) $targetpage = "search.php"; // How many items to show per page $limit = 5; $page = $_GET['page']; if($page) $start = ($page - 1) * $limit; else $start = 0; if ($page == 0) $page = 1; $prev = $page - 1; $next = $page + 1; $lastpage = ceil($foundnum/$limit); $lpm1 = $lastpage - 1; $pagination = ""; if($lastpage > 1) { $pagination .= "<div class=\"pagination\">"; // Previous if ($page > 1) $pagination .= "<a href=\"$targetpage?page=$prev\">« previous</a>"; else $pagination .= "<span class=\"disabled\">« previous</span>"; // Pages if ($lastpage < 7 + ($adjacents * 2)) { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination .= "<span class=\"current\">$counter</span>"; else $pagination .= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } } elseif($lastpage > 5 + ($adjacents * 2)) { if($page < 1 + ($adjacents * 2)) { for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($counter == $page) $pagination .= "<span class=\"current\">$counter</span>"; else $pagination .= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } $pagination .= "..."; $pagination .= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; $pagination .= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>"; } elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination .= "<a href=\"$targetpage?page=1\">1</a>"; $pagination .= "<a href=\"$targetpage?page=2\">2</a>"; $pagination .= "..."; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == $page) $pagination .= "<span class=\"current\">$counter</span>"; else $pagination .= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } $pagination .= "..."; $pagination .= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; $pagination .= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>"; } else { $pagination .= "<a href=\"$targetpage?page=1\">1</a>"; $pagination .= "<a href=\"$targetpage?page=2\">2</a>"; $pagination .= "..."; for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination .= "<span class=\"current\">$counter</span>"; else $pagination .= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } } } // Next if ($page < $counter - 1) $pagination .= "<a href=\"$targetpage?page=$next\">next »</a>"; else $pagination .= "<span class=\"disabled\">next »</span>"; $pagination .= "</div>\n"; } ?> If you recommend an easier pagination technique to implement than i one i'm using now, i'll be grateful.. i've been stuck on this for days..
  3. this is the working search engine, underneath is the pagination i have implemented. $button = $_GET['submit']; $search = $_GET['search']; if (!$button) echo "<br>You didn't submit a keyword"; else { if(!isset($search) || strlen($search)<=2) echo "<br><font color=white><br>search term too short</font>"; else { echo "<br><br><font color=white><br>you searched for <b>$search</b></font><hr size='1'>"; } mysql_connect("localhost", "Master", "password"); mysql_select_db("Ustack"); //explode our search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { //construct query $x++; if($x==1) $construct .= "keywords LIKE '%$search_each%'"; else $construct .= "OR keywords LIKE '%$search_each%'"; } //echo out $construct $construct = "SELECT * FROM Stacks WHERE $construct"; } $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "<br><br><font color=white>No Stacks Found</font>"; else { echo "<font color=white>$foundnum <img src='http://www.u-stack.com/mini%20stack.jpg'> Found!</font><hr size='1'><p>"; if($_GET['RadioGroup1']== 1 ) $margin = 'style="margin-left:60px"'; else if($_GET['RadioGroup1']== 2 ) $margin = 'style="margin-left:120px"'; else if($_GET['RadioGroup1']== 3 ) $margin = 'style="margin-left:180px"'; else if($_GET['RadioGroup1']== 4 ) $margin = 'style="margin-left:240px"'; else if($_GET['RadioGroup1']== 5 ) $margin = 'style="margin-left:300px"'; else if($_GET['RadioGroup1']== 6 ) $margin = 'style="margin-left:360px"'; else if($_GET['RadioGroup1']== 7 ) $margin = 'style="margin-left:420px"'; else if($_GET['RadioGroup1']== 8 ) $margin = 'style="margin-left:480px"'; else $margin = 'style="margin-left:0px"'; echo '<table '.$margin.'>'; while ($runrows = mysql_fetch_assoc($run)) { //get data $id = $runrows['id']; $name = $runrows['name']; $image = $runrows['image']; $hyperlink = $runrows['hyperlink']; $currency = $runrows['currency']; $info = $runrows['info']; $type = $runrows['type']; $rating = $runrows['rating']; echo '<td><tr>'; switch ($type) { case 'I': echo "<a href='$hyperlink'><img src='http://www.u-stack.com/Stack.jpg'></a>"; break; case 'M': echo "<a href='$hyperlink'><img src='http://www.u-stack.com/Stack.jpg'></a>"; break; case 'F': echo "<a href='$hyperlink'><img src='http://www.u-stack.com/Stack.jpg'></a>"; break; case 'V': echo "<a href='$hyperlink'><img src='http://www.u-stack.com/Stack.jpg'></a>"; break; case 'J': echo "<a href='$hyperlink'><img src='http://www.u-stack.com/Stack.jpg'></a>"; break; case 'D': echo "<a href='$hyperlink'><img src='http://www.u-stack.com/Stack.jpg'></a>"; break; case 'P': echo "<a href='$hyperlink'><img src='http://www.u-stack.com/Stack.jpg'></a>"; break; } echo "</tr><font color=white><strong> $name - $info - $rating <a href='rate.php?id=$id'><img src='http://www.u-stack.com/rate.jpg'></a></center><br><br><hr size='1'></strong></font></td>"; } echo '</table>'; } Now this is the pagination i have implemented. It is recognizing the results and displays the appropriate pages but doesn't put the results on those pages, they are only on page 1. On page 2 it says Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/ustackc1/public_html/search.php on line 102 // number of rows to show per page $runrowsperpage = 5; // find out total pages $totalpages = ceil($foundnum / $runrowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if $offset = ($currentpage - 1) * $runrowsperpage; $runrowsrange = 3; if ($currentpage > 1) { echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; $prevpage = $currentpage - 1; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // loop to show links to range of pages around current page for ($x = ($currentpage - $runrowsrange); $x < (($currentpage + $runrowsrange) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ Any help much appreciated.
  4. ok i've changed some stuff around i have it sort of working.. now the pagination is aware of the number of my results... but it doesn't put the appropriate amount on page on. It just lists all of them and says next page? when i click on next page then i get the errors again. you can see here.. http://www.u-stack.com/search.php?search=basketball+video&submit=search i put in the code to display 5 per page? // Number of results per page $display = 5; if(isset($_GET['page'])) { $currentPage = $_GET['page']; } else{ $currentPage = 1; } //last page $lastPage = ceil($foundnum/$display); //limit in the query thing $limitQ = 'type' .($currentPage - 1) * $display .',' .$display; //normal query and print results $construct = "SELECT * FROM Stacks $limitQ"; $run = mysql_query($construct); //here you do your loop like while($row=@mysql_fetch_object($run)) { print "$row->FieldName"; } //pagination navigation (links) //previous if ($currentPage == 1) { print "<font color=white>Prev </font>"; } else { print "<font color=white><a href=search.php?page=1>First page</a></font> "; $previousPage = $currentPage-1; print "<font color=white><a href=search.php?page=$previousPage>Previous</a></font>"; } print " {<font color=white> Page $currentPage of $lastPage </font>} "; //for next pages links if ($currentPage== $lastPage) { print "<font color=white>Next last </font>"; } else { $nextPage = $currentPage+1; print " <font color=white><a href=search.php?page=$nextPage>NEXT</a></font> "; print " <font color=white><a href=search.php?page=$lastPage>LAST</a></font> "; }
  5. can you expand on that? i typed in the correct database, username and password...
  6. mysql_connect("localhost", "Master", "password"); mysql_select_db("database"); //get the number of total rows $construct = "SELECT * FROM Stacks"; $run = mysql_query($construct); // Number of records found $foundnum = mysql_num_rows($run); // Number of results per page $display = 5; if(isset($_GET['page'])) { $currentPage = $_GET['page']; } else{ $currentPage = 1; } //last page $lastPage = ceil($foundnum/$display); //limit in the query thing $limitQ = 'LIMIT ' .($currentPage - 1) * $display .',' .$display; //normal query and print results $construct = "SELECT * FROM Stacks $limitQ"; $run = mysql_query($construct); //here you do your loop like while($row=@mysql_fetch_object($run)) { print "$row->FieldName"; } //pagination navigation (links) //previous if ($currentPage == 1) { print "Prev "; } else { print "<a href=search.php?page=1>First page</a> "; $previousPage = $currentPage-1; print "<a href=search.php?page=$previousPage>Previous</a>"; } print " { Page $currentPage of $lastPage } "; //for next pages links if ($currentPage== $lastPage) { print "Next last"; } else { $nextPage = $currentPage+1; print " <a href=search.php?page=$nextPage>NEXT</a> "; print " <a href=search.php?page=$lastPage>LAST</a> "; } ?> i get these errors It shows results are found but doesn't display the results on the page? and when i click on next page then i get those error messages?
  7. how would i go about making a new page after clicking on a result, that page is exclusive for that result. $result would be the variable. e.g. i type in search 'Car'.. the results come up. I click on the first result. Then it takes me to an exclusive page. easy or difficult?
  8. i have rows in my database howcome it isn't finding any?
  9. I changed some values of results in phpmyadmin and now the search engine doesn't work. It just displays no results found. The code is correct i'm sure, what could be wrong? <?php //get data $button = $_GET['submit']; $search = $_GET['search']; if (!$button) echo "You didn't submit a keyword"; else { if(!isset($search) || strlen($search)<=2) echo "<br><font color=white>search term too short</font>"; else { echo "<br><br><font color=white>you searched for <b>$search</b></font><hr size='1'>"; } mysql_connect("localhost", "Master", "password"); mysql_select_db("Login"); //explode our search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { //construct query $x++; if($x==1) $construct .= "keywords LIKE '$search_each'"; else $construct .= "OR keywords LIKE '$search_each'"; } //echo out $construct $construct = "SELECT * FROM Upload WHERE $construct"; } $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "<br><br><font color=white>No Stacks Found</font>"; else { echo "<font color=white>$foundnum Stacks Found!</font><p>"; if($_GET['RadioGroup1']== 1 ) $margin = 'style="margin-left:60px"'; else if($_GET['RadioGroup1']== 2 ) $margin = 'style="margin-left:120px"'; else if($_GET['RadioGroup1']== 3 ) $margin = 'style="margin-left:180px"'; else if($_GET['RadioGroup1']== 4 ) $margin = 'style="margin-left:240px"'; else if($_GET['RadioGroup1']== 5 ) $margin = 'style="margin-left:300px"'; else if($_GET['RadioGroup1']== 6 ) $margin = 'style="margin-left:360px"'; else if($_GET['RadioGroup1']== 7 ) $margin = 'style="margin-left:420px"'; else if($_GET['RadioGroup1']== 8 ) $margin = 'style="margin-left:480px"'; else $margin = 'style="margin-left:0px"'; echo '<table '.$margin.'>'; while ($runrows = mysql_fetch_assoc($run)) { //get data $name = $runrows['name']; $image = $runrows['image']; $hyperlink = $runrows['hyperlink']; $currency = $runrows['currency']; $info = $runrows['info']; $type = $runrows['type']; echo '<tr><td>'; switch ($type) { case 'I': echo '<img src="http://www.u-stack.com/Image.jpg">'; break; case 'M': echo '<img src="http://www.u-stack.com/Music.jpg">'; break; case 'F': echo '<img src="http://www.u-stack.com/File.jpg">'; break; case 'V': echo '<img src="http://www.u-stack.com/Video.jpg">'; break; case 'J': echo '<img src="http://www.u-stack.com/Job.jpg">'; break; case 'D': echo '<img src="http://www.u-stack.com/Discussion.jpg">'; break; case 'P': echo '<img src="http://www.u-stack.com/Product.jpg">'; break; } echo '</td></tr>'; } echo '</table>'; } ?>
  10. Not anything to do after this on this page. the upload page will be done. I just want it simple as possible. thx for help. I'm more innovative when it comes to design and ideas but implementing them is where i have trouble.
  11. thx for the help one again is the bolded correct?
  12. thanks i really appreciate the help. I now have Everything working on the page but in phpadmin when i check the records it says Array for each field. Its not displaying what i typed in the fields. I added $i to reference each and that works but still displays Array. Just need an understanding of this.
  13. Can i have an example please?
  14. I did this... in phpmyadmin all the fields say Array??
  15. hello again.. I've adjusted it you can see here if your logged in username:testing password:testing. www.u-stack.com/Admin.php But submit only submits one input stack of fields.. I'm guessing its hard for submit button to do multiple entry into the database...
  16. thx so much it works.. now i'll just figure out how to submit them individually... thx again
  17. Username:testing Password:testing
  18. it says your username is toddy? is that you? i've tested registration everything works fine..
  19. I tried that and same, the add button doesn't work. look here.. if you willing to register to my site... http://www.u-stack.com/Index.php when you get to the admin page.. you press the add button and nothing happens i don't know anything about javascript, so i'm not looking for that option.. i already have trouble on php
  20. thx for reply, not exactly what i'm looking for. I want to be able to add multiple stack of input fields on the press of an add button. Your code put a login form at the top and then when pressing the button GO. The input fields appeared. So i need to put the button Add in a form. Its on the same page so shall the method be 'post'? i'm a noob...
  21. the add button should echo $stacks[0].. what type of form should it be in?
  22. it just displays "you have not pressed add yet" .. when i press the add button nothing happens. Its supposed to echo the form. Any idea why?
  23. i tried this array and its not showing the input fields. any idea why? it just says "Array".
  24. ok i tried and i get, where did i go wrong? Parse error: syntax error, unexpected T_ELSE in /home/ustackc1/public_html/Admin.php on line 28
  25. i do, but i have trouble declaring a whole lot of code as a variable. is this right? $array="<p align='center'><input name='image' value='image' type='text'> <br> <input type='text' name='hyperlink'value='hyperlink'> <br> <input type='text' name='currency' value='currency'> <br> <input type='text' name='name' value='name'> <br> <input type='text' name='info' value='info'> <br> <input type='text' name='keywords' value='keywords'> <br> <input type='text' name='type' value='type'> <br> <input type='submit' value='Submit'<br></p>";
×
×
  • 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.