Jump to content

squiblo

Members
  • Posts

    483
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by squiblo

  1. sorry ill explain it a bit better, the page numbers below the results are infinate depending on the amount of results and the results per page, the page numbers can go above ten but i do not think that is user friendly... i tried this but on the 10th page the option to click next is not linked and will not allow you to view page 11... $maxPages = ceil($foundnum / $perPage); //may come out as a decimal if ($maxPages > 10) $maxPages = 10;
  2. indicating what page i am on is perfect now, the last thing is only echoing 10 page numbers at a time when $maxPages => 10
  3. i have a pagination script working fine but the numbers at the bottom do not indicate what page i am currently on, how can change this to show that i am currently on page 5 for example by making the number 5 bold or underlined <?php for ($i=1; $i<=$maxPages; $i++) echo ($i === $page) ? $i .' ' : '<a href="?page='. $i . (strlen($search) ? '&search=' . $search : '') .'" class="pagenumbers">'. $i .'</a> '; ?>
  4. change $maxPages = floor($count/$perPage); to $maxPages = ceil($count/$perPage);
  5. ive modified the code slightly here is it... <html> <body> <p> <form action="resultstest.php" method="GET"> <input type="text" name="search" /><br/> <input type="submit" value="search" /><br/> </p> </form> </body> </html> <?php //connect to our database mysql_connect("","",""); mysql_select_db(""); // Search was made. if (isset($_POST['search'])) { $search = $_POST['search']; // For keeping search while changing pages. $where = " WHERE description LIKE '%" . ($_POST['search']) ."%' "; $page = 1; // Page must be set to 1 after new search. } else if (isset($_GET['search'])) { $search = $_GET['search']; // For keeping search while changing pages. $where = " WHERE description LIKE '%" . ($_GET['search']) ."%' "; } else { $where = ''; $search = ''; } // Entries per page. $perPage = 4; $query = "SELECT * FROM members $where"; //count results $run = mysql_query($query); $foundnum = mysql_num_rows($run); //count max pages $maxPages = floor($foundnum / $perPage); //may come out as a decimal // Check user inputted page does not exceed maxPages and is over zero. if (isset($_GET['page']) && intval($_GET['page']) > 0 && intval($_GET['page']) <= $maxPages) { $page = intval($_GET['page']); } else { $page = 1; } // Calculate start (and offset = $perPage). $start = ($page * $perPage) - $perPage; // Build query, run and get results for current page. $sql = "SELECT * FROM members $where LIMIT $start, $perPage"; $result = mysql_query($sql); while ($row = mysql_fetch_object($result)) { echo $row->id . ' - ' . $row->description . '<br/>'; } // Print prev button. if (!($start<=0)) echo ($page > 1) ? '<a href="?page=' . ($page - 1) . (strlen($search) ? '&search=' . $search : '') .'">prev</a> ' : 'prev '; // Print pages for ($i=1; $i<=$maxPages; $i++) { echo ($i === $page) ? $i .' ' : '<a href="?page='. $i . (strlen($search) ? '&search=' . $search : '') .'">'. $i .'</a> '; } // Print next button. if (!($start>=$foundnum-$perPage)) echo ($page < $maxPages) ? ' <a href="?page=' . ($page + 1) . (strlen($search) ? '&search=' . $search : '') . '">next</a>' : ' next'; ?>
  6. just found another problem, changing the results per page to more than 4 does not show all of my results, im just entered 12 rows of dummy data in my database and only 10 show when i change the results per page to more than 4
  7. everything is working nearly perfect, but when i am searching, and i use more that one word in my search, no results are found
  8. doing a pagination script that is just reading from a database im ok with and im ok with a search engine script but putting them both together really confuses me. TeNDoLLA, is it ok if you could give an example with my search paginated and i could try and change a few things?
  9. below is a search engine script and im tring to improve it by adding pagination to it, but im having a little problem with the "next" button, i have looked at other script but i cant understand them as i am new to php and i want to make one that i can understand, the "prev" button does work. there are no errors within the script but my problem is that the "next" button is never displayed. please help. <?php //connect to our database mysql_connect("","",""); mysql_select_db(""); //strlen check $search = $_GET['results']; if(strlen($search)<3) echo "Your search must be at least 3 characters long."; //results per page $per_page = 10; //get start variable $start = $_GET['start']; //get start if(!$start) $start = 0; //explode our search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { //construct query $x++; if ($x==1) $query .= "description LIKE '%$search_each%' LIMIT $start, $per_page"; else $query .= " OR description LIKE '%$search_each%' LIMIT $start, $per_page"; } $query = "SELECT * FROM members WHERE $query"; //count results $run = mysql_query($query); $foundnum = mysql_num_rows($run); //count max pages $max_pages = $foundnum / $per_page; //may come out as a decimal if ($foundnum==0) echo "You searched for <b>$search</b>. No results found."; else { echo "You searched for <b>$search</b><br>$foundnum result(s) found!<p><hr size='1' width='387'color='#E6E6E6' align='left'>"; while ($runrows = mysql_fetch_assoc($run)) { //get data $city = ucwords($runrows['city']); $pageurl = $runrows['pageurl']; $company = ucwords($runrows['company']); $logo = $runrows['logo']; $pageid = $runrows['pageid']; if ($imagelocation == "") { $imagelocation = "./profileimages/noprofilepic.jpg"; } echo " <img src ='$logo' width='100' height='105' border='0' align='left' style='padding-right:10px'><br> <b>$company</b><br> $city<br> <a href='http://www.squiblo.com/page.php?pageid=$pageid' style='text-decoration:none;'><font color='#FFFF00'><u>View page</u></font></a><br><br><br><br><br> <hr size='1' width='387' align='left' color='#E6E6E6'> "; } } //navigation //previous and next variables $prev = $start - $per_page; $next = $start + $per_page; //show prev button if (!($start<=0)) echo "<a href='results2.php?start=$prev&results=$search'>Prev</a> "; //show page numbers (not done yet) //show next button if (!($start>=$foundnum-$per_page)) echo " <a href='results2.php?start=$next&results=$search'>Next</a>"; ?>
  10. i still cant figure this one out
  11. is this something that you are looking for? <?php $connect = mysql_connect("localhost","username","password") or die ("Couldn't connect"); mysql_select_db("database name") or die ("Couldn't find db"); $query = mysql_query("SELECT * FROM databasename WHERE username='$username'"); $numrows = mysql_num_rows($query); if ($numrows!=0) { while ($row = mysql_fetch_assoc($query)) { $dbhasserver = $row['hassserver']; } if ($dbhasserver = "") { echo "You currenley have no game servers head over to packages to buy one."; } else echo $hassserver; } else die("user does not exist"); ?>
  12. yes that is correct how does that effect things?
  13. the problem is described within the code, please help <?php if ($_POST['submit']){ $username = $_POST['username']; $companyname = $_POST['companyname']; $secretquestion = $_POST['secretquestion']; $secretanswer = $_POST['secretanswer']; if ($username&&$companyname&&$secretquestion&&$secretanswer){ $connect = mysql_connect("***","***","***") or die ("Couldn't connect"); mysql_select_db("***") or die ("Couldn't find db"); $query = mysql_query("SELECT * FROM members WHERE username='$username'"); $numrows = mysql_num_rows($query); if ($numrows !=0) { while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbcompanyname = $row['company']; $dbsecretquestion = $row['secretquestion']; $dbsecretanswer = $row['secretanswer']; $dbpersonalemail = $row['personalemail']; } //check to see if they match if ($username==$dbusername&&$companyname==$dbcompanyname&&$secretquestion==$dbsecretquestion&&$secretanswer==$dbsecretanswer) { $random = rand(23456789,98765432); mysql_query("UPDATE members SET randomforgot='$random' WHERE username='$username'"); echo "Success, we have sent you an email containing a random number, enter the random number below.<br><br> <form action='forgotpassword.php' method='POST'> <table width='100%'> <tr><td width='50%'></td><td></td></tr> <tr><td align='right'>Random number:</td><td><input type='text' name='randomnumber' maxlength='8' size='8'></td></tr> <tr><td></td><td align='left'><input type='submit' name='submitrandomnumber' value='Enter'></td></tr> </table> </form> "; /*just below is where i am having my problem when i click the submit button in the form just above it just goes back to the very beginning of the script like the page has just been refreshed even if there is information entered in the "<input type='text' name='randomnumber' maxlength='8' size='8'>" or not. but i want to redirect to /bob.php */ if ($_POST['randomnumber']) { $randomnumber = $_POST['randomnumber']; $dbrandomnumber = $row ['randomforgot']; if ($randomnumber==$dbrandomnumber) { header("location:./bob.php"); } } //end of the problem } else $incorrectdetails = " <form action='forgotpassword.php' method='POST'> <table> <tr><td></td><td>Sorry we could not find those details<td></tr> <tr><td align='right'>Username:</td><td><input type='text' name='username' value='$username'></td></tr> <tr><td align='right'>Company name:</td><td><input type='text' name='companyname' value='$companyname'></td></tr> <tr><td align='right'>Secret Question:</td><td><select name='secretquestion'><option selected></option><option>Your pets name</option><option>Mothers maiden name</option><option>Favourite book</option><option>Favourite school teacher</option><option>Fathers first name</option></select></td></tr> <tr><td align='right'>Answer:</td><td><input type='password' name='secretanswer'></td></tr> <tr><td></td><td align='left'><input type='submit' name='submit' value='Send'></td></tr> </table> </form> "; } else { $incorrectuser = " <form action='forgotpassword.php' method='POST'> <table> <tr><td></td><td>Username does not exist<td></tr> <tr><td align='right'>Username:</td><td><input type='text' name='username' value='$username'></td></tr> <tr><td align='right'>Company name:</td><td><input type='text' name='companyname' value='$companyname'></td></tr> <tr><td align='right'>Secret Question:</td><td><select name='secretquestion'><option selected></option><option>Your pets name</option><option>Mothers maiden name</option><option>Favourite book</option><option>Favourite school teacher</option><option>Fathers first name</option></select></td></tr> <tr><td align='right'>Answer:</td><td><input type='password' name='secretanswer'></td></tr> <tr><td></td><td align='left'><input type='submit' name='submit' value='Send'></td></tr> </table> </form> "; } } else { $error = " <form action='forgotpassword.php' method='POST'> <table> <tr><td></td><td>Please fill in all fields<td></tr> <tr><td align='right'>Username:</td><td><input type='text' name='username' value='$username'></td></tr> <tr><td align='right'>Company name:</td><td><input type='text' name='companyname' value='$companyname'></td></tr> <tr><td align='right'>Secret Question:</td><td><select name='secretquestion'><option selected></option><option>Your pets name</option><option>Mothers maiden name</option><option>Favourite book</option><option>Favourite school teacher</option><option>Fathers first name</option></select></td></tr> <tr><td align='right'>Answer:</td><td><input type='password' name='secretanswer'></td></tr> <tr><td></td><td align='left'><input type='submit' name='submit' value='Send'></td></tr> </table> </form> "; } } ?> <?php echo $error ?> <?php echo $incorrectuser ?> <?php echo $incorrectdetails ?> <?php if (!$_POST['submit']){ echo " <form action='forgotpassword.php' method='POST'> <table> <tr><td align='right'>Username:</td><td><input type='text' name='username' value='$username'></td></tr> <tr><td align='right'>Company name:</td><td><input type='text' name='companyname' value='$companyname'></td></tr> <tr><td align='right'>Secret Question:</td><td><select name='secretquestion'><option selected></option><option>Your pets name</option><option>Mothers maiden name</option><option>Favourite book</option><option>Favourite school teacher</option><option>Fathers first name</option></select></td></tr> <tr><td align='right'>Answer:</td><td><input type='password' name='secretanswer'></td></tr> <tr><td></td><td align='left'><input type='submit' name='submit' value='Send'></td></tr> </table> </form> "; } ?>
  14. Hi, I have two fully working scripts, the first being a search script and the second being a pagination script, and my hair is all falling out trying to get pagination for my search results by trying to merge the two scripts together, please could someone help im losing the will to live :'( this is the search script... <?php $search = $_GET['results']; if(strlen($search)<3) { echo "Your search must be at least 3 characters long."; $div_height = 'height:500px;'; $img_height = 'height="500"'; } else { echo ""; //connect to our database mysql_connect("***","***","***"); mysql_select_db("***"); //explode our search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { //construct query $x++; if ($x==1) $construct .= "company LIKE '%$search_each%'"; else $construct .= " OR company LIKE '%$search_each%'"; } //echo out construct $construct = "SELECT * FROM members WHERE $construct"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "You searched for <b>$search</b>. No results found."; else { echo "You searched for <b>$search</b><br>$foundnum result(s) found!<p><hr size='1' width='387'color='#E6E6E6' align='left'>"; while ($runrows = mysql_fetch_assoc($run)) { //get data $city = ucwords($runrows['city']); $pageurl = $runrows['pageurl']; $company = ucwords($runrows['company']); $imagelocation = $runrows['imagelocation']; if ($imagelocation == "") { $imagelocation = "./profileimages/noprofilepic.jpg"; } echo " <img src ='$imagelocation' width='100' height='105' border='0' align='left' style='padding-right:10px'><br> <b>$company</b><br> $city<br> <a href='$page' style='text-decoration:none;'><font color='#FFFF00'><u>View page</u></font></a><br><br><br><br><br> <hr size='1' width='387' align='left' color='#E6E6E6'> "; } } } ?> and this is the pagination script i have... <?php mysql_connect('***','***','***') or die("Couldn't connect"); mysql_select_db('***') or die("Couldn't find db"); //max per page $per_page = 5; //start variable $start = $_GET['start']; //$count records $record_count = mysql_num_rows(mysql_query("SELECT * FROM members")); //count max pages $max_pages = $record_count / $per_page; //may be a decimal if (!$start) $start = 0; //display data $get = mysql_query("SELECT * FROM members LIMIT $start,$per_page"); while ($row = mysql_fetch_assoc($get)) { //get data $company = $row['company']; $id = $row['id']; echo $company." (".$id.")<br />"; } //set prev and next variables $prev = $start - $per_page; $next = $start + $per_page; //show prev if (!($start<=0)) echo " <a href='resultstest.php?start=$prev'>Previous</a> "; //show numbers //set variable for first page $i=1; for ($x=0;$x<$record_count;$x=$x+$per_page) { if ($start!=$x) echo " <a href='resultstest.php?start=$x'>$i</a> "; else echo " <a href='resultstest.php?start=$x'><b>$i</b></a> "; $i++; } //show next if (!($start>=$record_count-$per_page)) echo " <a href='resultstest.php?start=$next'>Next</a> "; ?>
  15. im not sure if this is anything to do with any PHP but what I am looking for is a toolbar for a form in my website, just like what people use here on the forums and click the icon and code tags, a href tags appear and change font etc, what keywords can i search in google for something like this?
  16. i found my problem, the name for the button and the options were the same
  17. ive messed about with this code for ages now but i cant get it to work, can anyone see the problem? there are no errors. The problem is that, it is always echoing from the database but when i change it in the form, it still echoes the same things from the database <style> table.pagecontent { background-color: <?php if (!isset($_GET['bgcolor'])){ ?> <?php $_SESSION['myusername']; $connect = mysql_connect("***","***","***") or die ("Couldn't connect"); mysql_select_db("***") or die ("Couldn't find db"); $username = isset($_SESSION['myusername']) ? $_SESSION['myusername'] : 'default_value'; $query = mysql_query("SELECT * FROM members WHERE username='$username'"); if (mysql_num_rows($query)==0){ die; }else{ $row = mysql_fetch_assoc($query); $location = $row['bgcolor']; if($location == ""){ echo ""; }else{ echo $location; } } ?> <?php } else echo ($_GET['bgcolor']); ?> } </style> <form name="bgcolor" method="GET" action=""> Background color:<br> <select name="bgcolor"><option selected></option> <option style="background-color:#F0F8FF; color: #000000;">AliceBlue</option> <option style="background-color:#FAEBD7; color: #000000;">AntiqueWhite</option> <option style="background-color:#00FFFF; color: #000000;">Aqua</option> <input type="submit" name="bgcolor" value="Change"></form> </form>
  18. <?php if(!$_GET['user']){ die("User not found"); //would doctype and meta tags go here?? mysql_connect("***","***","***") or die ("Couldn't connect"); mysql_select_db("***") or die ("Couldn't find db"); $user = mysql_real_escape_string($_GET['user']); mysql_query("SELECT image FROM profile WHERE username='$user'"); ?>
  19. what would an example of $_GET look like? does the $_GET replace the session or to get items info from the database?
  20. would something like this work... <?php session_start(); if($_SESSION['myusername']){ //start example mysql_connect("***","***","***") or die ("Couldn't connect"); mysql_select_db("***") or die ("Couldn't find db"); $username = isset($_SESSION['myusername']) mysql_query("SELECT image FROM profile WHERE username='$username'"); ?> but the problem i can think of with using this is that, all the pages will have the same layout and i want each user to be able to design thier own layout
  21. hi, my aim is to make a dynamic page for every user, like a profile page, and they can edit the design of the page, such as background color and add text boxes and so on, but firstly how do i create the indiviual page for each user, also what can i search for in google because i do not know where to start with this. thank you
  22. ive changed it a little bit so it may be easier to understand, i dont know how to get this to work properly, it is getting an image directory from mysql and the actual image is in ftp. <?php session_start(); if($_SESSION['myusername']){ $connect = mysql_connect("localhost","","") or die ("Couldn't connect"); mysql_select_db("") or die ("Couldn't find db"); $username = ($_SESSION['myusername']); $query = mysql_query("SELECT * FROM members WHERE username='$username'"); if (mysql_num_rows($query)==0){ die; }else{ $row = mysql_fetch_assoc($query); $location = $row['imagelocation']; if($location == ""){ echo ""; }else{ echo "<img src ='$location' width='110' height='110' border='1'><br>"; echo "Welcome " . ucwords(strtolower($_SESSION['myusername'])); } } } else { echo "<a href='login.php' style='text-decoration:none'><font color=#FFFF00>Sign in </a></font><font color=#FFFFFF><font color=#000000>/</font> Register</font>"; } ?>
  23. nothing is being echoed in this code, and no errors, notices or warnings are appearing <?php session_start(); if($_SESSION['myusername']){ ?> <?php $_SESSION['myusername']; $connect = mysql_connect("localhost","***","***") or die ("Couldn't connect"); mysql_select_db("***") or die ("Couldn't find db"); $username = isset($_SESSION['myusername']) ? $_SESSION['myusername'] : 'default_value'; $query = mysql_query("SELECT * FROM members WHERE username='$username'"); if (mysql_num_rows($query)==0){ die; }else{ $row = mysql_fetch_assoc($query); $location = $row['imagelocation']; if($location == ""){ echo ""; }else{ echo "<img src ='$location' width='110' height='110' border='1'><br>"; echo "Welcome " . ucwords(strtolower($_SESSION['myusername'])); } } ?> <?php } else { echo "<a href='login.php' style='text-decoration:none'><font color=#FFFF00>Sign in </a></font><font color=#FFFFFF><font color=#000000>/</font> Register</font>"; } ?>
  24. squiblo

    md5

    Hi, i have this login script but without md5 for the password and im not sure where to type it in, could some please show me where the md5 for the password goes? <?php error_reporting(E_ALL); ini_set('display_errors', 'off'); $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name=""; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); if(isset($_POST['Login'])){ // username and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $mycompany=$_POST['mycompany']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $mycompany = stripslashes($mycompany); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $mycompany = mysql_real_escape_string($mycompany); //$_SESSION['myusername']=$dbusername; $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword' and company='$mycompany'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword and $mycompany, table row must be 1 row if($count==1){ session_register("myusername"); session_register("mypassword"); session_register("mycompany"); header("location:index.php"); } else { header("location:wrong_login.php"); } } ?>
  25. im new to php ive never heard of anchors, how do you set up and anchor?
×
×
  • 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.