PHP - Php/sql Removing Certain Names From A List
Say i wanted to make a list with only female names and i wrote the whole file for it but it kept showing both Male and Female names how would i remove the male names from the list without deleting them out of the SQL?
I wish i knew how to word this better for what I'm looking for.... ----------------------------------------------Don't know if you need this---------------------------------------------- MySQL Server: Localhost via UNIX socket Server version: 5.0.91 Protocol version: 10 User: tpkrpgn1@localhost MySQL charset: UTF-8 Unicode (utf8) Web server cpsrvd 11.28.64 MySQL client version: 5.0.91 PHP extension: mysql phpMyAdmin Version information: 3.3.8.1 ----------------------------------------------Don't know if you need this---------------------------------------------- Also is there a way to delete previous posts? Similar TutorialsMy Php Buddies, I have mysql tbl columns these:
id: Now, I want to display their row data by excluded a few columns. Want to exclude these columns: date_&_time account_activation_code account_activation_status id_verification_video_file_url password
So, the User's (eg. your's) homepage inside his account should display labels like these where labels match the column names but the underscores are removed and each words' first chars CAPITALISED:
Id: 1
For your convenience only PART 1 works. Need help on Part 2 My attempted code:
PART 1 <?php // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Query to get columns from table $query = $conn->query("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'members' AND TABLE_NAME = 'users'"); while($row = $query->fetch_assoc()){ $result[] = $row; } // Array of all column names $columnArr = array_column($result, 'COLUMN_NAME'); foreach ($columnArr as $value) { echo "<b>$value</b>: ";?><br><?php } ?> PART 2 <?php //Display User Account Details echo "<h3>User: <a href=\"user.php?user=$user\">$user</a> Details</h3>";?><br> <?php $excluded_columns = array("date_&_time","account_activation_code","account_activation_status","id_verification_video_file_url","password"); foreach ($excluded_columns as $value2) { echo "Excluded Column: <b>$value2</b><br>"; } foreach ($columnArr as $value) { if($value != "$value2") { $label = str_replace("_"," ","$value"); $label = ucwords("$label"); //echo "<b>$label</b>: "; echo "$_SESSION[$value]";?><br><?php echo "<b>$label</b>: "; echo "${$value}";?><br><?php } } ?> PROBLEM: Columns from the excluded list still get displayed. Edited November 19, 2018 by phpsaneThe following code is what I have already done, but I have just realised that the way I have done this will not enable me to display the online users in alphabetical order, I do not know a way how to do this. Any help or suggestions? Thanks $friend_query = mysql_query("SELECT * FROM friend_request WHERE user='{$user_id}'"); $friend_id_array = ""; while($row = mysql_fetch_assoc($friend_query)) { $friend_id = $row['friend_id']; $more_query = mysql_query("SELECT * FROM friend_request WHERE friend_id='{$user_id}'"); while($row_more = mysql_fetch_assoc($more_query)) { $more_friend_id = $row_more['user']; //all friends in an array $friend_id_array = $friend_id_array.$friend_id."/".$more_friend_id; $friend_id_array = explode('/', $friend_id_array); $friend_count = count($friend_id_array); //how many of the friends are online $online_count = 0; for($i=0;$i<$friend_count;$i++) { $query_online = mysql_query("SELECT loggedin, fname, mname, lname FROM users WHERE id='{$friend_id_array[$i]}'"); //get loggedin and names $row = mysql_fetch_assoc($query_online); $loggedin = $row['loggedin']; if($loggedin == "1") //if logged in { $online_count++; // final number off people online } } } } Hi guys, I am currently building a customer appointment booking system with PHP. Customers who are added are store on a customer database and displayed or listed as links dynamically in a 'customer.php' page. So you can click on a customer to view their profile i.e. name, address, time added, an so on. Also there is a button to 'create appointment' for the customer. Click the button, a form appear, select a day and time the click submit. It all works fine. The problem is once the appointment is booked I dont how to remove the customer from the list on the customer.php page. So am looking for something like what they have on e-commerce sites e.g a customer buys an item and that item is no longer available for another customer. Please guys am calling for your expertise, any ideas, inputs or suggestions you may have are more than welcome. Thanks Hi, I have db table that records the days (Sunday, Monday...) when the employee login to the system. Say that the employee logged in on Monday then Logged in on Wednesday so this means he was absent on Tuesday. I calculated the number of days to get the answer 2 (between Wednesday and Monday before logging in on Wednesday) how to get the name of the missing day "Tuesday"? code: $curdate = date("Y-m-d"); $currday = date('l'); $lastdate = $row['indate']; $lastdayin = $row['lastdayin']; if ($lastdate !=Null) { $misseddates = strtotime($curdate) - strtotime($lastdate); $misseddates = $misseddates / 86400; echo $misseddates; $misseddays = strtotime($lastdayin) - strtotime($currday); $misseddays = $misseddays / 86400; echo $misseddays; } I tried to get the name of day in the last step but it only calculates 5 in numbers how to get the name. I want the answer to be "Tuesday" as of the example. Thanks. Hi guys, I am currently stuck in a situation. I have duplicated names in my form. View duplicated.jpg for a reference. What exactly went wrong? Any help will be greatly appreciate! How do I eliminate the duplicated names. Thanks!! And my $count is currently not working as well, it is supposed to be 5 columns per row. Code: [Select] <?php /***Pre-School Level***/ echo '<input name="level[]" type="checkbox" id="level_1" value="1">'; echo '<span class="zone_text_enlarge"><label for="level_1">Pre-School</label></span><br/>'; $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die(mysqli_error($dbc)); $query = "SELECT sl.subject_level_id, sl.level_id, sl.subject_id, tl.level_name AS level_name, ts.subject_name AS subject_name " . "FROM tutor_subject_level AS sl " . "INNER JOIN tutor_level AS tl USING (level_id) " . "INNER JOIN tutor_subject AS ts USING (subject_id) " . "ORDER BY subject_level_id ASC LIMIT 7"; $sql = mysqli_query($dbc, $query) or die(mysqli_error($dbc)); $query1 = "SELECT subject_level_id FROM tutor_overall_level_subject WHERE tutor_id = '" . $_GET['tutor_id'] . "'"; $sql1 = mysqli_query($dbc, $query1) or die(mysqli_error($dbc)); $selected_subjects = array(); while ($row = mysqli_fetch_array($sql1)) { array_push($selected_subjects, $row['subject_level_id']); } echo'<table><tr>'; // Start your table outside the loop... and your first row $count = 0; // Start your counter while($data = mysqli_fetch_array($sql)) { /* Check to see whether or not this is a *new* row If it is, then end the previous and start the next and restart the counter. */ if ($count % 5 == 0) { echo "</tr><tr>"; $count = 0; } foreach($selected_subjects as $selected_subject) { if ($data['subject_level_id'] == $selected_subject) { echo '<td><input name="subject_level[]" class="subject_a" type="checkbox" checked="checked" id="subject_level_'.$data['subject_level_id'].'" value="'.$data['subject_level_id'].'"/>'; echo '<label for="subject_level_'.$data['subject_level_id'].'" class="subject_1">'.$data['subject_name'].'</label></td>'; $count++; //Increment the count } else { echo '<td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_'.$data['subject_level_id'].'" value="'.$data['subject_level_id'].'"/>'; echo '<label for="subject_level_'.$data['subject_level_id'].'" class="subject_1">'.$data['subject_name'].'</label></td>'; $count++; //Increment the count } } } echo '</tr></table><br/>'; //Close your last row and your table, outside the loop ?> This is the end result of the HTML code, through 'view page source' in web browser Code: [Select] <input name="level[]" type="checkbox" id="level_1" value="1"> <span class="zone_text_enlarge"><label for="level_1">Pre-School</label></span><br/> <table><tr></tr> <tr> <td><input name="subject_level[]" class="subject_a" type="checkbox" checked="checked" id="subject_level_1" value="1"/> <label for="subject_level_1" class="subject_1">Mathematics</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_1" value="1"/> <label for="subject_level_1" class="subject_1">Mathematics</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_2" value="2"/> <label for="subject_level_2" class="subject_1">English</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_2" value="2"/> <label for="subject_level_2" class="subject_1">English</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_3" value="3"/> <label for="subject_level_3" class="subject_1">Chinese</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_3" value="3"/> <label for="subject_level_3" class="subject_1">Chinese</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_4" value="4"/> <label for="subject_level_4" class="subject_1">Tamil</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_4" value="4"/> <label for="subject_level_4" class="subject_1">Tamil</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_5" value="5"/> <label for="subject_level_5" class="subject_1">Malay</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_5" value="5"/> <label for="subject_level_5" class="subject_1">Malay</label></td> </tr> <tr> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_6" value="6"/> <label for="subject_level_6" class="subject_1">Phonics</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" checked="checked" id="subject_level_6" value="6"/> <label for="subject_level_6" class="subject_1">Phonics</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_7" value="7"/> <label for="subject_level_7" class="subject_1">Creative Writing</label></td> <td><input name="subject_level[]" class="subject_a" type="checkbox" id="subject_level_7" value="7"/> <label for="subject_level_7" class="subject_1">Creative Writing</label></td></tr> </table><br/> Hey , I'm looking for functions names from the GD directory. 1.function that open image. 2.function that getting pixel color. 3.function that changing pixel color. thanks. Hi php freaks I've been learning php, but what confuses me are the arrays. I have ini file, i want to get the data from file and add it to the database. Every section makes a new table and all they keys are added with their values. I figured out how to get the keys and how to see the values, but how can i get the name of the sections. Furthermore, how do i know what keys belong to what section. I am really grateful for person who helps me to realize how to be a good friend with those complicated arrays. Hi, In my mysql database i have a text input option, in the registration form and edit my details form i have a multiple select dropdown list, which user selects options to populate the text input box, which ultimately populates the text field in the mysql database. All works perfectly. The dropdownlist consists of 3 parts <optgroups> first is current selection (what is the usesr current selection)works fine, The second <optgroup> is existing words, what words we(the site) have given as options, and the third <optgroup> is the words that others have used. This is where im having a small problem. Because its a text field when i call the data from the database, it calls the entire text box as a single option in my select list.. I want to break the words in the text field (at the comma) and have them listed each one as an option in the select list. Example what i need: Words in text box:(my input allows the "comma") word1, word2, word3, word4, word5, word6, How i want them called/displayed: <option value=\"word1\">word1</option> <option value=\"word2\">word2</option> <option value=\"word3\">word3</option> <option value=\"word4\">word4</option> <option value=\"word5\">word5</option> <option value=\"word6\">word6</option> here's my code: $query = "SELECT allwords FROM #__functions_experience WHERE profile_id = '".(int)$profileId."' LIMIT 1"; $original_functionsexperience =doSelectSql($query,1); $query = "SELECT allwords FROM #__functions_experience WHERE profile_id = '".(int)$profileId."' LIMIT 1"; $functionsexperiencelist=doSelectSql($query); $funcexpList ="<select multiple=\"multiple\" onchange=\"setFunctionsexperience(this.options)\">"; foreach ($functionsexperiencelist as $functionsexperienceal) { $selected=""; if ($functionsexperienceals->allwords == $original_functionsexperience) $selected=' selected="selected"'; $allwords=$functionsexperienceal->allwords; $funcexpList .= "<optgroup label=\"Current selection\"> <option value=\"".$allwords."\" ".$selected." >".$allwords."</option> </optgroup> <optgroup label=\"Existing Words\"> <option value=\"existing1,\">existing1</option> <option value=\"existing2,\">existing2</option> <option value=\"existing3,\">existing3</option> <option value=\"existing4,\">existing4</option> <option value=\"existing5,\">existing5</option> <option value=\"existing6,\">existing6</option> </optgroup> <optgroup label=\"Others added\"> //heres problem <option value=\"".$allwordsgeneral."\">".$allwordsgeneral."</option> </optgroup>"; } $funcexpList.="</select>"; $output['FUNCEXPLIST']=$funcexpList; The result im getting for optgroup others added: word1, word2, word3, word4, word5, how can i get it like this: <option value=\"word1\">word1</option> <option value=\"word2\">word2</option> <option value=\"word3\">word3</option> <option value=\"word4\">word4</option> <option value=\"word5\">word5</option> <option value=\"word6\">word6</option> Hi , I have one question .. Can I split showing of content of dynamic list in 2 parts , when I echo list in code .. Code: [Select] <?php // Run a select query to get my letest 8 items // Connect to the MySQL database include "../connect_to_mysql.php"; $dynamicList = ""; $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 8"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $product_name = $row["product_name"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $dynamicList .= '<table width="100%" border="2" cellspacing="2" cellpadding="2"> <tr> <td width="17%" valign="top"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="2" /></a></td> <td width="83%" valign="top">' . $product_name . '<br /> $' . $price . '<br /> <a href="product.php?id=' . $id . '">View Product Details</a></td> </tr> </table>'; } } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> Code: [Select] <p><?php echo $dynamicList; ?><br /> </p> It works ok, and putting my files, everything works, but when I put 8 pictures with price and other details, it just show one image with details and another image below with details, and the third image below and so on .. Can I split dynamic list to show 4 images with details on the left side and 4 on the right side? Thank you in advance for help , if is possible In my forms, at the top, I have PHP that fires if the Form was submitted like this... // ************************************************************* // HANDLE FORM. * // ************************************************************* if ($_SERVER['REQUEST_METHOD']=='POST'){ // Form was Submitted (Post). // Initialize Errors Array. $errors = array(); // Trim all form data. $trimmed = array_map('trim', $_POST); And then at the bottom of the file I have my HTML Form with controls like this... <!-- First Name --> <label for="firstName"><b>*</b>First Name:</label> <input id="firstName" name="firstName" type="text" maxlength="30" value="<?php if(isset($firstName)){echo htmlentities($firstName, ENT_QUOTES);} ?>" /><!-- Sticky Field --> <?php if (!empty($errors['firstName'])){ echo '<span class="error">' . $errors['firstName'] . '</span>'; } ?> Where is this code getting the name "$firstName"... <?php if(isset($firstName)) I guess I am asking what in my Form determines the name of things in the $_POST array?? Hope that makes sense?! Debbie IronMineList.php: Code: [Select] <?php include('buildingfile.php'); ?> <?php $dbhost = 'localhost:3306'; $dbuser = 'root'; $dbpass = 'root'; $dbname = 'aosdb'; $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); $query="SELECT * FROM IMPrints"; $result=mysql_query($query); $num=mysql_num_rows($result); $i=0; $n=1; $j=0; $b=1; while($i<$num) { $name = mysql_result($result, $i, 'name'); $work = mysql_result($result, $i, 'workers'); $effi = mysql_result($result, $i, 'efficiency'); $cost = mysql_result($result, $i, 'cost'); $iron = mysql_result($result, $i, 'iron'); $copp = mysql_result($result, $i, 'copper'); $silv = mysql_result($result, $i, 'silver'); $titan = mysql_result($result, $i, 'titanium'); $gold = mysql_result($result, $i, 'gold'); $uran = mysql_result($result, $i, 'uranium'); $plat = mysql_result($result, $i, 'platinum'); $diam = mysql_result($result, $i, 'diamonds'); $oil = mysql_result($result, $i, 'oil'); $water = mysql_result($result, $i, 'water'); include('Iron.php'); $i++; $b++; $j++; $n++; } ?> Iron.php: Code: [Select] <?php $dbhost = 'localhost:3306'; $dbuser = 'root'; $dbpass = 'root'; $dbname = 'aosdb'; $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); $queryj = "SELECT name FROM IMPrints"; $resultj = mysql_query($queryj); $Column = mysql_result($resultj, $j); $queryp = "SELECT * FROM IMBuilt WHERE idcol = $idcol"; $resultp = mysql_query($queryp); $Base = mysql_fetch_row($resultp); if(isset($_POST[""])) { if($_POST[""]) { $Badd = $Base[$b]+$_POST[""]; $queryi="UPDATE IMBuilt SET $Column=$Badd WHERE idcol = $idcol"; mysql_query($queryi); } } $queryf = "SELECT * FROM IMBuilt WHERE idcol = $idcol"; $resultf = mysql_query($queryf); $Basic = mysql_fetch_row($resultf); echo $i; ?> <p class="bd" id="built">| Built: <?php echo $Basic[$n]; ?> |</p> <form class="bd" method="post" action="IronMineList.php"><input type="text" name='[]'><input type="submit" value="Build"></form> What those 2 php documents do is display a list of iron mines a player in my game can build. It is supposed to create 1 form for each blueprint so that a player can add only to the number of that blueprint on their colony. The displays work perfectly. It creates 1 div that properly displays the stats of each mine in the database table. It also creates one form for each div. The problem I have is, I can only make the forms add 1 to all the buildings on a colony. The name='' value of the form and the $_POST[''] values do not increment with the rest of the code. I need a way to make each form apply only to the div which displays a specific mine. So where $i=0 the first form should only alter the value in imbuilt for the stats that are displayed by the rest of the div created for $i=0. hey guys im getting my column names with this query: $query = mysql_query("SELECT column_name FROM information_schema.columns WHERE table_name = 'cam_systems'"); I then have an array: $fields = array( "cfg_change_date" => "Configuration Change Date", "system_name" => "System Name", "system_manf" => "System Manufacturer", "system_model_no" => "System Model Number", "system_serial_no" => "System Serial Number", "system_board_part_no" => "System Board Part Number", "system_board_serial_no" => "System Board Serial Number", "asset_tag" => "Asset Tag", "sla_code" => "SLA Code", "category" => "Category", "os_version" => "OS Version", "os_upgraded" => "OS Upgraded", "bios_version" => "BIOS Version", "bios_upgraded" => "BIOS Upgraded", "ilom_version" => "ILOM Version", "ilom_ip" => "ILOM IP Address", "ilom_updated" => "ILOM Updated", "rack_id" => "Rack ID", "rack_location_id" => "Rack Location ID", "tech_id" => "Tech ID", "warranty" => "Warranty" ); I need to display these field names now, but rather than the actual column name, I've created an array with column name and then the name I want to actual display. How can I do that? Is their a better way I should be doing this? The default PHP Session name on my webspace server is PHPSESSID. Does that mean that the session cookie will be called PHPSESSID? The reason i ask is that in a couple of places i can't use PHP to update the information in the session cookie (because PHP is parsed before the webpage loads) and so i need to use Javascript to update a cookie which i would prefer to be the session cookie used by PHP. I guess i'm asking what the name of the cookie is, how i would refer to it in Javascript (if that is even possible) so that i can update it and whether this would cause any issues with the info already stored in the session cookie by PHP. Cheers NM Hi Guys, I'm new to PHP. I've gone through a few tutorials and I'm not sure how to go about the following: For work, every week 1 of 3 people is responsible for checking some bug report. This week I have to do this. Next week it's Tom the week after that is Brenda. Then it's back to me again and it cycles. We currently have a white board calendar at the back of the office that gets updated with the name of the person responsible for doing the checks that week. What I'm trying to do is write a small PHP snippet that will show on our internal site something like: Bug Checker this week is: TARA Then the next week it'll show Tom, then Brenda. And cycle back. That way we don't have to keep updating that board. Does anybody know the best way to go about this. I keep thinking of different ideas but they all seem pretty convoluted and I'm fairly certain there's got to be a very easy way to do it; it's just not coming to me. Any help would be appreciated Thanks so much! XXX Tara EDIT: We cycle through every Monday. If that helps. I considered creating a database file with the date and the person and just read that in but that is so embarassingly inefficient that I didn't even want to mention this in the post. Hi Guys, I use this function to generate seo friendly names for my products once pulled from the database: function generate_seo_friendly_links($pNM, $pID) { $replacedNM = str_replace(" ", "-", $pNM); $replacedNM = rtrim($replacedNM); $brandNewSEOFriendlyURL = "<a href='$replacedNM-$pID.html'>$pNM</a>"; return $brandNewSEOFriendlyURL; } This works great, the only thing is say a product is stored in the database like: product name it would then be converted to: product-name.html if for example theres 2 spaces: product name it would then be converted to: product--name.html with the 2 "--" so for every space it finds we replace with a "-" etc is there a way i could ignore more than 1 space and always have it like product-name-here.html so the names are more uniformed, i can't think of a way to do it. any help would be appreciated thanks guys Graham How do I get directory names to display with spaces. My script sticks them into arrays just fine, but when trying to echo from a checkbox selection, it only displays the first word. How would I fix this? Hi all. I've got a little function to generate a simple form depending on the input. What I'd like to do is alias the field names that get output to make them a little more human readable. However, I'm not entirely sure how to do that with the output that I get. The function.... function build_form($table_name){ $result=mysql_query("SELECT * FROM $table_name"); $num=mysql_num_rows($result); $i=1; echo "<table>"; while ($i < mysql_num_fields($result)) { $fields=mysql_fetch_field($result,$i); echo "<tr><td>" . $fields->name . "</td><td><input type=\"text\" size=\"30\" name=\"" . $fields->name . "\" /></td></tr>"; $i++; }; echo "</table>"; }; Q: Where would I have to modify the output from mysql_fetch_field? My modified function... function build_form($table_name){ $result=mysql_query("SELECT * FROM $table_name"); $num=mysql_num_rows($result); $i=1; echo "<table>"; while ($i < mysql_num_fields($result)) { $fields=mysql_fetch_field($result,$i); $field_name=str_replace("_"," ",$fields->name); echo "<tr><td>" . $field_name . "</td><td><input type=\"text\" size=\"30\" name=\"" . $field_name . "\" /></td></tr>"; $i++; }; echo "</table>"; }; Not sure if that will work, but am I heading in the right direction? Any help is much appreciated! Lets say that I have a table (participant_registrations) with following columns amongst others: first_name, middle_name, last_name, full_name. full_name consists of first_name last_name and middle_name in the midddle is it is available.
Let's Say that I have Michael John Smith registerd. How would I set up the query so when someone searches for "Michael John Smith" or "Michael Smith" they would get the record in the results. Right no I have it set up in manner of "... WHERE full_name LIKE '%$term%' ... " which will show the record in results if you search for "Michael John Smith" but not when you search for "Michael Smith".
Thanks
I have been developing applications for over 2 years now. In one of my domains I see some strange php files all created on 20th of April 2011 and named like this : IwA8ZSIhJ.php,QvDBnXYevm.php,LXgU1kf16y.php etc etc Any idea what could be the potential reason of creating such files in my hosting ? Thanks Sadan Masroor. This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=334315.0 |