Jump to content

QuickOldCar

Staff Alumni
  • Posts

    2,972
  • Joined

  • Last visited

  • Days Won

    28

Everything posted by QuickOldCar

  1. I like the idea of the site, always nice to have more organized sites. The background I don't like, made me feel like in a hospital. Must be hard work locating and tagging all the tutorials.
  2. My curl script can fetch the info on the page. Can echo the html and is there. What you do with the html will be up to you. <?php $url = "http://www.clickcritters.com/"; /*connect to the url using curl to see if exists and get the information*/ //$cookie = tempnam('tmp','cookie'); //$cookie_file_path = "tmp/"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); //curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); //curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3'); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_TIMEOUT, 15); curl_setopt($ch, CURLOPT_MAXREDIRS, 15); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt ($ch, CURLOPT_FILETIME, 1); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_ENCODING , ""); $curl_session = curl_init(); //curl_setopt($curl_session, CURLOPT_COOKIEJAR, $cookie); //curl_setopt($curl_session, CURLOPT_COOKIEFILE, $cookie_file_path); curl_setopt($curl_session, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3'); curl_setopt($curl_session, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($curl_session, CURLOPT_ENCODING , ""); curl_setopt($curl_session, CURLOPT_TIMEOUT, 15); curl_setopt($curl_session, CURLOPT_HEADER, 1); curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl_session, CURLOPT_HEADER, true); curl_setopt($curl_session, CURLOPT_MAXREDIRS, 15); curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true); curl_setopt( $curl_session, CURLOPT_AUTOREFERER, true ); curl_setopt ($curl_session, CURLOPT_HTTPGET, true); curl_setopt($curl_session, CURLOPT_URL, $url); $string = mysql_real_escape_string(curl_exec($curl_session)); $html = mysql_real_escape_string(curl_exec ($ch)); $info = curl_getinfo($ch); /*curl response check and to resolve url to the actual location*/ $response = curl_getinfo( $ch ); if ($response['http_code'] == 301 || $response['http_code'] == 302) { ini_set("user_agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3"); $headers = get_headers($response['url']); $location = ""; foreach( $headers as $value ) { if ( substr( strtolower($value), 0, 9 ) == "location:" ) return get_final_url( trim( substr( $value, 9, strlen($value) ) ) ); } } if ( preg_match("/window\.location\.replace\('(.*)'\)/i", $con_addtent, $value) || preg_match("/window\.location\=[\"'](.*)[\"']/i", $con_addtent, $value) || preg_match("/location\.href\=[\"'](.*)[\"']/i", $con_addtent, $value) ) { $finalurl = get_final_url($value[1]); } else { $finalurl = $response['url']; } $html = curl_exec($ch); $header = "Location: "; //echo $finalurl."<br />"; //view site echo $html; //stripped tags text //echo strip_tags($html); curl_close($ch); ?>
  3. Here is a simple little demo I made using a single page to display posts as you described. http://get.blogdns.com/dynaindex/post-variable.php Another way is to make a separate php file made exclusively to display the single posts. As an example, lets call this view.php <?php //At the top would use a $_GET parameter $id = $_GET['id']; //make mysql connection, use your connection info $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } //select your database mysql_select_db("my_db", $con); //query what you want, insert your table name $result = mysql_query("SELECT * FROM table WHERE id='$id'"); //post loop while($row = mysql_fetch_array($result)) { //use your values echo $row['id'] ."<br />"; echo $row['title'] ."<br />"; echo $row['description'] ."<br />"; } //close the connection mysql_close($con); ?> From the page you want to link to your single post, make a hyperlink leading to view.php, get the id from each post echo "<a href='view.php?id=$id'>View Post</a>"; The above is in it's simplest form, you can use other unique values versus id's.
  4. Whats the url of the website that your talking about.
  5. You can place somethinglike this before the if/else if(!isset($_GET['os']) || $_GET['os'] == "") { $page = "home"; } You can also in your if/else do a last else including home.php $page = $_GET['os']; if ($page == "home") { include('home.php'); } elseif ($page == "how") { include('how.php'); } elseif ($page == "signup") { include('signup.php'); } elseif ($page == "offers") { include('offers.php'); } elseif ($page == "friends") { include('friends.php'); } elseif ($page == "login") { include('login.php'); } elseif ($page == "register") { include('register.php'); } else { include('home.php'); }
  6. OK The best way then is to do 5 queries grouping them by each day and display each of the results same page. Otherwise would have to sift through all the results creating new arrays and then exploding and foreach on each of those results. so an idea would be to group each value by day for all results. in your while() you now have an array of $recurrence I do not know which key is the date, but you will $recurrence_date = trim($recurrence[0]);//this is the first of the exploded group, change to date key if($recurrence_date == "monday") { $monday_group[] = $find_schedule['ce_recurrence']; } if($recurrence_date == "tuesday") { $tuesday_group[] = $find_schedule['ce_recurrence']; } if($recurrence_date == "wednesday") { $wednesday_group[] = $find_schedule['ce_recurrence']; } if($recurrence_date == "thursday") { $thursday_group[] = $find_schedule['ce_recurrence']; } if($recurrence_date == "friday") { $friday_group[] = $find_schedule['ce_recurrence']; } //now each is grouped in day arrays outside the while loop //now explode and echo all the results for each day in a foreach foreach($monday_group as $monday_array) { foreach($monday_array as $monday_results){ echo $monday_results."<br />"; } } //and do the others as well Maybe others know better ways, but I think the 5 queries each day is the best.
  7. I knew you knew. It's not really incorrect, as else if still works as long as is brackets, but elseif is also faster. I was actually thinking of what the original poster really wants. It may be wiser to actually do header redirects and then include a header.php file each page along with a navigation menu.
  8. It's "elseif" not "else if"
  9. In the select statement itself you can add GROUP BY type to the end of your query. type being the day value you use. EDIT: You should be able to use a dropdown to change the day values by using a variable in the select statement. So can select which day would like to see the results for.
  10. 'm guessing you now need to do something like a foreach loop. foreach($content as $value){ echo $value."<br />"; } or however would like to style and display it Posting what code you have helps greatly.
  11. It's called $_GET http://www.w3schools.com/php/php_get.asp Get variables are visible and can be retrieved from the address bar. Usually a form is used, but also works without a form. Alternately $_POST is commonly used and requires some sort of form. The values are not visible in the address bar. http://www.tizag.com/phpT/forms.php You may use $_POST ,$_GET among other types.. http://php.net/manual/en/reserved.variables.php ... depending on what you need to do. What you use the variable for is almost limited just by your imagination. You can include a php page for instance. http://www.tizag.com/phpT/include.php As for your question: $os = $_GET['os']; if(isset($_GET['os']) && $os == "learn") ( include('how.php'); ) if/else or switch statements could show different results depending on the value of any different $_GET or $os value http://www.w3schools.com/php/php_if_else.asp http://www.tizag.com/phpT/switch.php May also use the variable to fetch different results from mysql http://www.w3schools.com/php/php_mysql_select.asp Read the tutorials, try them, any more questions or problems can always ask for more help here. The php manual has lots of good information and many times contains excellent examples. http://php.net/manual/en/manual.php
  12. It's very similar to NASA's logo.
  13. Gotta agree with webstyles. You can lessen the "load" by caching, creating indexes in mysql on any where,or,and statements, is also query caching.
  14. update this line if(isset($questiontext)){ if(isset($_POST['questiontext'])){ or even like if(!isset($_POST['questiontext'])){ echo "post question text not set"; } else { //execture query here } Checking for empty values may be nice as well if(isset($_POST['questiontext']) && $_POST['questiontext'] != ""){ //execute the query } else { echo "post question text not set"; } Just some examples of checking, there are more and even different ways Nowhere in the code do I see $questiontext EDIT: Lemme rephrase Nowhere do I see $questiontext assigned to a $_POST I see $dirty_questiontext=$_POST['questiontext']; instead of most likely you meant $questiontext=$_POST['questiontext'];
  15. Doing the checks as you describe would require to do a mysql query and compare values of new content versus stored content, depending on if they match or not can do nothing/update....else insert new. The above process would slow everything down, it may be better to just make a script that cycles through your database and deletes any similar stored content......meaning duplicate entries.
  16. Actually I made another mistake, I addeda quote when needed to remove a quote in last query. <?php //get the url from the address bar and redirect to script name $url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING); if (!empty($_SERVER["QUERY_STRING"])){ $query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING); $url .= "?".$query_string; } if($url == "http://".$_SERVER['HTTP_HOST']){ $redirect_to = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']; header("Location: $redirect_to"); } if (!isset($_GET['make'])) { $_GET['make'] = "All"; } ?> <form name="input" action="" method="GET"> Make: <Select name="make"> <option "Input" value="<?php echo $_GET['make']; ?>"><?php echo $_GET['make']; ?></option> <option value="All">All</option> <option value="Ford">ford</option> <option value="BMW">BMW</option> <option value="Honda">Honda</option> <option value="Lexus">Lexus</option> </select> <?php if (!isset($_GET['model'])) { $_GET['model'] = "All"; } ?> Model: <Select name="model"> <option "Input" value="<?php echo $_GET['model']; ?>"><?php echo $_GET['model']; ?></option> <option value="All">All</option> <option value="Civic">Civic</option> <option value="3 Series">3 Series</option> <option value="Fiesta">Fiesta</option> <option value="IS200">IS200</option> </select> <?php if (!isset($_GET['fuel'])) { $_GET['fuel'] = "Any"; } ?> Fuel: <Select name="fuel"> <option "Input" value="<?php echo $_GET['fuel']; ?>"><?php echo $_GET['fuel']; ?></option> <option value="Any">Any</option> <option value="Petrol">Petrol</option> <option value="Diesel">Diesel</option> </select> <?php if (!isset($_GET['location'])) { $_GET['location'] = "All"; } ?> Location: <Select name="location"> <option "Input" value="<?php echo $_GET['location']; ?>"><?php echo $_GET['location']; ?></option> <option value="All">All</option> <option value="UK">UK</option> <option value="London">London</option> <option value="Kent">Kent</option> </select> <?php if (!is_numeric($_GET['page']) || !isset($_GET['page']) || $_GET['page'] == 0 || empty($_GET['page'])) { $_GET['page'] = 1; } ?> Page:<input onfocus="this.value=''" size="15" type="text" name="page" value="<?php echo $_GET['page']; ?>"/> <input type="submit" value="Search Cars" /> </form> <?php //include 'db.inc.php'; $con = mysql_connect("localhost","db_username","db_password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); //variables from selection form $make = mysql_real_escape_string(trim($_GET['make'])); $model = mysql_real_escape_string(trim($_GET['model'])); $fuel = mysql_real_escape_string(trim($_GET['fuel'])); $location = mysql_real_escape_string(trim($_GET['location'])); $startrow = 0; $posts_per_page = 20; $nav_get = $_GET['page']; if (!isset($_GET['page']) || !is_numeric($_GET['page']) || empty($_GET['page'])) { $startrow = 0; $_GET['page'] = 1; $nav_get = 1; } else { $convert = $nav_get * $posts_per_page -$posts_per_page; $startrow = (int)$convert; } $prev = $nav_get - 1; if ($prev < 1) { $prev =1; } $next = $nav_get +1; $navigation_url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING); if (!empty($_SERVER["QUERY_STRING"])){ $query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING); $navigation_url .= "?".$query_string; } $navigation_url = trim($navigation_url,$nav_get); //you can change these to your needs if ($url == "http://".$_SERVER['HTTP_HOST'] || $url == "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']) { $navigation_url = "$navigation_url?&page="; } //default query $query = "SELECT * FROM `cars`"; //count the selections for queries $query_count = 0; //set queries and associate WHERE,AND if(isset($_GET['make']) && $_GET['make'] != "All" && $_GET['make'] != ""){ $query_count = $query_count +1; if($query_count == 1) { $where_and = "WHERE"; } else { $where_and = "AND"; } //if selected adds to query $query .= " $where_and Make='$make'"; } if(isset($_GET['model']) && $_GET['model'] != "All" && $_GET['model'] != ""){ $query_count = $query_count +1; if($query_count == 1) { $where_and = "WHERE"; } else { $where_and = "AND"; } //if selected adds to query $query .= " $where_and Model='$model'"; } if(isset($_GET['fuel']) && $_GET['fuel'] != "Any" && $_GET['fuel'] != ""){ $query_count = $query_count +1; if($query_count == 1) { $where_and = "WHERE"; } else { $where_and = "AND"; } //if selected adds to query $query .= " $where_and Fuel='$fuel'"; } if(isset($_GET['location']) && $_GET['location'] != "All" && $_GET['location'] != ""){ $query_count = $query_count +1; if($query_count == 1) { $where_and = "WHERE"; } else { $where_and = "AND"; } //if selected adds to query $query .= " $where_and Location='$location'"; } //find number of total count of GETs for each result minus the limits $totals = mysql_query($query); $total_posts = mysql_num_rows($totals); //final query to add the order and limit $query .=" ORDER BY id DESC LIMIT $startrow,$posts_per_page"; //echo $query."<br />";//query built from values above depending on selections $result = mysql_query($query); $lastposts = $total_posts - $posts_per_page; $nextposts = $total_posts +1; $total_posts_pages = $total_posts / $posts_per_page; list($int,$dec)=explode('.', $total_posts_pages); $int_pages = $int +1; $total_pages = $total_posts / $posts_per_page; $page_number = $startrow / $posts_per_page + 1; if ($nextposts >= $int_pages) { $nextposts = $int_pages; $page_one = 1; } if (!$_GET['page']) { $_GET['page'] = 1; } if ($page_number >= $int_pages+1) { $_GET['page'] = $int_pages; } if ($_GET['page'] <= 0) { $_GET['page'] = 1; } if ($page_number <= 0) { $page_number = 1; } if ($total_posts == 0){ echo '<h2>No results found.</h2>'; } echo "Page $page_number of $int_pages - $total_posts Results<br />"; //the page navigation hyperlinks echo "[<a href='./?page=1'><b>New</b></a>]"; echo "[<a href='$navigation_url$page_one'><b>First</b></a>]"; if ($page_number > 1){ echo '[<a href="'.$navigation_url.''.$prev.'"><b><<- Previous.. </b></a>]'; } if ($next <= $prev) { $next = $next+1; } echo "[$page_number]"; if ($next <= $nextposts){ echo '[<a href="'.$navigation_url.''.$next.'"><b> ..Next ->></b></a>]'; } if ($int_pages >= $int_pages){ echo '[<a href="'.$navigation_url.''.$int_pages.'"><b>Last</b></a>]'; } //check if results if(!$result){ echo "No Results <br />"; } else { echo "<table class='ex1' border='0' width='120%' style=text-align:center; cellpadding='6' cellspacing='0'></tr>"; while($row = mysql_fetch_array($result)) { echo "<tr style=font-family:verdana;font-size:80%;>"; echo "<td width=13%>" . $row[""] . "<img src=\"" . $row["Photo"] . "\"></a>"; echo '<td width="14%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Make'] . '</a></td>'; echo '<td width="5%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Model'] . '</a></td>'; echo '<td width="4%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Fuel'] . '</a></td>'; echo '<td width="4%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Location'] . '</a></td>'; echo "</tr>"; } echo "</table>"; } //the page navigation hyperlinks echo "[<a href='./?page=1'><b>New</b></a>]"; echo "[<a href='$navigation_url$page_one'><b>First</b></a>]"; if ($page_number > 1){ echo '[<a href="'.$navigation_url.''.$prev.'"><b><<- Previous.. </b></a>]'; } if ($next <= $prev) { $next = $next+1; } echo "[$page_number]"; if ($next <= $nextposts){ echo '[<a href="'.$navigation_url.''.$next.'"><b> ..Next ->></b></a>]'; } if ($int_pages >= $int_pages){ echo '[<a href="'.$navigation_url.''.$int_pages.'"><b>Last</b></a>]'; } ?>
  17. oops sorry, yeah I knew something wouldn't work. This should. <?php //get the url from the address bar and redirect to script name $url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING); if (!empty($_SERVER["QUERY_STRING"])){ $query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING); $url .= "?".$query_string; } if($url == "http://".$_SERVER['HTTP_HOST']){ $redirect_to = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']; header("Location: $redirect_to"); } if (!isset($_GET['make'])) { $_GET['make'] = "All"; } ?> <form name="input" action="" method="GET"> Make: <Select name="make"> <option "Input" value="<?php echo $_GET['make']; ?>"><?php echo $_GET['make']; ?></option> <option value="All">All</option> <option value="Ford">ford</option> <option value="BMW">BMW</option> <option value="Honda">Honda</option> <option value="Lexus">Lexus</option> </select> <?php if (!isset($_GET['model'])) { $_GET['model'] = "All"; } ?> Model: <Select name="model"> <option "Input" value="<?php echo $_GET['model']; ?>"><?php echo $_GET['model']; ?></option> <option value="All">All</option> <option value="Civic">Civic</option> <option value="3 Series">3 Series</option> <option value="Fiesta">Fiesta</option> <option value="IS200">IS200</option> </select> <?php if (!isset($_GET['fuel'])) { $_GET['fuel'] = "Any"; } ?> Fuel: <Select name="fuel"> <option "Input" value="<?php echo $_GET['fuel']; ?>"><?php echo $_GET['fuel']; ?></option> <option value="Any">Any</option> <option value="Petrol">Petrol</option> <option value="Diesel">Diesel</option> </select> <?php if (!isset($_GET['location'])) { $_GET['location'] = "All"; } ?> Location: <Select name="location"> <option "Input" value="<?php echo $_GET['location']; ?>"><?php echo $_GET['location']; ?></option> <option value="All">All</option> <option value="UK">UK</option> <option value="London">London</option> <option value="Kent">Kent</option> </select> <?php if (!is_numeric($_GET['page']) || !isset($_GET['page']) || $_GET['page'] == 0 || empty($_GET['page'])) { $_GET['page'] = 1; } ?> Page:<input onfocus="this.value=''" size="15" type="text" name="page" value="<?php echo $_GET['page']; ?>"/> <input type="submit" value="Search Cars" /> </form> <?php //include 'db.inc.php'; $con = mysql_connect("localhost","db_username","db_password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); //variables from selection form $make = mysql_real_escape_string(trim($_GET['make'])); $model = mysql_real_escape_string(trim($_GET['model'])); $fuel = mysql_real_escape_string(trim($_GET['fuel'])); $location = mysql_real_escape_string(trim($_GET['location'])); $startrow = 0; $posts_per_page = 20; $nav_get = $_GET['page']; if (!isset($_GET['page']) || !is_numeric($_GET['page']) || empty($_GET['page'])) { $startrow = 0; $_GET['page'] = 1; $nav_get = 1; } else { $convert = $nav_get * $posts_per_page -$posts_per_page; $startrow = (int)$convert; } $prev = $nav_get - 1; if ($prev < 1) { $prev =1; } $next = $nav_get +1; $navigation_url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING); if (!empty($_SERVER["QUERY_STRING"])){ $query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING); $navigation_url .= "?".$query_string; } $navigation_url = trim($navigation_url,$nav_get); //you can change these to your needs if ($url == "http://".$_SERVER['HTTP_HOST'] || $url == "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']) { $navigation_url = "$navigation_url?&page="; } //default query $query = "SELECT * FROM `cars`"; //count the selections for queries $query_count = 0; //set queries and associate WHERE,AND if(isset($_GET['make']) && $_GET['make'] != "All" && $_GET['make'] != ""){ $query_count = $query_count +1; if($query_count == 1) { $where_and = "WHERE"; } else { $where_and = "AND"; } //if selected adds to query $query .= " $where_and Make='$make'"; } if(isset($_GET['model']) && $_GET['model'] != "All" && $_GET['model'] != ""){ $query_count = $query_count +1; if($query_count == 1) { $where_and = "WHERE"; } else { $where_and = "AND"; } //if selected adds to query $query .= " $where_and Model='$model'"; } if(isset($_GET['fuel']) && $_GET['fuel'] != "Any" && $_GET['fuel'] != ""){ $query_count = $query_count +1; if($query_count == 1) { $where_and = "WHERE"; } else { $where_and = "AND"; } //if selected adds to query $query .= " $where_and Fuel='$fuel'"; } if(isset($_GET['location']) && $_GET['location'] != "All" && $_GET['location'] != ""){ $query_count = $query_count +1; if($query_count == 1) { $where_and = "WHERE"; } else { $where_and = "AND"; } //if selected adds to query $query .= " $where_and Location='$location'"; } //find number of total count of GETs for each result minus the limits $totals = mysql_query($query); $total_posts = mysql_num_rows($totals); //final query to add the order and limit $query .=" 'ORDER BY id DESC LIMIT $startrow,$posts_per_page'"; //echo $query."<br />";//query built from values above depending on selections $result = mysql_query($query); $lastposts = $total_posts - $posts_per_page; $nextposts = $total_posts +1; $total_posts_pages = $total_posts / $posts_per_page; list($int,$dec)=explode('.', $total_posts_pages); $int_pages = $int +1; $total_pages = $total_posts / $posts_per_page; $page_number = $startrow / $posts_per_page + 1; if ($nextposts >= $int_pages) { $nextposts = $int_pages; $page_one = 1; } if (!$_GET['page']) { $_GET['page'] = 1; } if ($page_number >= $int_pages+1) { $_GET['page'] = $int_pages; } if ($_GET['page'] <= 0) { $_GET['page'] = 1; } if ($page_number <= 0) { $page_number = 1; } if ($total_posts == 0){ echo '<h2>No results found.</h2>'; } echo "Page $page_number of $int_pages - $total_posts Results<br />"; //the page navigation hyperlinks echo "[<a href='./?page=1'><b>New</b></a>]"; echo "[<a href='$navigation_url$page_one'><b>First</b></a>]"; if ($page_number > 1){ echo '[<a href="'.$navigation_url.''.$prev.'"><b><<- Previous.. </b></a>]'; } if ($next <= $prev) { $next = $next+1; } echo "[$page_number]"; if ($next <= $nextposts){ echo '[<a href="'.$navigation_url.''.$next.'"><b> ..Next ->></b></a>]'; } if ($int_pages >= $int_pages){ echo '[<a href="'.$navigation_url.''.$int_pages.'"><b>Last</b></a>]'; } //check if results if(!$result){ echo "No Results <br />"; } else { echo "<table class='ex1' border='0' width='120%' style=text-align:center; cellpadding='6' cellspacing='0'></tr>"; while($row = mysql_fetch_array($result)) { echo "<tr style=font-family:verdana;font-size:80%;>"; echo "<td width=13%>" . $row[""] . "<img src=\"" . $row["Photo"] . "\"></a>"; echo '<td width="14%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Make'] . '</a></td>'; echo '<td width="5%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Model'] . '</a></td>'; echo '<td width="4%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Fuel'] . '</a></td>'; echo '<td width="4%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Location'] . '</a></td>'; echo "</tr>"; } echo "</table>"; } //the page navigation hyperlinks echo "[<a href='./?page=1'><b>New</b></a>]"; echo "[<a href='$navigation_url$page_one'><b>First</b></a>]"; if ($page_number > 1){ echo '[<a href="'.$navigation_url.''.$prev.'"><b><<- Previous.. </b></a>]'; } if ($next <= $prev) { $next = $next+1; } echo "[$page_number]"; if ($next <= $nextposts){ echo '[<a href="'.$navigation_url.''.$next.'"><b> ..Next ->></b></a>]'; } if ($int_pages >= $int_pages){ echo '[<a href="'.$navigation_url.''.$int_pages.'"><b>Last</b></a>]'; } ?> As for the buttons will see what I can do. See if this works and actually displays a Next to page 2 and proper results now. It didn't set the total_posts because the query was failing. Results set to 20 per page now.
  18. By using sessions http://www.php.net/manual/en/book.session.php
  19. Here you go. If have any issues describe it or better yet show me your working page. The script assumes the page is index.php If you need it called different, just make a folder named cars or something and drop this script inside named index.php ......otherwise changes would have to be made. <?php //get the url from the address bar and redirect to script name $url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING); if (!empty($_SERVER["QUERY_STRING"])){ $query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING); $url .= "?".$query_string; } if($url == "http://".$_SERVER['HTTP_HOST']){ $redirect_to = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']; header("Location: $redirect_to"); } if (!isset($_GET['make'])) { $_GET['make'] = "All"; } ?> <form name="input" action="" method="GET"> Make: <Select name="make"> <option "Input" value="<?php echo $_GET['make']; ?>"><?php echo $_GET['make']; ?></option> <option value="All">All</option> <option value="Ford">ford</option> <option value="BMW">BMW</option> <option value="Honda">Honda</option> <option value="Lexus">Lexus</option> </select> <?php if (!isset($_GET['model'])) { $_GET['model'] = "All"; } ?> Model: <Select name="model"> <option "Input" value="<?php echo $_GET['model']; ?>"><?php echo $_GET['model']; ?></option> <option value="All">All</option> <option value="Civic">Civic</option> <option value="3 Series">3 Series</option> <option value="Fiesta">Fiesta</option> <option value="IS200">IS200</option> </select> <?php if (!isset($_GET['fuel'])) { $_GET['fuel'] = "Any"; } ?> Fuel: <Select name="fuel"> <option "Input" value="<?php echo $_GET['fuel']; ?>"><?php echo $_GET['fuel']; ?></option> <option value="Any">Any</option> <option value="Petrol">Petrol</option> <option value="Diesel">Diesel</option> </select> <?php if (!isset($_GET['location'])) { $_GET['location'] = "All"; } ?> Location: <Select name="location"> <option "Input" value="<?php echo $_GET['location']; ?>"><?php echo $_GET['location']; ?></option> <option value="All">All</option> <option value="UK">UK</option> <option value="London">London</option> <option value="Kent">Kent</option> </select> <?php if (!is_numeric($_GET['page']) || !isset($_GET['page']) || $_GET['page'] == 0 || empty($_GET['page'])) { $_GET['page'] = 1; } ?> Page:<input onfocus="this.value=''" size="15" type="text" name="page" value="<?php echo $_GET['page']; ?>"/> <input type="submit" value="Search Cars" /> </form> <?php //include 'db.inc.php'; $con = mysql_connect("localhost","db_username","db_password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); //variables from selection form $make = mysql_real_escape_string(trim($_GET['make'])); $model = mysql_real_escape_string(trim($_GET['model'])); $fuel = mysql_real_escape_string(trim($_GET['fuel'])); $location = mysql_real_escape_string(trim($_GET['location'])); $startrow = 0; $posts_per_page = 30; $nav_get = $_GET['page']; if (!isset($_GET['page']) || !is_numeric($_GET['page']) || empty($_GET['page'])) { $startrow = 0; $_GET['page'] = 1; $nav_get = 1; } else { $convert = $nav_get * $posts_per_page -$posts_per_page; $startrow = (int)$convert; } $prev = $nav_get - 1; if ($prev < 1) { $prev =1; } $next = $nav_get +1; $navigation_url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING); if (!empty($_SERVER["QUERY_STRING"])){ $query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING); $navigation_url .= "?".$query_string; } $navigation_url = trim($navigation_url,$nav_get); //you can change these to your needs if ($url == "http://".$_SERVER['HTTP_HOST'] || $url == "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']) { $navigation_url = "$navigation_url?&page="; } //default query $query = "SELECT * FROM `cars`"; //count the selections for queries $query_count = 0; //set queries and associate WHERE,AND if(isset($_GET['make']) && $_GET['make'] != "All" && $_GET['make'] != ""){ $query_count = $query_count +1; if($query_count == 1) { $where_and = "WHERE"; } else { $where_and = "AND"; } //if selected adds to query $query .= " $where_and Make='$make'"; } if(isset($_GET['model']) && $_GET['model'] != "All" && $_GET['model'] != ""){ $query_count = $query_count +1; if($query_count == 1) { $where_and = "WHERE"; } else { $where_and = "AND"; } //if selected adds to query $query .= " $where_and Model='$model'"; } if(isset($_GET['fuel']) && $_GET['fuel'] != "Any" && $_GET['fuel'] != ""){ $query_count = $query_count +1; if($query_count == 1) { $where_and = "WHERE"; } else { $where_and = "AND"; } //if selected adds to query $query .= " $where_and Fuel='$fuel'"; } if(isset($_GET['location']) && $_GET['location'] != "All" && $_GET['location'] != ""){ $query_count = $query_count +1; if($query_count == 1) { $where_and = "WHERE"; } else { $where_and = "AND"; } //if selected adds to query $query .= " $where_and Location='$location'"; } //find number of total count of GETs for each result minus the limits $total_posts = mysql_num_rows($query); //final query to add the order and limit $query .=" ORDER BY id DESC LIMIT $startrow,$posts_per_page"; //echo $query."<br />";//query built from values above depending on selections $result = mysql_query($query); $lastposts = $total_posts - $posts_per_page; $nextposts = $total_posts +1; $total_posts_pages = $total_posts / $posts_per_page; list($int,$dec)=explode('.', $total_posts_pages); $int_pages = $int +1; $total_pages = $total_posts / $posts_per_page; $page_number = $startrow / $posts_per_page + 1; if ($nextposts >= $int_pages) { $nextposts = $int_pages; $page_one = 1; } if (!$_GET['page']) { $_GET['page'] = 1; } if ($page_number >= $int_pages+1) { $_GET['page'] = $int_pages; } if ($_GET['page'] <= 0) { $_GET['page'] = 1; } if ($page_number <= 0) { $page_number = 1; } if ($total_posts == 0){ echo '<h2>No results found.</h2>'; } echo "Page $page_number of $int_pages - $total_posts Results<br />"; //the page navigation hyperlinks echo "[<a href='./?page=1'><b>New</b></a>]"; echo "[<a href='$navigation_url$page_one'><b>First</b></a>]"; if ($page_number > 1){ echo '[<a href="'.$navigation_url.''.$prev.'"><b><<- Previous.. </b></a>]'; } if ($next <= $prev) { $next = $next+1; } echo "[$page_number]"; if ($next <= $nextposts){ echo '[<a href="'.$navigation_url.''.$next.'"><b> ..Next ->></b></a>]'; } if ($int_pages >= $int_pages){ echo '[<a href="'.$navigation_url.''.$int_pages.'"><b>Last</b></a>]'; } //check if results if(!$result){ echo "No Results <br />"; } else { echo "<table class='ex1' border='0' width='120%' style=text-align:center; cellpadding='6' cellspacing='0'></tr>"; while($row = mysql_fetch_array($result)) { echo "<tr style=font-family:verdana;font-size:80%;>"; echo "<td width=13%>" . $row[""] . "<img src=\"" . $row["Photo"] . "\"></a>"; echo '<td width="14%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Make'] . '</a></td>'; echo '<td width="5%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Model'] . '</a></td>'; echo '<td width="4%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Fuel'] . '</a></td>'; echo '<td width="4%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Location'] . '</a></td>'; echo "</tr>"; } echo "</table>"; } //the page navigation hyperlinks echo "[<a href='./?page=1'><b>New</b></a>]"; echo "[<a href='$navigation_url$page_one'><b>First</b></a>]"; if ($page_number > 1){ echo '[<a href="'.$navigation_url.''.$prev.'"><b><<- Previous.. </b></a>]'; } if ($next <= $prev) { $next = $next+1; } echo "[$page_number]"; if ($next <= $nextposts){ echo '[<a href="'.$navigation_url.''.$next.'"><b> ..Next ->></b></a>]'; } if ($int_pages >= $int_pages){ echo '[<a href="'.$navigation_url.''.$int_pages.'"><b>Last</b></a>]'; } } mysql_close($con); ?> My nephew was blabbing to me entire time did this, hopefully I got it right.
  20. I didn't look too much into the pagination process you did, but I did notice this. change this: while($result_row = mysql_fetch_array($result)) { to this: while($row = mysql_fetch_array($result)) { Even basic pagination is not too easy to do, and I'm talking work correctly. That pagination you did may work for all the queries, but the count will be incorrect because you set the query to all of them, and when you do a certain select or more........it will still be all post results. Anyway, I'm not gonna even bother trying to fix your pagination. Right now I'm writing up your code using my own pagination, I'll post it when I get it done for you to try.
  21. edit your script worked fine for me.
  22. I wanted to add, you can see if your database files exist..or copy them somewhere as a backup from this location. C:\wamp\bin\mysql\mysql5.5.8\data your mysql version may be different. Back it up and try reinstalling wamp.
  23. I don't know too many people that would pay 300 to 500 dollars for NaviCat, that's what the commercial versions are. Mysql Workbench is a free open source solution that probably does even more. http://dev.mysql.com/downloads/workbench/ Regardless what this person uses. Possible problems: windows 7 blocking it a lost, corrupted or deleted file. Possible is in safe mode. The permissions are wrong. Wrong path to php in php.ini file. Database was actually deleted. phpmyadmin needs to be reinstalled.
  24. Yeah sorry about that, was some huge storms here and my server went kaput, then lost dns for a few days as well. I got it sorted and the above links should work now.
  25. Although I've seen many sites similar, I like yours too. Basically you are a cnet, but smaller. Do you manually collect all this information? I just don't see how you can keep up with everything out there. I guess if you keep to quality versus quantity people would like it, less garbage to sift through. Well good luck to you, hope it goes as you planned it.
×
×
  • 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.