PHP - Making The Script Echo Only Specific Results
Hello community, I am working on a database of specialties in the hospital I work. The doctor's referral requests are sent to a mySQL database and I have, with the help of online guidance, produced a working php script that displays the information I need it to. However, I need it a little bit more specific. I intend to make multiple copies of this file for each specialty, so that when they open the file they only have the requests for that particular specialty. My question is, with reference to my code below, can I make echo information so that online, for instance, if 'specialty1 = gastroenterology' (as in, that particular specialty that that referral request is for), then only the rows on the database that have that particular text are displayed only? Hope that makes sense. Code below for your reference and assistance is highly appreciated. <!DOCTYPE html> <html> <head> <title>Specialty Referral Form</title> <style> table { border-collapse: collapse; width: 100%; color: #000000; font-family: arial; font-size: 10px; text-align: center; } th { background-color: #588c7e; color: white; } tr:nth-child(even) {background-color: #f2f2f2} </style> </head> <body> <table> <tr> <th>Patient Details</th> <th>Hospital Number</th> <th>Date of Birth</th> <th>Referred by:</th> <th>New/Repeat Visit to Patient</th> <th>Specialty</th> <th>Admission Date</th> <th>Too Ill for Clinic?</th> <th>Diagnosis Aware?</th> <th>Question</th> <th>History</th> <th>Medications</th> <th>Examination</th> <th>Results</th> <th>WorkingDiagnosis</th> <th>Investigation(s) Requested</th> </tr> <?php $conn = mysqli_connect("localhost", "view", "", "referral"); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT patientdetails, hospitalnumber, DoB, referral, admission, specialty1, admissiondate, illness, awareness, question, history, medications, examination, results, workingdiagnosis, investigations FROM referralform"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while ($row = $result->fetch_assoc()) { echo "<tr><td>" . $row["patientdetails"]. "</td><td>" . $row["hospitalnumber"] . "</td><td>" . $row["DoB"] . "</td><td>" . $row["referral"] . "</td><td>" . $row["admission"] . "</td><td>" . $row["specialty1"] . "</td><td>" . $row["admissiondate"] . "</td><td>" . $row["illness"] . "</td><td>" . $row["awareness"] . "</td><td>" . $row["question"] . "</td><td>" . $row["history"] . "</td><td>" . $row["medications"] . "</td><td>" . $row["examination"] . "</td><td>" . $row["results"] . "</td><td>" . $row["workingdiagnosis"] . "</td><td>" . $row["investigations"]. "</td></tr>"; } echo "</table>"; } else { echo "0 results"; } $conn->close(); ?> </table> </body> </html> I guess what I am looking for is something like echo specialty1 IF it writes a particular specialty and only that specialty. Thank you. Edited April 2, 2020 by samanjSimilar TutorialsHi guys, How do I call the 2nd row of 'TSuperQuestion'? Code: [Select] <?PHP $con = mysql_connect("localhost","ph6theo", "xxxx"); if (!$con) { die('Could not connect: ' . mysql_error("oop")); } mysql_select_db("ph6theo_testDB") or die(mysql_error()); $result = mysql_query("SELECT * FROM QANDATable "); $row = mysql_fetch_array($result); echo $row['TSuperQuestion']; ?> Hey... I'm trying to echo the title of the news in the right column but I just want to display maximum of 25 characters how can I do it? thanks I'm using a wordpress theme that always tries to load a specific search tab first. ive tried figuring out if theres a way to make the second tab load first but cant seem to get it. hopefully someone can help a rookie like myself understand it for a live "demo" to get a sense of what im talking about you can see it here http://demo.woothemes.com/estate/ the Search Our Properties tab loads first. I want it to load the "Search the MLS" tab first or only display and load that one to be honest. Code: [Select] <span id="mls-search"> code is below. thanks! Code: [Select] <?php if (defined('DSIDXPRESS_OPTION_NAME')) { $options = get_option(DSIDXPRESS_OPTION_NAME); } else { $options = array('Activated' => false); } ?> <div class="search-tab <?php if(get_option('woo_idx_plugin_search') != 'true'){ echo 'no-idx'; }?>"> <?php if(get_option('woo_search_header')) { ?> <span id="local-search" class="current"><?php echo stripslashes(get_option('woo_search_header')); ?></span> <?php if ( $options['Activated'] && ( get_option('woo_idx_plugin_search') == 'true' ) ) { ?> <span id="mls-search"><a class="red-highlight"><?php echo stripslashes(get_option('woo_search_mls_header')); ?></a></span> <?php } ?> <?php } ?> </div> <div id="search"> <form name="property-webref-search" id="property-webref-search" method="get" action="<?php bloginfo('url'); ?>/"> <input type="text" class="text webref" id="s-webref" name="s" value="<?php _e('Property ID', 'woothemes'); ?>" onfocus="if (this.value == '<?php _e('Property ID', 'woothemes'); ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e('Property ID', 'woothemes'); ?>';}" /> <input type="submit" class="submit button" name="property-search-webref-submit" value="<?php _e('Go To', 'woothemes'); ?>" /> </form> <form name="property-search" id="property-search" method="get" action="<?php bloginfo('url'); ?>/"> <div class="query"> <?php if (isset($_GET['s'])) { $keyword = strip_tags($_GET['s']); } else { $keyword = ''; } if ( $keyword == 'View More' ) { $keyword = ''; } ?> <input type="text" class="main-query text" id="s-main" name="s" value="<?php if ( $keyword != '' ) { echo $keyword; } else { _e(get_option('woo_search_keyword_text'), 'woothemes'); } ?>" onfocus="if (this.value == '<?php _e(get_option('woo_search_keyword_text'), 'woothemes') ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e(get_option('woo_search_keyword_text'), 'woothemes') ?>';}" /> <input type="submit" class="submit button" name="property-search-submit" value="<?php _e('Search', 'woothemes'); ?>" /> <span class="or"><?php _e('Or', 'woothemes'); ?></span> <div class="fix"></div> </div><!-- /.query --> <div class="filters"> <?php if (isset($_GET['sale_type'])) { $sale_type = $_GET['sale_type']; } else { $sale_type = ''; } if ($sale_type == '') { $sale_type = 'all'; } ?> <div class="saletype"> <label for="saletype"><?php _e(get_option('woo_label_sale_type'), 'woothemes'); ?>:</label> <input type="radio" name="sale_type" value="all" <?php if ($sale_type == 'all') { ?>checked<?php } ?>> <?php _e('All', 'woothemes') ?> <input type="radio" name="sale_type" value="sale" <?php if ($sale_type == 'sale') { ?>checked<?php } ?>> <?php _e(get_option('woo_label_for_sale'), 'woothemes') ?> <input type="radio" name="sale_type" value="rent" <?php if ($sale_type == 'rent') { ?>checked<?php } ?>> <?php _e(get_option('woo_label_for_rent'), 'woothemes') ?> </div><!-- /.saletype --> <div class="location-type"> <label><?php _e(get_option('woo_label_property_location_and_type'), 'woothemes'); ?>:</label> <?php //property locations drop down if (isset($_GET['location_names'])) { $category_ID = $_GET['location_names']; } else { $category_ID = 0; } if ($category_ID > 0) { //Do nothing } else { $category_ID = 0; } $dropdown_options = array ( 'show_option_all' => __(get_option('woo_label_locations_dropdown_view_all')), 'hide_empty' => 0, 'hierarchical' => 1, 'show_count' => 0, 'orderby' => 'name', 'name' => 'location_names', 'id' => 'location_names', 'taxonomy' => 'location', 'hide_if_empty' => 1, 'selected' => $category_ID ); wp_dropdown_categories($dropdown_options); ?> <?php //property types drop down if (isset($_GET['property_types'])) { $category_ID = $_GET['property_types']; } else { $category_ID = 0; } if ($category_ID > 0) { //Do nothing } else { $category_ID = 0; } $dropdown_options = array ( 'show_option_all' => __(get_option('woo_label_property_type_dropdown_view_all')), 'hide_empty' => 0, 'hierarchical' => 1, 'show_count' => 0, 'orderby' => 'name', 'name' => 'property_types', 'id' => 'property_types', 'taxonomy' => 'propertytype', 'hide_if_empty' => 1, 'selected' => $category_ID, 'class' => 'last' ); wp_dropdown_categories($dropdown_options); if (isset($_GET['price_min'])) { $price_min = $_GET['price_min']; } else { $price_min = ''; } if (isset($_GET['price_max'])) { $price_max = $_GET['price_max']; } else { $price_max = ''; } ?> </div><!-- /.location-type --> <div class="fix"></div> <div class="price"> <label for="price_min"><?php _e(get_option('woo_label_min_price'), 'woothemes'); ?> <?php echo '('.get_option('woo_estate_currency').')'; ?>:</label><input type="text" class="text price validate_number" name="price_min" id="price_min" value="<?php if ( $price_min != '' ) { echo $price_min; } ?>" > <label for="price_max"><?php _e(get_option('woo_label_max_price'), 'woothemes'); ?> <?php echo '('.get_option('woo_estate_currency').')'; ?>:</label><input type="text" class="text price validate_number" name="price_max" id="price_max" value="<?php if ( $price_max != '' ) { echo $price_max; } ?>" > </div><!-- /.price --> <span class="advanced-search-button button"><?php _e(get_option('woo_label_advanced_search'), 'woothemes'); ?> ↓</span> <div class="fix"></div> <div id="advanced-search"> <?php if (isset($_GET['no_garages'])) { $no_garages = $_GET['no_garages']; } else { $no_garages = 'all'; } ?> <?php if (isset($_GET['no_beds'])) { $no_beds = $_GET['no_beds']; } else { $no_beds = 'all'; } ?> <?php if (isset($_GET['no_baths'])) { $no_baths = $_GET['no_baths']; } else { $no_baths = 'all'; } ?> <?php if (isset($_GET['size_min'])) { $size_min = $_GET['size_min']; } else { $size_min = ''; } ?> <?php if (isset($_GET['size_max'])) { $size_max = $_GET['size_max']; } else { $size_max = ''; } ?> <?php $options_features_amount = array("0","1","2","3","4","5","6","7","8","9","10+"); ?> <div class="features-filters"> <label for="no_garages"><?php _e(get_option('woo_label_garages'), 'woothemes'); ?>:</label> <select class="postform" id="no_garages" name="no_garages"> <option <?php if ($no_garages == 'all') { ?>selected="selected"<?php }?> value="all"><?php _e('Any', 'woothemes') ?></option> <?php foreach ($options_features_amount as $option) { ?><option <?php if ($no_garages == $option) { ?>selected="selected"<?php }?> value="<?php echo $option; ?>"><?php echo $option; ?></option><?php } ?> </select> <label for="no_beds"><?php _e(get_option('woo_label_beds'), 'woothemes'); ?>:</label> <select class="postform" id="no_beds" name="no_beds"> <option <?php if ($no_beds == 'all') { ?>selected="selected"<?php }?> value="all"><?php _e('Any', 'woothemes') ?></option> <?php foreach ($options_features_amount as $option) { ?><option <?php if ($no_beds == $option) { ?>selected="selected"<?php }?> value="<?php echo $option; ?>"><?php echo $option; ?></option><?php } ?> </select> <label for="no_baths"><?php _e(get_option('woo_label_baths_long'), 'woothemes'); ?>:</label> <select class="postform last" id="no_baths" name="no_baths"> <option <?php if ($no_baths == 'all') { ?>selected="selected"<?php }?> value="all"><?php _e('Any', 'woothemes') ?></option> <?php foreach ($options_features_amount as $option) { ?><option <?php if ($no_baths == $option) { ?>selected="selected"<?php }?> value="<?php echo $option; ?>"><?php echo $option; ?></option><?php } ?> </select> <label for="size_min"><?php _e(get_option('woo_label_min_size'), 'woothemes'); ?> <?php echo '('.get_option('woo_label_size_metric').')'; ?>:</label><input type="text" class="text size validate_number" name="size_min" id="size_min" value="<?php if ( $size_min != '' ) { echo $size_min; } ?>" > <label for="size_max"><?php _e(get_option('woo_label_max_size'), 'woothemes'); ?> <?php echo '('.get_option('woo_label_size_metric').')'; ?>:</label><input type="text" class="last text size validate_number" name="size_max" id="size_max" value="<?php if ( $size_max != '' ) { echo $size_max; } ?>" > </div><!-- /.size --> </div><!-- /#advanced-search --> <div class="fix"></div> </div><!-- /.filters --> <?php $term_names = ''; $price_list = ''; $size_list = ''; //Taxonomies $taxonomy_data_set = get_terms(array('location',/*'pricerange',*/'propertytype','propertyfeatures'), array('fields' => 'names')); $taxonomy_data_set = woo_multidimensional_array_unique($taxonomy_data_set); foreach ($taxonomy_data_set as $data_item) { //Convert string to UTF-8 $str_converted = woo_encoding_convert($data_item); //Add category name to data string $term_names .= htmlspecialchars($str_converted, ENT_QUOTES, 'UTF-8').','; } //Post Custom Fields $meta_data_fields = array('address'); $meta_data_set = woo_get_custom_post_meta_entries($meta_data_fields); $meta_data_set = woo_multidimensional_array_unique($meta_data_set); foreach ($meta_data_set as $data_item) { //Convert string to UTF-8 $str_converted = woo_encoding_convert($data_item->meta_value); //Add category name to data string $term_names .= htmlspecialchars($str_converted, ENT_QUOTES, 'UTF-8').','; } $price_list = ''; //Post Custom Fields $meta_data_fields = array('price'); $meta_data_set = woo_get_custom_post_meta_entries($meta_data_fields); $meta_data_set = woo_multidimensional_array_unique($meta_data_set); foreach ($meta_data_set as $data_item) { //Convert string to UTF-8 $str_converted = woo_encoding_convert($data_item->meta_value); //Add category name to data string $price_list .= htmlspecialchars($str_converted, ENT_QUOTES, 'UTF-8').','; } //Post Custom Fields $meta_data_fields = array('size'); $meta_data_set = woo_get_custom_post_meta_entries($meta_data_fields); $meta_data_set = woo_multidimensional_array_unique($meta_data_set); foreach ($meta_data_set as $data_item) { //Convert string to UTF-8 $str_converted = woo_encoding_convert($data_item->meta_value); //Add category name to data string $size_list .= htmlspecialchars($str_converted, ENT_QUOTES, 'UTF-8').','; } ?> <script> jQuery(document).ready(function($) { <?php if ( ( ($no_garages == 'all') || ($no_garages == '') ) && ( ($no_beds == 'all') || ($no_beds == '') ) && ( ($no_baths == 'all') || ($no_baths == '') ) && ( $size_min == '' ) && ( $size_max == '' ) ) { ?>jQuery("#advanced-search").toggle();<?php } ?> jQuery(".advanced-search-button").click(function(){ var hidetext = 'Hide <?php echo get_option('woo_label_advanced_search'); ?>'; var showtext = '<?php echo get_option('woo_label_advanced_search'); ?>'; var currenttext = jQuery(".advanced-search-button").text(); //toggle advanced search jQuery("#advanced-search").toggle(); //toggle text if (currenttext == hidetext) { jQuery(".advanced-search-button").text(showtext); //reset search values jQuery("#no_garages").val('all'); jQuery("#no_beds").val('all'); jQuery("#no_baths").val('all'); } else { jQuery(".advanced-search-button").text(hidetext); } }); //GET PHP data items var keyworddataset = "<?php echo $term_names; ?>".split(","); var pricedataset = "<?php echo $price_list; ?>".split(","); var sizedataset = "<?php echo $size_list; ?>".split(","); //Set autocomplete(s) $("#s-main").autocomplete(keyworddataset); $("#price_min").autocomplete(pricedataset); $("#price_max").autocomplete(pricedataset); $("#size_min").autocomplete(sizedataset); $("#size_max").autocomplete(sizedataset); //Handle autocomplete result $("#s").result(function(event, data, formatted) { //Do Nothing }); $("#price_min").result(function(event, data, formatted) { //Do Nothing }); $("#price_max").result(function(event, data, formatted) { //Do Nothing }); $("#size_min").result(function(event, data, formatted) { //Do Nothing }); $("#size_max").result(function(event, data, formatted) { //Do Nothing }); }); </script> <div class="fix"></div> </form> <?php if ( $options['Activated'] && ( get_option('woo_idx_plugin_search') == 'true' ) ) { $pluginUrl = DSIDXPRESS_PLUGIN_URL; $formAction = get_bloginfo("url"); if (substr($formAction, strlen($formAction), 1) != "/") $formAction .= "/"; $formAction .= dsSearchAgent_Rewrite::GetUrlSlug(); ?> <form name="property-mls-search" id="property-mls-search" method="get" action="<?php echo $formAction; ?>"> <?php $defaultSearchPanels = dsSearchAgent_ApiRequest::FetchData("AccountSearchPanelsDefault", array(), false, 60 * 60 * 24); $defaultSearchPanels = $defaultSearchPanels["response"]["code"] == "200" ? json_decode($defaultSearchPanels["body"]) : null; $propertyTypes = dsSearchAgent_ApiRequest::FetchData("AccountSearchSetupPropertyTypes", array(), false, 60 * 60 * 24); $propertyTypes = $propertyTypes["response"]["code"] == "200" ? json_decode($propertyTypes["body"]) : null; $requestUri = dsSearchAgent_ApiRequest::$ApiEndPoint . "LocationsByType"; //cities $location_cities = explode("\n", get_option('woo_idx_search_cities')); //communities $location_communities = explode("\n", get_option('woo_idx_search_communities')); //Tracts $location_tracts = explode("\n", get_option('woo_idx_search_tracts')); //Zips $location_zips = explode("\n", get_option('woo_idx_search_zips')); ?> <div class="mls-property-type"> <label for="idx-q-PropertyTypes"><?php _e('Property Type', 'woothemes'); ?>:</label> <select name="idx-q-PropertyTypes" class="dsidx-search-widget-propertyTypes"> <option value="All">- All property types -</option> <?php if (is_array($propertyTypes)) { foreach ($propertyTypes as $propertyType) { $name = htmlentities($propertyType->DisplayName); echo "<option value=\"{$propertyType->SearchSetupPropertyTypeID}\">{$name}</option>"; } } ?> </select> <label for="idx-q-MlsNumbers"><?php _e('MLS #', 'woothemes'); ?>:</label> <input id="idx-q-MlsNumbers" name="idx-q-MlsNumbers" type="text" class="text" /> </div> <div class="fix"></div> <div class="mls-area-details"> <label for="idx-q-Cities"><?php _e('City', 'woothemes'); ?>:</label> <select id="idx-q-Cities" name="idx-q-Cities" class="small"> <?php if (is_array($location_cities)) { foreach ($location_cities as $city) { $city_name = htmlentities(trim($city)); echo "<option value=\"{$city_name}\">$city_name</option>"; } } ?> </select> <label for="idx-q-Communities"><?php _e('Community', 'woothemes'); ?>:</label> <select id="idx-q-Communities" name="idx-q-Communities" class="small"> <option value="">- Any -</option> <?php if (is_array($location_communities)) { foreach ($location_communities as $community) { $community_name = htmlentities(trim($community)); echo "<option value=\"{$community_name}\">$community_name</option>"; } } ?> </select> <label for="idx-q-TractIdentifiers"><?php _e('Tract', 'woothemes'); ?>:</label> <select id="idx-q-TractIdentifiers" name="idx-q-TractIdentifiers" class="small"> <option value="">- Any -</option> <?php if (is_array($location_tracts)) { foreach ($location_tracts as $tract) { $tract_name = htmlentities(trim($tract)); echo "<option value=\"{$tract_name}\">$tract_name</option>"; } } ?> </select> <label for="idx-q-ZipCodes"><?php _e('Zip', 'woothemes'); ?>:</label> <select id="idx-q-ZipCodes" name="idx-q-ZipCodes" class="small"> <option value="">- Any -</option> <?php if (is_array($location_zips)) { foreach ($location_zips as $zip) { $zip_name = htmlentities(trim($zip)); echo "<option value=\"{$zip_name}\">$zip_name</option>"; } } ?> </select> </div> <div class="fix"></div> <div class="mls-features"> <label for="idx-q-PriceMin"><?php _e('Min Price', 'woothemes'); ?>:</label> <input id="idx-q-PriceMin" name="idx-q-PriceMin" type="text" class="text validate_number" /> <label for="idx-q-PriceMax"><?php _e('Max Price', 'woothemes'); ?>:</label> <input id="idx-q-PriceMax" name="idx-q-PriceMax" type="text" class="text validate_number" /> <label for="idx-q-ImprovedSqFtMin"><?php _e('Min Size', 'woothemes'); ?> <?php echo '(SQ FT)'; ?>:</label> <input id="idx-q-ImprovedSqFtMin" name="idx-q-ImprovedSqFtMin" type="text" class="text validate_number" /> <label for="idx-q-BedsMin"><?php _e('Beds', 'woothemes'); ?>:</label> <input id="idx-q-BedsMin" name="idx-q-BedsMin" type="text" class="text validate_number" /> <label for="idx-q-BathsMin"><?php _e('Baths', 'woothemes'); ?>:</label> <input id="idx-q-BathsMin" name="idx-q-BathsMin" type="text" class="text validate_number" /> </div> <input type="submit" value="Search" class="submit button" /> <?php if($options["HasSearchAgentPro"] == "yes"){ echo 'try our <a href="'.$formAction.'advanced/"><img src="'.$pluginUrl.'assets/adv_search-16.png" /> Advanced Search</a>'; } ?> <div class="fix"></div> </form> <?php } ?> </div><!-- /#search --> Hello. I am trying to make a very simple shopping cart. The add to cart button on a product simply just insert a record to my shopping cart table in MySQL. and then my shopping cart just reads from that table, and displays in a table. What i want now is a "remove from shopping cart" button, a button that removes the product on the same line as the button. How do i do that? Thanks I'm storing website files online and each user can upload their own files and admin can upload files for that user specifically. How would I go about making sure nobody else can download their PDF file? Would it be a case of assigning a folder for each user's documents and not allowing access to any other user to that folder?
Thanks in advance.
Hi, fairly new to PHP over the last couple weeks. Been having a problem with certain queries. I have a database with football results, games, teams etc. I can filter these using drop down and that's all well and good. The problem I'm having is displaying the data via gameweek. I've been asked to display the table like so - Gameweek1 will display week1 teams, results etc. Gameweek2 will display week2... and so on.
I can manage to do this in a drop down. But I've been asked to display this using links like "Previous, 1, 2, 3 Next". I've tried pagination but I couldn't figure it out. Can anyone point me in the right direction? If I need a GET() method, how would I go about coding that so it will be used in a link(s)? Been searching and searching to find an answer but to no avail...
//Database connection etc... $gameweek = "SELECT * FROM games WHERE gameweek= 1"; //if(isset($_GET['gameweek'])) //{ // $gameweek = $_GET['gameweek']; // //} //.... $result=mysqli_query($connection, "select * from games WHERE gameweek= 1"); //Print table and table headings... mysqli_close($connection); ?> <a href="http://weeks.php?gameweek=2">Week 2</a> <a href="http://weeks.phpgameweek=3">Week 3</a> </body> </html> Code: [Select] if (isset($_POST['update'])) { $signature = $_POST['signature']; $type = $_POST['type']; $name = $_POST['name']; $b=0; While ($b < $i) { echo $signature[$b]."<br>"; echo $type[$b]."<br>"; echo $name[$b]."<br><br>"; $b++; }} I did echo '<pre>'; print_r($_POST); echo '</pre>'; The results are Code: [Select] Array ( [sname] => [notes] => [signature] => Array ( [0] => 1-1 [1] => 1-2 [2] => 1-3 ) [type] => Array ( [0] => Test1 [1] => Test2 [2] => Test3 ) [name] => Array ( [0] => Testa [1] => Testb [2] => Testc ) [update] => Update ) But for some reason nothing is showing up on the screen. Hi, I have a searchbar which looks for a value in my tables, it works great but i want to know how i can make the results of the search clickable; go to a page relevent to that search, let me explain in more depth. User searches for a postcode, script finds and displays the postcode on the next page, user clicks the result postcode to goto the next page. What im stuck with is how to take that result and automatically display it on the clicked "final" page? Search script: Code: [Select] <?php // Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit=10; // check for an empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } // check for a search parameter if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } //connect to your database ** EDIT REQUIRED HERE ** mysql_connect("xxxxx","xxxx","xxxx"); //(host, username, password) //specify database ** EDIT REQUIRED HERE ** mysql_select_db("removalspacelogin") or die("Unable to select database"); //select which database we're using // Build SQL Query $query = "(SELECT postcode FROM freelistings WHERE postcode like '%$trimmed%') UNION (SELECT postcode FROM basicpackage WHERE postcode like '%$trimmed%') UNION (SELECT postcode FROM premiumuser WHERE postcode like '%$trimmed%') ORDER BY postcode"; // EDIT HERE and specify your table and field names for the SQL query $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); $result = mysql_query($query) or die("<b>Query:</b> $query<br><b>Error</b>: " . mysql_error()); // If we have no results, offer a google search as an alternative if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; echo "<p><a href=\"http://www.google.com/search?q=" . $trimmed . "\" target=\"_blank\" title=\"Look up " . $trimmed . " on Google\">Click here</a> to try the search on google</p>"; } // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for echo "<p>You searched for: "" . $var . ""</p>"; // begin to show results set echo "Results for $q"; $count = 1 + $s ; // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row['postcode']; echo " $title" ; $count++ ; } $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?> <form method="post" action="localarea.php"> <a href="localarea.php"><?php echo """ .$var. ""</p>";?></a> </form> [\code] The form at the bottom im guessing is where i should take the $var from but how exactly? or if not where should it be pulled from to display on the next page? I want this "next" page because ideally there would be lots of results in postcode, so the user can choose which one is more relevant to them and go to that specific page with all the companies within that postcode. Hope this helps for a better understanding of what im trying to achieve, its just implementing it in? Ok, here's my code: How do i make it so that it outputs a maximum of only 5 results from the query where the img file exists. When I add LIMIT to the sql query it doesnt work so I guess its something else, but I have no clue. Can anyone help? $query = mysql_query("SELECT * FROM table WHERE date >= '$now' ORDER BY max(date) desc"); while ($row = mysql_fetch_assoc($query)) { $cid = $row['cat_id']; $title = $row['name']; $seoname = $row['seourl']; $img = 'images/'.$seoname.'.jpg'; if (!file_exists($img)) { $img = ''; } else { $img = 'images/'.$seoname.'.jpg'; } if (!empty($img)) { echo '<a href="images/'.$seoname.'/"><img src="'.$img .'" style="width:528px;" alt="" /></a>' . "\n"; } } Thanks. How do I present these documentaries like this:
0-9
10 Things You Need to Know About Sleep
20 Animals That Will Kill You
A
Ant Kingdom
Atkins Diet
B
Battle of the Brains
Body Talk
I don't even know where to start!
I'm not asking anyone to do this for me; I just need a push in the right direction.
Any help will be appreciated.
Ive gotten some results user selcts check box on first page The php page will say which brackets it falls between example price is between 100-300 say I dont seem to be able to populate a table with the data in the database:S Code: [Select] $row_number= 0; while ($row = mysql_fetch_array($result3)) { If (($row["price"] = $price_low) && ($row["price"] <= $price_high)) //price If (($row["storage"] = $storage_low) && ($row["storage"] <= $storage_high)) //storage if (($row["Processor "] = $processor_low) && ($row["Processor"] <= $processor_high)) //Processor { $row_number++; ?> <tr> <td align="center"><?php print $row["Computer_Price"]; ?> </td> <td align="center"><?php print $row["Computer_Storage"]; ?> </td> <td align="center"><?php print $row["Computer_ProcessorSpeed"]; ?> </td> </tr> </table> Thats wat im usign atm the price_low and price_high are what sets the low and high price for the search Hello, im new here, and i have little experience to php and mysql as i started for 2 weeks ago. I started out with some tutorials and feeling im getting the hang of it. Enough of me, lets get to the point: <?php $con = mysql_connect('localhost',$user,$pass)or die(mysql_error()); $selectdb = mysql_select_db($selectdb)or die(mysql_error()); $sql = "SELECT * From table"; $result = mysql_query($sql); $num = mysql_num_rows($result); $myarray = array($result); $i =0; while ($i < $num){ echo $myarray[$i]; $i++; } ?> Here i have written a dummyscript that does what the original script does, it tries to fetch the keys from the table and then trying to loop it and echo out the results. The output in the browser is this: Resource id #3 I know this probably is a simple fix but i cant seem to get it sorted out. Hope some of you could help me get this baby work, or maybe have another way of doing it more "simple". Thanks in advance! Dan-Levi i have built pages that paginate with 10 rows per page (some pages show more but for the moment i want to focus on this particular page)
//Define Some Options for Pagination $num_rec_per_page=10; if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * $num_rec_per_page; $results = mysql_query("SELECT * FROM `ecmt_memberlist` WHERE toonCategory='Capital' AND oldMember = 0 ORDER BY CONCAT(MainToon, Name) LIMIT $start_from, $num_rec_per_page") or die(mysql_error()); $results_array = array(); while ($row = mysql_fetch_array($results)) { $results_array[$row['characterID']] = $row; }The above sets the variables for the pagination and below the results are echo with 10 rows per page then i show the pagination links: <?php $sql = "SELECT * FROM `ecmt_memberlist` WHERE toonCategory='Capital' AND oldMember = 0 ORDER BY CONCAT(MainToon, Name)"; $rs_result = mysql_query($sql); //run the query $total_records = mysql_num_rows($rs_result); //count number of records $total_pages = ceil($total_records / $num_rec_per_page); ?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="center"><div style="width:100%; text-align:center;"> <ul class="pagination"> <li class="selected"> <?php echo "<a href='capitalmember.php?page=1'>".'«'."</a> ";?> </li> <? for ($i=1; $i<=$total_pages; $i++) { echo "<li><a href='capitalmember.php?page=".$i."'>".$i."</a></li> "; }; ?> <li class="selected"> <? echo "<a href='capitalmember.php?page=$total_pages'>".'»'."</a> "; // Goto last page ?></li> </ul></div> <?php $pageNr = $page; // Get Current Page Number $from = $pageNr * $rowsPerPage; // 3 * 10 = 30 // 3 * 10 = 30 $to = $from + $rowsPerPage; // 30 + 10 = 40 echo $pageNr; /* Result: From page 30 to 40 */ ?></td> </tr> </table>this works great and shows me 10 results per page, what i need to work out and work on next is: echo the number of results above the records (for example: "showing records 1 to 10" and then on page 2 "showing records 11 to 21" and page 3 "showing records 22 to 32" how can i work out the maths for this echo? i was thinking along the lines of; <?php $pageNr = $page; // Gets Current Page Number $from = $pageNr * $rowsPerPage; // 3 * 10 = 30 $to = $from + $rowsPerPage; // 30 + 10 = 40 // Now Show Results echo $from; // Echo from echo $to // Echo to ?>but i'm still working on this.. then i need to look at shortening the amount of page links on the page if for example i have 500 records it shows me links 1 to 50 and eats up the page.... Appreciate any help and light onto my problems. Many thanks Edited by jacko_162, 11 January 2015 - 05:43 PM. I think I understand that there can only be one "submit" button on a page.
I want buttons for separate forms to not trigger the empty errors on the other forms...
How do you accomplish specific button actions?
I think I've tried it with javascript but you can do it with PHP right?
Thanks for any help.
here is my code... please help <form method="get" action="shit3.php"> <input maxlength="50" size="50" type="text" name="q"> <input type="submit" value="SEARCH"> </form> <?php if (@$_GET['q']) { $var = $_GET['q'] ; $trimmed = trim($var); $limit=1; if ($trimmed == "") { echo "Please enter a search..."; exit; } if (!isset($var)) { echo "Container not found!"; exit; } mysql_connect("localhost", "xxx", "yyy") or die(mysql_error()); mysql_query("SET NAMES 'cp1251'"); mysql_select_db("agaexpor_container") or die("Unable to select database"); //select which database we're using $query = "select * from containertracking where vin like \"%$trimmed%\" order by vin"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); if (empty($s)) { $s=0; } $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); $count = 1 + $s ; while ($row= mysql_fetch_array($result)) { $vin = $row["vin"]; $container = $row["container"]; echo "$count.) VIN: $vin <br />"; echo "container is: $container <br />"; $count++ ; } } ?> Does any one know how to run PHP script automatically at specific time interval in my local machine. I am using Windows 7. What about using the Task scheduler ? Please write to me in details how to give the path of the php page in Task Scheduler. I need help making img src work without using echo. The session has been started from another page. Code: [Select] <?php $name = $_FILES['change']['name']['myfile']; $tmp_name = $_FILES['change']['tmp_name']['myfile']; if($name) { //start upload process $dblocation = "$name"; $location = "photos/$name"; move_uploaded_file($tmp_name,$location); $origloc = $location; $_SESSION['imglocation'] = $origloc; echo "<img src='../crop.php?h=50&w=50&f=$origloc' />"; } ?> my site is laid out as follows: beta.domain.com/index.html <-- this page contains an ajax form scripts.domain.com/js/formoperations.js <--ajax javascript scripts.domain.com/php/msgsend.php <--ajax php script The PHP script which is posted below is to echo back "Thank you" once the form is processed & emailed. If the files are in the directories stated above the PHP script does not echo back. It still completes emailing the form data successfully but does the echo does not make it back to beta.domain/index.html. HOWEVER...if I move my PHP file to beta.domain.com/msgsend.php it works flawlessly. Why can't my script echo across subdomains? Thanks! Code: [Select] <?php $fname= urldecode($_GET['param']); $lname = urldecode($_GET['param1']); $email = urldecode($_GET['param2']); $details = urldecode($_GET['param3']); $datereported = date(n."/".j."/".Y." @ ".g.":".i." ".A); $text="<p><b>First Name:</b> ".$fname."</p><p><b>Last Name:</b> ".$lname."</p><p><b>Email Address:</b> ".$email."</p><p><b>Message:</b> ".$details."</p>-End Submission"; $plaintext="First Name: ".$fname."\nLast Name: ".$lname."\nEmail Address: ".$email."\nMessage: ".$details."\n\n End Submission"; $to = 'chris@domain.com'; $subject = 'Web Message'; $random_hash = md5(date('r', time())); $headers = "From: Web Message\r\nReply-To: info@domain.com"; $headers .= "\r\nContent-Type: text/html; charset='iso-8859-1' Content-Transfer-Encoding: 7bit"; ob_start(); ?> <img src="http://uniformimgs.domain.com/emailheadcontact.gif" alt="" /> <p style="font-family:Arial, Helvetica, sans-serif; font-size:12px; margin:15px 0 50px 0;"><?php echo $fname.' '.$lname; ?> has submitted a message from the website on <?php echo $datereported; ?>.</p> <?php echo $text; ?> <? $message = ob_get_clean(); if(mail($to, $subject, $message, $headers)) { echo '<h4>Thanks for your message '.$fname.'!</h4><br/><br/><br/><br/>'; $to = $email; $subject = 'Thanks for your message!'; $random_hash = md5(date('r', time())); $headers = "From: info@domain.com\r\nReply-To: info@domain.com"; $headers .= "\r\nContent-Type: text/html; charset='iso-8859-1' Content-Transfer-Encoding: 7bit"; ob_start(); ?> <img src="http://uniformimgs.domain.com/emailheadcontact.gif" alt="" /> <p style="font-family:Arial, Helvetica, sans-serif; font-size:12px; margin:15px 0 5px 0;">Dear <?PHP echo $fname ?>,</p> <p style="font-family:Arial, Helvetica, sans-serif; font-size:12px; margin:0;">Thank you for sending us a message from our website; we love hearing from you folks! If needed, we'll contact you as soon as possible in regards to your message.</p> <p style="font-family:Arial, Helvetica, sans-serif; font-size:12px; margin:20px 0 0 200px;">Sincerely,</p> <p style="margin: 10px 0 0 200px;"><img src="http://uniformimgs.domain.com/briansig.gif" alt="" /></p> <p style="font-family:Arial, Helvetica, sans-serif; font-size:10px; margin:0px 0 0 200px;">John R Smith, pricipal</p> <p style="font-family:Arial, Helvetica, sans-serif; font-size:10px; margin:200px 0 0 0">This email has been sent by an automated service</p> <? $message = ob_get_clean(); //send the email mail($to, $subject, $message, $headers); } else { echo "<h5>Oops! Seems like we have a problem.</h5><h6>Please try again later or call XXX-XX-XXX.</h6>"; } ?> Hey, I am currently trying to get a variable created inside a require_once script to be echoed inside the main page that called the require. The script below is a basic idea of what i want to do. I just want to be able to create a basic variable none of this session stuff as its makes life harder at the moment. Thank guys, hope the snippet below gives you a better idea. Main Code: Code: [Select] <body> <?php require_once("makesVariable.php"); <div> // Variable I want to be echo "NOT WORKING" echo $var; </div> ?> </body> External PHP Code: Code: [Select] <?php //Function gets called by previous code to create the needed variable function createTheVariable(){ $var = "I am the variable to be called"; return $var; } ?> I would be needing different picture sizes on different pages on my site but saving different sizes of a single pic is space consuming. I've heard that it's possible to automatically adjust the size of the picture and found a script that ought to make that possible. Unfortunately, it did not work for me. Article: PHP Thumbnail Script Using GD http://www.rainbodesign.com/pub/thumbnails/ Here's the code: Code: [Select] <? // Rainbo Design PHP Thumbnail Maker // Copyright (C) 2005-2010 by Richard L. Trethewey - rick@rainbo.net // All Rights Reserved // If you use this script, I'd appreciate a link! // http://www.rainbodesign.com/pub/ // Defaults $thumbsize = 150; // Default thumbnail width. $imagesource = 'images/default_img.jpg'; // Default image file name. // Set to empty string for no image output on failure. $error = ''; if (isset($_GET['width'])) { $thumbsize = $_GET['width']; } if (isset($_GET['src'])) { $imagesource = $_GET['src']; } $filetype = substr($imagesource,strlen($imagesource)-4,4); $filetype = strtolower($filetype); if (file_exists($imagesource)) { if($filetype == ".gif") $image = @imagecreatefromgif($imagesource); if($filetype == ".jpg") $image = @imagecreatefromjpeg($imagesource); if($filetype == ".png") $image = @imagecreatefrompng($imagesource); $imagewidth = imagesx($image); $imageheight = imagesy($image); if ($imagewidth >= $thumbsize) { $thumbwidth = $thumbsize; $factor = $thumbsize / $imagewidth; $thumbheight = floor($imageheight * $factor); } else { $thumbwidth = $imagewidth; $thumbheight = $imageheight; $factor = 1; } // Create a thumbnail-sized GD Image object $thumb = @imagecreatetruecolor($thumbwidth,$thumbheight); // bool imagecopyresized ( resource dst_image, resource src_image, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h ) imagecopyresized($thumb, $image, 0, 0, 0, 0, $thumbwidth, $thumbheight, $imagewidth, $imageheight); // Send output to user as a jpeg type, regardless of original type header("Content-type:image/jpeg;"); imagejpeg($thumb); imagedestroy($image); imagedestroy($thumb); } else { $error = "File $imagesource Not Found"; } // endif file_exists if ($error != '') { header('Content-type:text/plain;'); echo($error); exit; } // endif $error ?> And here's a little instruction (which I have followed as well). Quote All it takes is replacing the "src" parameter in the <img> tag with the URL for the PHP script, including the parameters "src" which contains the path to the original image file, and "color" to select the color for the font. The script also supports a "width" parameter to specify the width of your thumbnail image. Using that script to display the above image as a thumbnail by setting the "src" attribute to "makeThumb.php?src=slides/slide1.jpg", we get the resulting image shown on the right. Can anyone please help me with this script or something similar? Thanks in advance. ^_^ Edit: The problem is that the image is not showing. It appears as if it cannot locate the file source. |