PHP - Login Using Specific Id And Then Only Display Certain Data
In follow up to my previous post, I have found a way to display my data but now I am wanting to only display certain data (within an 'if' statement). For example, if I login as a particular student and there is three sets of data in there e.g. MATH1023, ENG1003 and ENG1013 but I only want to display the student's MATH1023 data in a section, how do I do this? I know that I need to do some sort of an IF statement where 'crsecode=MATH1023' but for some reason I cannot get this to work without it pulling this along with the two English courses.
Here is my code: Code: [Select] <?php $db_host = "locahost"; $db_user = "dbuser"; $db_pass = "dbpassword"; $db_name = "dbconnection"; $dbac = mysql_connect($db_host,$db_user,$db_pass); mysql_select_db ($db_name) or die ("Cannot connect to database."); if (!$_POST['search']){ ?> <form name="Item Search" method="post" action=""> Item Search:<br> <label> <input name="swords" type="text" size="30" maxlength="30"> </label> <br> <label> <input name="search" type="submit" id="search" value="Search"> </label> </form> <?php }else{ $searchwords = addslashes(htmlspecialchars($_POST['swords'])); if (strlen($searchwords) < 2){ echo "Your search must contain at least 3 characters. Please try again.<br><input type=button value='Back' onClick='history.go(-1)'>"; }else{ $words = explode(' ',$searchwords); $totalwords = count($words); $i = 0; $searchstring = ""; while ($i != $totalwords){ if ($i != 0 and $i != $wordcount){ $searchstring .= " and ";; } $searchstring .= "cwid LIKE '%$words[$i]%'"; $i = $i + 1; } $query = mysql_query("SELECT DISTINCT * FROM transferdatafile where $searchstring"); if (mysql_num_rows($query) == 0){ echo "No results were found.<br><input type=button value='Back' onClick='history.go(-1)'>"; }else{ echo '<table border=1>'; while ($row = mysql_fetch_array($query)){ echo '<tr>'; echo '<td>'.$row['firstname'].'</td>'; echo '<td>'.$row['lastname'].'</td>'; echo '<td>'.$row['subj'].'</td>'; echo '<td>'.$row['course'].'</td>'; echo '<td>'.$row['crsecode'].'</td>'; echo '<td>'.$row['crsegrade'].'</td>'; // etc echo '</tr>'; } echo '</table>'; } } } ?> Here is the output that I currently get with this when all I want is MATH1023 to display for this particular student's ID (see attachment). Anyone help? [attachment deleted by admin] Similar TutorialsHi this is what I have set up - SQL tables - Members - memberid - primary key Username Password Orders - Orderid - primary key memberid - foreign key orderno In my sql table there are two members and two orders. 1 order is assigned to 1 member and the other order to the other member. After each member logs in I need to 'echo' that order on the page. I've not been able to write any succesful php code that 'gets' the specific order that is related to the member that has signed in. I would appreciate help on this! Thanks is it possible to disable warnings on a specific page? php.ini set to show warnings 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 --> Hi I am trying to create a dynamic gallery in php with specific order of pictures on the page, but I can't find the function or piece of php code to do so.
Conditions: My code: $files = glob("layout/gallery/*.jpg"); rsort($files, SORT_NATURAL); for ($i=0; $i < count($files); $i++) { for( ; $i<5; $i++){ $one = $files[$i]; echo '<img src="'.$one.'">' . '<br><br>'; } echo "<br>"; for( ; $i<9; $i++){ $two = $files[$i]; echo '<img src="'.$two.'">' . '<br><br>'; } } The code works well, but it just displays 9 pictures obviously. I was unable to make it dynamic displaying 5 pictures first, 4 pictures after and stay this way in a loop till displays all pictures from that folder. I am wondering if it's possible to get some data from another website via PHP? I would like to get data from website http://www.gamersfirst.com/warrock/?q=Player&nickname=soldier, and the exact data which I need is "Level" which is in this case 2. Can this value be grabbed and if it can, where can I get some info about how to do it? I have json code and i want to prine only {"currency":"DOGE","available":"0","reserved":"420.000000000"} data. my json data [{"currency":"1ST","available":"0","reserved":"0"},{"currency":"DOGE","available":"0","reserved":"420.000000000"},{"currency":"ZSC","available":"0","reserved":"0"}] I use this code
<?php ?> <ul> <!-- List the rest of the articles found in the category --> <?php else : ?> <li class="otherrecentmain"><span class="title"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></span> <span class="meta"></span> </li> <?php endif; ?> <?php endwhile; ?> <!-- END --> </ul> For some reason, its stuck on displaying 9 articles but I want to be able to control how many I want. I may want to choose 17 or whatever etc, not sure how to add it into the php. i have a register and login page where the users can perform register and login task and their detail gets saved in the database. my requirement is that when the user enters his/her account, they should be redirected to their profile page, where they can view all their profile details. Till now i have been able to make the user login and dislay a part of their profile page, for this purpose the code that i am using is
<code>
<?php I'm new to PHP and I have an html page I would like to pull specific data into certain areas on the page that I will modified for php. Here are some details. The page is a static html page that has the prices of 40+ products in a standard <li> list. When I update the prices in our database through our shopping cart, I have to change these prices manually in the html. https://www.novon.co...mic_mixers.html. It would be great if I could link the field for Base_Price in the products table to each affiliated <li> tag, I am pulling all the data I need into ($results) and can display it all but I don't know how to get just the single products Base_Price in my <li> tag. <?=$row['Base_Price'] ?> I know this code is not correct but to get the point across, can I create a variable that I define in each <li> tag with a statement like,,,, <?=$row['Base_Price with Product_Code=123456'] ?> I could create a new SQL query for each <li> like "SELECT Base_Price from Products WHERE Product_Code='123456' ", but that's a lot of calls to the DB and a lot of code on the page. And just so I weed out the hard core coders, I can not rebuild the entire page. This is too big of a project for me and my limited coding with PHP. Can anyone help?? Thanks in advance Michael I am trying to get specific data from a MySQL table but cannot seem to find a proper command. Code: [Select] $link = mysqli_connect('#####', '########', '########'); $user = $_SESSION['username']; $email = mysqli_query($link,"select email from members where username='$user'"); echo $email; Specifically, I am trying to get the email address stored for the user specified by the session, and display that address. However, I do not get any output with the current code, and am not sure what to try next. I have tried mysqli_fetch_row() but it only returns an error. Hi guys ..
please help me .. I don't know how to do this and I tried but there were no satisfied results..
I want to retrieve a Title (ing_title) from a database called k_db2 , in a table called content_langs
depending on its ID , which called ing_contID
example: if ing_contID=1 , then show the ing_title with this id ing_contID
the above code should be in a php file ..
then I want to include this php file inside the header of my website..
by importing the ing_contID from the database and depending on it the title should be shown..
I really tried but I couldn't find any solution ..
if you could help me in the first part of this problem I'll be glad ..
Hi I have been trying to populate my data from 3 tables and display like this: DATE $acronym1 $acronym2 POSTS 1/9/2011 10 (this is no of posts) 3 POSTS 31/8/2011 20 10 and so on. the threads and user table will be similar as well. I am not able to populate the distinct dates since the dateline contains time as well. So when I try to print out the just dates(without time) , it prints with the dates repeated. it prints something like this: 1/9/2011 1 1/9/2011 1 and so on.. How can populate and print the the date and number of posts in the above format. Here is my complete code below: Code: [Select] <?php error_reporting(-1); //ini_set('display_errors',1); include("db.php"); //$thirty_days_ago = strtotime("-30 days"); $limit = strtotime("-1 month"); $sql=mysql_query(("SELECT * from new_site"),$con) or die(mysql_error()); while($row=mysql_fetch_assoc($sql)) { $include=$row['include']; $forumurl=$row['forumurl']; $url=$row['url']; $acronym=$row['acronym']; include("$include"); //echo $include."<br>"; $configdbname=$config['Database']['dbname']; $configdbconport=$config['MasterServer']['servername'].":".$config['MasterServer']['port']; $configusername=$config['MasterServer']['username']; $configpassword=$config['MasterServer']['password']; $configprefix=$config['Database']['tableprefix']; /* Connect to the required database */ $con2=mysql_connect($configdbconport, $configusername, $configpassword); if (!$con2) { die('Could not connect: ' . mysql_error()); } mysql_select_db($configdbname, $con2); $postdate=mysql_query("SELECT DISTINCT dateline,postid from post WHERE dateline >='$limit' ORDER by dateline DESC") or die(mysql_error()); while($postdate_results=mysql_fetch_assoc($postdate)) { $postdate_record=$postdate_results['dateline']; // echo $postdate."<br>"; $postdate_formatted=date('M dS Y ',$postdate_results['dateline']); $post_count=mysql_query("SELECT * from post WHERE dateline >='$postdate_record'"); while($post_count_results=mysql_fetch_assoc($post_count)) { //$postdate_formatted=date('M dS Y ',$post_dateline_results['dateline']); $posts=mysql_num_rows($post_count) or die(mysql_error()); //echo $acronym.":POSTS:".$posts."<br>"; echo '<table border="1">'; echo "<tr>"; echo "<th>Category</th>"; echo "<th>".$acronym."</th>"; echo "</tr>"; echo "<tr>"; echo "<td>POSTS:DATE:".$postdate_formatted."</td>"; echo "<td>".$posts."</td>"; echo "</tr>"; } $threaddate=mysql_query("SELECT * from thread WHERE dateline >='$limit' ORDER by dateline DESC") or die(mysql_error()); while($threaddate_results=mysql_fetch_assoc($threaddate)) { $threaddate_record=$threaddate_results['dateline']; $threaddate_formatted=date('M dS Y ',$threaddate_results['dateline']); $thread_count=mysql_query("SELECT * from thread WHERE dateline='$threaddate_record'"); while($thread_count_results=mysql_fetch_assoc($thread_count)) { $threads=mysql_num_rows($thread_count) or die(mysql_error()); //echo $acronym.":THREADS:".$threads."<br>"; echo "<tr>"; echo "<td>THREADS:DATE:".$threaddate_formatted."</td>"; echo "<td>".$threads."</td>"; echo "</tr>"; $userdate=mysql_query("SELECT * from user WHERE joindate >='$limit' ORDER by joindate DESC") or die(mysql_error()); while($userdate_results=mysql_fetch_assoc($userdate)) { $userdate_record=$userdate_results['joindate']; $userdate_formatted=date('M dS Y ',$userdate_results['joindate']); $user_count=mysql_query("SELECT * from user WHERE joindate='$userdate_record'"); while($user_count_results=mysql_fetch_assoc($user_count)) { $users=mysql_num_rows($user_count) or die(mysql_error()); //echo $acronym.":USERS REGISTERED:".$users."<br>"; echo "<tr>"; echo "<td>REGISTERED USERS::DATE:".$userdate_formatted."</td>"; echo "<td>".$users."</td>"; echo "</tr>"; } } } } } } echo "</table>"; ?> Hello All, Please excuse my lack of knowledge in advance, I'm a beginner but pick things up relatively quickly, and tend to do things by trial and error. I would appreciate any help that anyone could offer with the following: I would like to retrieve two pieces of data from a "text file" and use them to calculate a result from a function I have in javascript. An example of the javascript code is: <script type="text/javascript"> function calculate() { var drybulb = document.calc_form.drybulb.value; var relhum = document.calc_form.relhum.value; var answer = ''; if (drybulb !== '' && relhum !== '') { answer = (0.567*drybulb*1) + (0.393 * (relhum*1/100 * 6.105 * Math.exp(17.27 * drybulb / (237.7 + drybulb*1)))) + 3.94; } document.calc_form.answer.value = answer; return false; } </script> Currently this is evaluated with entry from a simple html form, but I would like to have this performed "automatically". The "text file" that I would like to access is here, not on my server: http://www.bom.gov.au/fwo/IDV60901/IDV60901.94870.axf I would like to extract the "air_temp" and "rel_hum" values under the [data] section for use in my function. I just need the "most recent" values (i.e. first), not all those contained in the file. This is a single record from that section (sorry for the mess this no doubt makes): [data] sort_order,wmo,name[80],history_product[80],local_date_time[80],local_date_time_full[80],aifstime_utc[80],air_temp,apparent_t,cloud[80],cloud_base_m,cloud_oktas,cloud_type[80],cloud_type_id,delta_t,dewpt,gust_kmh,gust_kt,lat,lon,press,press_msl,press_qnh,press_tend[80],rain_trace[80],rel_hum,sea_state[80],swell_dir_worded[80],swell_height,swell_period,vis_km[80],weather[80],wind_dir[80],wind_spd_kmh,wind_spd_kt 0,94870,"Moorabbin Airport","IDV60901","27/10:00pm","20120227220000","20120227110000",18.8,19.3,"Partly cloudy",510,3,"-",-9999,0.8,17.5,13,7,-38.0,145.1,1013.5,-9999.0,1013.5,"-","11.4",92,"-","-",-9999.0,-9999,"10","-","S",11,6 Would it be possible to obtain these values using PHP?, and if so any advice on how this could be done (noting my minimal knowledge) would be greatly appreciated. Cheers. This topic has been moved to Microsoft SQL - MSSQL. http://www.phpfreaks.com/forums/index.php?topic=347695.0 SELECT * FROM `booking_tbl` WHERE booking_status = 'Check In' AND departure_date_time = NOW()"I use the datetime datatype for the departure_date_time so i can get data from that data because it checking the date and time but i want it to check on the date from the datetime datatype So how can i get the data only with that date without the time in the mysql datetime datatype Hello,
First of all I'd like to say thank you for all the great information on the forums, I've been reading a lot on here lately.
I've started to make a website where users can log in and submit items to a database, which is then displayed on another page.
If Tom and Bill both post 10 items, all 20 items will be displayed on the "listings" page, however on the main log in screen Tom will only see his own 10 items and Bill will see his own 10 items.
This is all working perfectly, however, I now need to add a delete button so that they can delete specific items.
I have loosely followed this tutorial here to get the table to display as I want it (amongst a few other things, such as the user logins) http://www.wickham43...mphptomysql.php
I've added the delete button in the PHP loop for each row, I just can't figure out how to delete the specific row when clicked.
Any help would be really appreciated
Edited by eklem, 22 October 2014 - 08:10 AM. Hello. I'm a newbie so sorry if this isn't the best forum to post my problem.
I am using a MySQL and PHP to create a web app. I have authentication, and I can register users. I also have a form that users provide information and it is successfully inserting data into a table in my database.
I will use fictional fields for my database table called meal_info:
username
dateStartedDiet
numberMealsPerDay
costPerMeal
Problem: Select user-specific data from the MySQL database, using Session username to select only the current user's data, then display it and do some calculations.
Here is thecode at the top, and I am fairly sure it's working:
session_start(); //execute commone code
require("common.php"); //includes code to connect to database, etc.
if(empty($_SESSION['user'])) I am not sure if the title is correct; I tried my best.
I'm a PHP/MySQL beginner and I really need some help.
I have a small script that I am using for sending SMS. I recently added a phonebook. The problem with the phonebook right now is that it's available to all users, i.e. they can all update and delete all rows. What I would like to do is make it so that each user can update and delete only their own contacts.
I have a table call contacts. Inside that table there is first name, last name, company and phonenumber.
How can I accomplish this with PHP & MySQL?
CREATE TABLE IF NOT EXISTS `contacts` ( `contact_id` int(10) NOT NULL AUTO_INCREMENT, `firstname` varchar(255) NOT NULL, `lastname` varchar(255) NOT NULL, `company` varchar(255) NOT NULL, `cell_no` text NOT NULL, PRIMARY KEY (`contact_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ; CREATE TABLE IF NOT EXISTS `users` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, `users_name` varchar(30) NOT NULL, `uname` varchar(30) NOT NULL, `u_pass` varchar(60) NOT NULL, `utype` varchar(30) NOT NULL, `timezone` varchar(30) NOT NULL, `uapi_user` varchar(30) NOT NULL, `uapi_pass` varchar(60) NOT NULL, PRIMARY KEY (`user_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=20 ; <?php if (isset($_POST['submit'])){ //form has been submitted1 $firstname = trim($_POST['firstname']); $lastname = trim($_POST['lastname']); $company = trim($_POST['company']); $cellno = trim($_POST['cell_no']); if($firstname == ''){ echo '<div class="alert alert-danger">First Name is not Valid!</div>'; exit; }elseif($lastname == ''){ echo '<div class="alert alert-danger">Last Name is not Valid!</div>'; exit; }elseif($company == ''){ echo '<div class="alert alert-danger">Company is not Valid!</div>'; exit; }elseif($cellno == ''){ echo '<div class="alert alert-danger">Cellphone Number is not Valid!</div>'; exit; }else{ $query = "Select cell_no from contacts where cell_no = '".$cellno."' "; $result = mysql_query($query); if (!mysql_num_rows($result)) { $sql = "INSERT INTO contacts(firstname, lastname, company, cell_no) values('{$firstname}','{$lastname}', '{$company}', '{$cellno}')"; $result = mysql_query($sql); confirm_query($result); //echo '<div class="alert alert-success">Successfully added.</div>'; //exit; ?> <script type="text/javascript"> window.location = "contact_list.php"; </script> <?php } else{ echo '<div class="alert alert-danger">Username. already exist!.</div>'; echo '<p><a href="new_contact.php" class="btn btn-success"> Back </a></p>'; exit; }} }else{ $firstname = ""; $lastname = ""; $company = ""; $cellno = ""; } ?> I would like to know how to display the user's name after they logged in. This is the form: Code: [Select] <form action="login" method="post" name="LoginForm"> <p> <input name="username" type="text" /></p> <p> <input name="password" type="text" /></p> <p> <input type="submit" value="Login" /></p> </form> This is the login.php Code: [Select] <?php $myusername=$_POST['username']; $mypassword=$_POST['password']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM members WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("username"); session_register("password"); header("location:success"); } else { echo "Wrong Username or Password"; } ?> This is the page that it goes to after login, success.php: Code: [Select] <?php foreach ($this->_params['list'] as $login ){ $login_name = $login['name']; echo "<table>"; echo "<tr>"; echo "<td>"; echo "<a href=/logins/view/".$login['id'].">$login_name</a>"; echo "</td>"; echo "</tr>"; echo "</table>"; } ?> <?php session_destroy(); ?> <a href="/partner_portals/view">Log out</a> Could somebody help to pint me in the right direction where to look for the correct syntax for my problem. The user logs in and is sent to the members area, their username is echoed out to display that they are logged in, my problem is that it is displaying all the users in my database (currently 2 usernames). I would just like to have the current users username displayed. Code: [Select] <?php $con = mysql_connect("server","username", "password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); $result = mysql_query("SELECT username FROM users" ); while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['username'] . "</td>";; echo "</tr>";} echo "</table>"; ?> What sholud i research to perform this task properly? thank you. |