Jump to content

spiceweasel

Members
  • Posts

    16
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

spiceweasel's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for the ideas guys. I was think something similar to monkeytooth but thought i better check there wasnt a standard way of doing this. I was also toying with the idea of assigning a Pagination ID which i could cycle every 24 hours and then order results by these - again not fully thought out yet but might work. Time to have a play......
  2. Hi Guys I need some help this is my first real php website. Im trying to retrieve results from an accommodation database, to make the results fair I need to return a random set of results so each accommodation get a fair viewing and nobody is always at the bottom. The problem arises when i paginate the results, because each page executes a separate randomly ordered offset mysql query I can end up showing the some of the same results over and over on multiple pages. This is going to confuse and irritate searchers. How can i achieve results and paginate them where each accommodation gets a fair chance at the first page each time the database is searched?
  3. I am a relative beginner but from what i understand VARCHAR can be set to a value of between 0-255 in Mysql versions pryor to MySQL 5.0.3 and 0 to 65,535 in later versions. So check you versions also check out Mysql site for futher details: http://dev.mysql.com/doc/refman/5.0/en/char.html Scratch that i didnt read the question correctly (mssql) - Sorry
  4. YES!!!!!!!!!!!!!!!!!! thank you waterssaz that works - as a beginner i dont quite understand why, but it works and thats good enough for me. Thank you to everyone that helped.
  5. Hi intellix, I think i see what you mean. If i take out the query and just echo back the session value for each if statement it appears to be a string with the expected value eg. any any, hotel any, cornwall any ....etc - so it appear to be working. As a further check I have run each query on its own and they work independently and return the correct data just not within the if/ifelse's I cant understand why not. Im getting really confused and might start to look for an alternative way of doing this maybe a switch??
  6. Unfortunately none of it works now .....going back to original code: <?php //query database if ($_SESSION['type']== 'any' && $_SESSION['area']== 'any'){ $query = mysql_query("SELECT * FROM hotels Order by RAND() "); } elseif ($_SESSION['area'] == 'any' && $_SESSION['type'] != 'any'){ $query = mysql_query("SELECT * FROM hotels WHERE type = $_SESSION[type] Order by RAND()"); } elseif ($_SESSION['type'] == 'any' && $_SESSION['area'] != 'any'){ $query = mysql_query("SELECT * FROM hotels WHERE location =$_SESSION[area] Order by RAND()"); } else{ $query = mysql_query("SELECT * FROM hotels WHERE location ='$_SESSION[area]' AND type ='$_SESSION[type]' Order by RAND()"); } //show results while ($search_result = mysql_fetch_assoc($query)) { echo '<b>'.$search_result[name] . '</b><br>'; echo '<p><img src="'.$search_result['photo1'].'" /></p>'; echo '<p><img src="'.$search_result['award'].'" /></p>'; echo $search_result[description] . '<br><br>'; } ?>
  7. Thanks mdgeus I'll check it out but im not sure as the last else is one of the statements that worked.
  8. I thought for a second you had it mdgeus! But nothings changed still throws this error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in.... Plus the last else statement works without the singles around the string. Code now looks like this: <?php //select correct database $db = mysql_select_db('isleofwightholidays',$connection); if (!$db) { echo 'unable to select database' . mysql_error(); } //query database if ($_SESSION['type']== 'any' && $_SESSION['area']== 'any'){ $query = mysql_query("SELECT * FROM hotels Order by RAND() " or die (mysql_error())); } if ($_SESSION['area'] == 'any' && $_SESSION['type'] != 'any'){ $query = mysql_query("SELECT * FROM hotels WHERE type = ".$_SESSION['type']." Order by RAND()" or die (mysql_error())); } if ($_SESSION['type'] == 'any' && $_SESSION['area'] != 'any'){ $query = mysql_query("SELECT * FROM hotels WHERE location =".$_SESSION['area']." Order by RAND()" or die (mysql_error())); } else{ $query = mysql_query("SELECT * FROM hotels WHERE location ='$_SESSION[area]' AND type ='$_SESSION[type]' Order by RAND()" or die (mysql_error())); } //show results while ($search_result = mysql_fetch_assoc($query)) { echo '<b>'.$search_result[name] . '</b><br>'; echo '<p><img src="'.$search_result['photo1'].'" /></p>'; echo '<p><img src="'.$search_result['award'].'" /></p>'; echo $search_result[description] . '<br><br>'; } ?>
  9. Hi intellix <?php "SELECT * FROM hotels WHERE type = '$_SESSION[type]' Order by RAND()";?> This goes through PHPMyadmin fine if the singles are round $_SESSION[type]. It doesnt return anything as it doesnt recognise $_SESSION[type] but it goes through : MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0024 sec )
  10. Thanks for the suggestions intellix, Unfortunately i had just forgotten to put the singles back in after trying no quotes and doubles and it makes no difference. Mysql error also returns nothing. Cheers!
  11. Hi Guys, Beginner needs help with accommodation search feature...i have two drop downs(area and type), each one has an 'any' option. I cant evalute the 'any' options directly against the database so have written this: <?php //query database if ($_SESSION['type']== 'any' && $_SESSION['area']== 'any'){ $query = mysql_query("SELECT * FROM hotels Order by RAND() "); } elseif ($_SESSION['area'] == 'any' && $_SESSION['type'] != 'any'){ $query = mysql_query("SELECT * FROM hotels WHERE type = $_SESSION[type] Order by RAND()"); } elseif ($_SESSION['type'] == 'any' && $_SESSION['area'] != 'any'){ $query = mysql_query("SELECT * FROM hotels WHERE location =$_SESSION[area] Order by RAND()"); } else{ $query = mysql_query("SELECT * FROM hotels WHERE location ='$_SESSION[area]' AND type ='$_SESSION[type]' Order by RAND()"); } //show results while ($search_result = mysql_fetch_assoc($query)) { echo '<b>'.$search_result[name] . '</b><br>'; echo '<p><img src="'.$search_result['photo1'].'" /></p>'; echo '<p><img src="'.$search_result['award'].'" /></p>'; echo $search_result[description] . '<br><br>'; }?> The first if and last else return the correct info from database but the middle two elseif's throw this error: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given.... I have commented out the queries and replaced them with simple echoes and they all seem to evaluate correctly!. So im lost why $query isnt assigned in the middle two elseif's ?? Any ideas what im doing wrong and is there a better way. Cheers!!
  12. Hi jim_keller, Thanks alot that seems to do the trick!
  13. This is my first php script and im a bit confused. I have written a search form (search.html) sent via POST which is processed by results.php. This works and calls back the correct data from the database which i have paginated. The problem is that results are only showed on the first page although pagination shows there are more pages of results to be viewed. To try and figure out what is going on i echoed back the search term which shows correctly but then disappears on the subsequent pages as if it 'forgets' what the user searched for -is this why no results are returned on any page other than page one?. What am i doing wrong?? Its probably a simple fix but i just got done reading a php book and this is my first go at anything real world and useful. Any suggestions would be greatly appreciated. <link href="css/main.css" rel="stylesheet" type="text/css" /> <div id="container"> <?php include('includes\connection.php'); //connect $db_connect = mysql_connect(DB_SERVER, DB_USER, DB_PASS); if (!$db_connect){ echo "Could not connect to database ".mysql_error(); } //select $db_select = mysql_select_db(DB_NAME,$db_connect); if (!$db_connect){ echo "Could not select database ".mysql_error(); } $search = $_POST['area']; /****** pagination start ******/ // find out how many rows are in the table $sql = "SELECT COUNT(*) FROM hotels WHERE location = '$search'"; $result = mysql_query($sql, $db_connect) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 5; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // 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 // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // get the info from the db //query echo 'You searched '.$search; $query = mysql_query("SELECT * FROM hotels WHERE location = '$search' LIMIT $offset, $rowsperpage"); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($query)) { // echo data echo '<div id="listing">'; echo '<br><strong>'.$list['name'].'</strong'; echo '<br>Location: '.$list['location']; echo '<br>Price From: £'.$list['price']; echo '<br><img src="'.$list['awards'].'"/><br>'; echo '<img src="'.$list['image'].'"/><br>'; echo '<br>'.$list['description'].'<br>'; } // end while /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 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 ******/ ?> </div>
  14. I am looking to compile a tourist guide for my town. I want to be able to hold listing data (text and pictures) in a database and create pages dynamically and also be searched by a number of different ways (location, accommodation type, price etc). I have very basic php/mysql knowledge and think it would be a good project to increase my knowledge + fun too! Are there and books/tutorials/websites that you can recomend and any tips you could offer/newbie mistakes i should watch out for. Thanks Guys!
  15. Wow thanks for the quick reply thorpe? so this remains true even if their is no php on the actual page effected ie. i put up an html landing page and this also had code injected into it. so all they need is a site containing one insecure page and they can insert code into any other page they choose regardless of there coding in it or not???? sorry to seem thick i need to get this issue clear in my head! and can you recommend a resource that would help me secure my code im new to php and i would place myself in the catergory/level of being able to understand already written scripts but whenever i write my own they never work correctly lol!
×
×
  • 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.