PHP - Display Text Based On The Value From The Db
Hello, I have started a DB for simple web based inventory system, I have only dabbled in PHP before 6 weeks ago, within the last 6 weeks with some help and going through countless tutorials and asking questions when I need. At this time setup an insert, delete and update function for this db and are working perfectly, now what I need to know is there a way to display something like 'in stock' and 'out of stock' using php, based on the value of the quantity in my db next to the item in a table?
Example : when the table is generated it will display:
| Part number | Description | Stock | (normally Stock would show the quantity of each part, I just wish to
|10-1111 | Some info | In Stock | display In or out os stock)
|10-1112 | Some Info | Out of Stock |
I the only code I have is the tables and just not sure what to do next to get the results I have described above. So I will include the table code I have and see where we can go from there. Or if you have some webs site that I can read through that will be great as well as long as it can give me basic instruction on how to do this.
Reminder, I am self taught and still learning.
<?php $con = mysqli_connect("localhost","user","pass","part_inventory"); // Check connection if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { $result = mysqli_query($con, "SELECT * FROM amp20"); echo "<table border='1'> <tr> <th>ID</th> <th>Part number</th> <th>description</th> <th>location</th> <th>Quantity</th> </tr>"; while ($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['amp20ptid'] . "</td>"; echo "<td>" . $row['partnum'] . "</td>"; echo "<td>" . $row['description'] . "</td>"; echo "<td>" . $row['location'] . "</td>"; echo "<td>" . $row['quantity'] . "</td>"; echo "</tr>"; } echo "</table>"; mysqli_close($con); } ?> Edited by Thunder_Wolf, 22 October 2014 - 11:16 AM. Similar TutorialsI'm trying to display an html <div> based on the state of a variable set during php execution . The variable is $chk and is set to either 0 or 1 with 0 meaning failed and 1 meaning pass. Here's the code: if <?php echo "{$chk}";?> == 0 <div class="container"> <div class="row" style="color:red"> <br><br><br><br><br><br> <center>Database Update Failed</center> </div> </div> else <div class="container"> <div class="row"> <br><br><br><br><br><br> <center>Database Updated</center> </div> </div>
Thanks in advance, Larry Edited June 19, 2020 by larry29936additioal info Good day and Merry Christmas to all, I just spent a good time of my christmas eve trying to figure out this problem. I hope one of you santas would be so kind as to help me with it. First off I have two tables; employee and employee_works both connected via employee_id key. Basically I have a parent window we'll call parent.php. inside the parent page is a search button that once clicked will open a child window we'll call child.php inside the child page is a list, lets say employees with name, employee_id, etc. My main concern is this: How do I populate parent.php based off the employee selection I made in the child window. Example: -Access parent.php -Click on search -Click on [ID: 004] [NAME: JOHN SMITH] [PHONE: 1233456] [DATE HIRED: JULY 16, 1992] <---format of a row in child.php -child.php automatically closes and parent.php now shows all data from employee_works with the employee_id = 004 Is this even possible? I know this is vary vague and would be willing to explain more if needed. My website is built mostly on javascript and php. Hello my problem here is to have a drop down menu which gathers usernames from the database. Then with a click of a button the information for that specific user selected is shown. I'm close code wise but right now it's just showing me all users. I'm displaying the info in text box's to allow an admin to change the info.
<form action="edit.php" method="post"> <select name="username" id="username"> <?php // Connects to your Database $con=mysqli_connect('localhost', 'root', ''); /* check connection */ if (mysqli_connect_errno($con)) { trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR); } $query = "SELECT `username` FROM `bencobricks` . `users`"; $result = mysqli_query($con, $query) or trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($con), E_USER_ERROR); if($result) { while($row = mysqli_fetch_assoc($result)) { //printf ("%s\n %s\n ", echo "<label for='username'>Username: </label> <option value='$row[username]'>$row[username] </option><br/>"; echo "<br/><br/> "; } } mysqli_close($con); ?> </select> <br /> <input name="send" id="send" type="submit" value="Edit User" /> </form>Then in the edit.php file i have this code: <?php // Connects to your Database $con=mysqli_connect('localhost', 'root', ''); /* check connection */ if (mysqli_connect_errno($con)) { trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR); } if (isset($_POST['send'])) { $username = $_POST['username']; $query = "SELECT * FROM `bencobricks` . `users` "; $result = mysqli_query($con, $query) or trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($con), E_USER_ERROR); // Print the result if($result) { while ($row = mysqli_fetch_assoc($result)) { // $query = "SELECT * FROM `bencobricks` . `users` WHERE `username` = username = $row[username]"; printf ("%s\n %s\n %s\n %s\n %s\n %s\n %s\n %s\n %s\n %s\n %s\n", "<label for='username'>Username: </label> <input type='text' name='username' value='$row[username]'>" . "</input><br/>", "<label for='email'>Email: </label> <input type='text' name='email' value='$row[email]'>" . "</input><br/>", "<label for='membership'>Membership: </label> <input type='text' name='membership' value='$row[membership]'>" . "</input><br/>", "<label for='firstName'>First name: </label> <input type='text' name='firstName' value='$row[firstName]'>" . "</input><br/>", "<label for='lastName'>Last name: </label> <input type='text' name='lastName' value='$row[lastName]'>" . "</input><br/>", "<label for='gender'>Gender: </label> <input type='text' name='gender' value='$row[gender]'>" . "</input><br/>", "<label for='dateOfBirth'>Birthdate: </label> <input type='text' name='dateOfBirth' value='$row[dateOfBirth]'>" . "</input><br/>", "<label for='date'>Date: </label> <input type='text' name='date' value='$row[date]'>" . "</input><br/>", "<label for='sets'>Sets: </label> <input type='text' name='sets' value='$row[sets]'>" . "</input><br/>", "<label for='checkbox'>Checkbox: </label> <input type='text' name='checkbox' value='$row[checkbox]'>" . "</input><br/>", "<label for='admin'>Admin? </label> <input type='text' name='admin' value='$row[adminFlag]'>" . "</input><BR>", "<br/><br/> "); } } } mysqli_close($con); ?>Any help is greatly appreciated. I would like to know the best practice to achieve the following: I have a list of dates related to live events for performing artists. When someone views the web page that contains a section to display the dates, I would only want to show the dates from today into the future and not show any dates from the past. What is the best way to accomplish this? Thanks in advance... This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=359077.0 I am attempting to us glob to display contents of a users folder using a session variable. Example: I have a session variable called department Code: [Select] $row_fullname['department']; In department I have the name of the department the user belongs to such as: office, plant, maintenance, and groundskeeping I created a folder called docs inside of docs there are 4 subfolders called office, plant, maintenance, and groundskeeping I found this code which will display the contents of the folder: Code: [Select] <?php $files = glob( './docs/office/*.*' ); foreach ( $files as $file ) { echo '<a href="./docs/office/' . basename( $file ) . '"target="_blank">' . basename( $file ) . '</a><br />'; } ?> The above code works fine, but I would like it to only display the contents of a departments folder only if the user is part on that department. Here is an example that I know is completely wrong but it may help explain what I am trying to do. Code: [Select] <?php ]<?php $files = glob( './docs/echo $row_fullname['department'];/*.*' ); foreach ( $files as $file ) { echo '<a href="./docs/echo $row_fullname['department'];/' . basename( $file ) . '"target="_blank">' . basename( $file ) . '</a><br />'; } ?>Thanks for your time I have a little experience in coding php and am wanting to code a browser-based RPG. (One of the click the link games). I know how to code the login, registration, player list, lost password, etc., but I have no idea where to start with coding the attack, throwing in random chance, strength, agility and so forth; stores, items, money, and so on and so on. Can someone help me? Hi, I am trying to limit an user's input based on a text area size which is 180px. Is this even possible? There are ways to read how many linebreak's (\n) there are in a text area, but a long sentence will read as one linebreak. Any Ideaas? the idea on what im doing is like a converter, like showing what your name would look like with certain images per letter, when you input text (your name for example) and when you press the submit button you would get a series of images in a row that represent each character that you typed.
here is the example that i did...
<html> <?php Hi all, I'm currently rewriting our contact us form using the php Pear Mail package. It allows both html based emails and text based emails, and displays the relevant version based on the end recipients broswer capabilities. I have the html version working perfect, however the text based version spits out the whole message without line breaks. Since some of the computers in our building only except text emails (due to security) it needs to be laid out so that it is legible. I've searched around and tried various options but the emails are still arriving without breaks. So as an example: A User Inputs the following message using a textarea on the php form: Hi there, Great website, need help with such and such though. Regards Bob The email message gets collected and included in a html message. Then a duplicate text based message is made like so (Code so far): Code: [Select] $plaintxt = '-----------------------------------------' . "\n"; $plaintxt .= Website Enquiry' . "\n"; $plaintxt .= '-----------------------------------------' . "\n"; $plaintxt .= 'A visitor to our website has submitted the following enquiry:' . "\n\n"; $plaintxt .= 'Name: ' . $visitor_name . "\n"; $plaintxt .= 'Company Name: ' . $visitor_companyname . "\n"; $plaintxt .= 'Email Address: ' . $visitor_email . "\n"; $plaintxt .= 'Telephone Number: ' . $message_telephone . "\n\n"; $plaintxt .= 'Subject of Enquiry: ' . $msg_subject . "\n"; $plaintxt .= 'Enquiry: ' . "\n\n"; $plaintxt .= $message_body . "\n\n"; $plaintxt .= '-----------------------------------------' . "\n\n"; $plaintxt .= 'User IP Address:' . $ip . "\n"; $plaintxt .= 'User Browser Info:' . $httpagent . "\n"; $plaintxt .= 'Date/Time Submitted:' . $time . "\n"; $crlf = "\n"; $headers = array('From' => $contact_from_email, 'Return-Path' => $contact_from, 'Subject' => $subject, 'To' => $contact_to); // Creating the Mime message $mime = new Mail_mime($crlf); // Setting the body of the email $mime->setTXTBody($htmlmessage); //Text version of the email $mime->setHTMLBody($plaintxt); // HTML version of the email "\n"; - These were suggested by users on the pear mail manual. Then once sent and opened you'd expect to see: Quote ----------------------------------------- Website Enquiry ----------------------------------------- A visitor to our website has submitted the following enquiry: Name: Bob Company Name: Someplace Ltd Email Address: bob@someplace.com Telephone Number: 01234 567890 Subject of Enquiry: help Enquiry: Hi there, Great website, need help with such and such though. Regards Bob ----------------------------------------- User IP Address: 123.456.789.012 User Browser Info: Mozilla Date/Time Submitted: 29th September 2011 09:56 However when opened in all the email applications I have (Outlook, Gmail, Live Mail, Hotmail, Yahoo) it looks like this: Quote -----------------------------------------Website Enquiry-----------------------------------------A visitor to our website has submitted the following enquiry:Name: BobCompany Name: Someplace LtdEmail Address: bob@someplace.comTelephone Number: 01234 567890Subject of Enquiry: helpEnquiry: Hi there,Great website, need help with such and such though.RegardsBob-----------------------------------------User IP Address: 123.456.789.012User Browser Info: MozillaDate/Time Submitted: 29th September 2011 09:56 Yet if you look at the source of the email. The line breaks are there. Am I missing something?
Auto Save Plugin for the CKEditor which automatically saves the content (via HTML5 LocalStorage) temporarly (for example when a login session times out). And after the content is saved it can be restored when the editor is reloaded.
The auto save plugin for CKEditor does its job the way its described in the quote above.
I was wondering if there is a way to have the web based text editor for my blog, the way the Wordpress text editor is, with an auto save (draft) function?
Is there a web based text editor with such function, which would enable me this?
Edited by glassfish, 01 December 2014 - 07:43 AM. I don't have a lot of money and I'm launching a high traffic website, I intend to have a payment system linked to hosting service I am using so that in the event that my website is actually successful, it can expand accordingly.
I want to know ahead of time about bandwith usage, I have a 3TB limit per month which may seem like a lot but what if thousands of users are accessing/using files that are between 2 to 10 MB each? Uploading, viewing, scrolling, text...
This calculation also applies to storage
I haven't really given this much thought, I'm just curious, I have a lot to do and I would like to start amassing information ahead of time
Thank you for any help
I have a field in my database called description. How can I echo out only 500 out of the 2000 max characters? Like for example: Code: [Select] $query = mysql_query("SELECT description FROM `servers` ORDER BY votes DESC LIMIT 5"); If I were to echo out the value of description for the database, how can I only echo out the first 500 characters? Sorry if this is too obvious or hard to understand. I'm echoing a database value onto a webpage, the value in question is a large paragraph of text. I need it to only display the first 40 characters or so of that text, then trail off with a "..." So the users will be able to click a 'More Info' button which will take them to a page containing the full paragraph of text. I'm just not sure how to cut off the text after 40 characters. Any help HUGELY appreciated Hi there, I am trying to write a simple piece of code that will display a little text phrase on every Friday 13th in any year. How would I best go about doing this? Thank you. Hi, I have the following code in a WordPress theme which displays a companies website, Twitter and Facebook links. What I am trying to do is display the text "Useful Links:" if one of the links exists, and hide the text if all are not present. <p>Useful Links:</p> <?php if ( $website = get_the_company_website() ) : ?> <a class="company-website" href="<?php echo esc_url( $website ); ?>" itemprop="url" target="_blank" rel="nofollow"><?php _e('Website', 'jobseek'); ?></a> <?php endif; ?> <?php if ( get_the_company_twitter() ) : ?> <a class="company-twitter" href="http://twitter.com/<?php echo get_the_company_twitter(); ?>" target="_blank"><?php _e('Twitter', 'jobseek'); ?></a> <?php endif; ?> <?php $facebook_link = get_post_meta( get_the_ID(), '_facebook_link', true ); if ( ! empty($facebook_link) ) : ?> <a class="company-facebook" href="<?php echo $facebook_link; ?>" target="_blank">Facebook</a> <?php endif; ?> What would be the best way to show/hide the text depending on if the items are present or not? Thanks Hi, Wonder if someone could help with the problem below. Got a main page that includes a header, footer and a link to a database. I can get the two Includes to work but can't seem to display the database fields in the body of the page. What has me baffled is that it appears to be connecting to the database, (Opening the connection to the database server The connection worked. The link is: Resource id #3) but no text (see below for database text) is appearing on the screen. Yet I'm not getting a "page_not_found" message. I can go to the database in MYSQL console and query it successfully. Read and (hopefully) applied the section Debugging: A Beginner's Guide, but still can't see the problem. Any help greatly appreciated. Bren --------------------CODE FOR MAIN PAGE START------------------- <?php $page_name = $_REQUEST['name']; /*http://localhost/exemples/page.php?name=about_us*/ // Get the body of the page mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); $sql = "SELECT * from pages WHERE name='$page_name'"; print "Opening the connection to the database server<br>"; $link = mysql_connect("localhost","root", ""); print "The connection worked. The link is: $link <br>"; /* --------------What is being selected from the database-------------- +----------+------------------------------------------------------------------------+ | name | body | +----------+------------------------------------------------------------------------+ | about_us | <h1>About Us</h1> ACME Toys has been established in 1850 to provide toys | to children all over the world +----------+------------------------------------------------------------------------+ 1 row in set (0.00 sec) ---------------------------------------------------------------------- */ $result = mysql_query($sql) or die(mysql_error() ); // If the page is not found, redirect to a static page if(mysql_num_rows($result) == 0 ) { header("Location: page_not_found.html"); } $row = mysql_fetch_assoc( $result ); $body = stripslashes( $row["body"] ); // Include the header include("c:/wamp/www/exemples/header.php"); // Print the body of the page echo $body; // Include the footer include("c:/wamp/www/exemples/footer.php"); ?> --------------------CODE FOR MAIN PAGE END------------------- Hi all I have a MySQL data base that is saving information from a form. One the form a user can add a business name which is text and a logo if they have one. Now on my web page I want to beabe to display the picture if present if not I would like it to display the business name. How do I do this please. I know how to conect to DB etc just having problems getting my head around this problem. hey guys so im trying to display data into text boxes that are fetched from database according to checkbox with value id. processing is located before <!DOCTYPE html>: if(isset($_POST['edit_event']) && isset($_POST['check'])) { require "connection.php"; foreach ($_POST['check'] as $edit_id) { $edit_id = intval($GET['event_id']); //i tried (int)$edit_id; $sqls = "SELECT event_name,start_date,start_time,end_date,end_time,event_venue FROM event WHERE event_id IN $edit_id "; $sqlsr = mysqli_query($con, $sqls); $z = mysqli_fetch_array($sqlsr); { }button and form opens: <form method="post" action="event.php"> <input type="submit" name="edit_event" value="Edit Event">this is the html where the data will be echoed: <div id="doverlay" class="doverlay"></div> <div id="ddialog" class="ddialog"> <table class="cevent"> <thead><tr><th>Update Event</th></tr></thead> <tbody> <tr> <td> <input type="text" name="en_" value="<?php echo $z['event_name']; ?>"> </td> </tr> <tr> <td> <input type="text" name="dates_" value="<?php echo $z['start_date']; ?>"> <input type="text" name="times_" value="<?php echo $z['start_time']; ?>"> </td> </tr> <tr> <td><input type="text" name="datee_" value="<?php echo $z['end_date']; ?>"> <input type="text" name="time_" value="<?php echo $z['end_time']; ?>"> </td> </tr> <tr> <td><input type="text" name="ev_" value="<?php echo $z['event_venue']; ?>"> </td> </tr> <tr> <td><input type="submit" name="update" value="Update Event" id="update"> <input type="submit" id="cancelupdate" name="cancel" value="Cancel" > </td> </tr> </tbody> </table> </div>this is the part which is populated by data from database where isset($_POST['check']) gets the 'check' from: echo "<tr> <td><input type='checkbox' name='check[]' value='$id'>$name </td> </tr>";</form> thanks in advance! Edited by noobdood, 19 May 2014 - 10:42 PM. I wonder if someone can advise me on how to best tackle this issue. At the moment I am displaying a gallery of images pulled from the database. These are displayed as a thumbnail across my page, currently 4 in each row (then a new row is started dispalying the next 4 thumbnails). This works fine and does exactly what it should do. Now however I would like to display the username of who uploaded the image underneath each thumbnail. So it would go something like this: Display first 4 thumbnails pulled from database - breakline - Display username under each thumbnail - repeat for remainder of images, e.g: image image image image user user user user image image image image user user user user How would I go about this so it doesn't just display all the images in one vertical column, e.g: Image User Image User Image User I hope this makes sense. Any help would be greatly appreciated. |