PHP - Display Snippet Of Text But Not All
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 Similar TutorialsI really swear that the host I use is like screwing with me hard. Like literally will have something working one night, wake up the next day to my error log full and nothing working anymore. Or, like in this case, have the code working fine, perfectly in fact, to all of the sudden bring up all these errors and shit without changing anything I just can't figure it out. Point being, I am working on this portal, and on the account page, you can update your info. Which for one field... $result = queryMysql("SELECT * FROM accounts WHERE user='$user'"); $row = $result->fetch_assoc(); $set_comp = $row['company']; // Check if 'Company' value is set if (isset($_POST['company'])) { $company = sanitizeString($_POST['company']); if ($_POST['company'] != $set_comp) { queryMysql("UPDATE accounts SET company='$company' WHERE user='$user'"); } elseif ($set_company == "") { queryMysql("INSERT INTO accounts (company) VALUES('$company') WHERE user='$user'"); } elseif (empty($_POST['company'])) { $company = ""; } else { $company = stripslashes($row['company']); } } And the form... Quote<form method='post' action='account.php' enctype='multipart/form-data'> Company:</th><td><input type='company' size='50' maxlength='40' name='company' value='$company'> <input type='submit' value='Save Info'> </form>
Now before it inexplicably stopped working, what it was doing and meant to do was display a form, that either had the information that was set, or displayed nothing because nothing was entered, and you could either put something there or change what was already there. Now it keeps telling me: [22-Oct-2018 06:29:37 UTC] PHP Notice: Undefined variable: company in /home/iqy0804tq6fq/public_html/portal/account.php on line 262 Also, sanitizeString and queryMysql are my own created functions, they work fine. I tried removing the elseif (empty($_POST['company'])), and just left the last else in, didn't work. It just displays empty columns now. Now also, when I try to update, it feeds me all these errors now my SQL syntax is wrong its LIKE HOW DID THIS CHANGE IN 10 SECONDS!!? I didn't DO anything for my syntax to be any different than when it worked perfectly! It's insanity. I have this snippet that pulls up a confirmation page and requires a click to confirm before deleting the input member (or gives invalid member error), I have been completely unsuccessful removing the confirmation step and just deleting the member with success...
case 'deletemember': if (!isset($_POST['deletemember']) && !isset($confirm)) { $delmembername = null; print eval(get_template('delete_member')); } else { if (isset($confirm) && isset($mid)) { mysql_query("DELETE FROM members WHERE member_id='$mid'") or die(mysql_error()); mysql_query("UPDATE topics SET topic_rid=0 WHERE topic_rid='$mid'")or die(mysql_error()); mysql_query("UPDATE topics SET topic_lrid=0 WHERE topic_lrid='$mid'")or die(mysql_error()); mysql_query("UPDATE replies SET reply_aid=0 WHERE reply_aid='$mid'")or die(mysql_error()); show_message('Member deleted'); } else { $result = mysql_query("SELECT member_id FROM members WHERE member_name='$delmembername'"); if (mysql_num_rows($result) == 0) show_message('Member invalid'); else { $mid = mysql_result($result, 0); $board_title = sprintf('Delete '.$delmembername.'?'); $message = $board_title; $confirmed_link = '<a href="admin.php?a=deletemember&mid='.$mid.'&confirm=1">Delete</a>'; print eval(get_template('confirm')); } } } break;Can anyone help me here, I know it has to be something simple, I'm just not that great at PHP. Hi hi, CAn anyone tell me why this piece of code doesn't work? Code: [Select] <?php function readDirs($main){ $dirHandle = opendir($main); while($file = readdir($dirHandle)){ if(is_dir($file) && $file != '.' && $file != '..'){ readDirs($file); } else{ echo $file . '<br/>'; } } } $dir = '../../lib'; readDirs($dir); ?> It must show all the files in the directory, but only shows: Code: [Select] . .. technical The snippet repository section has been read only and nothing new for a long time.
Most of the ones there are pretty old.
The tutorials sections last post was from 2010
The old pagination tutorial needs a good mysqli and pdo version there.
http://www.phpfreaks...asic-pagination
I noticed how slow the sites been a while now, maybe need something to lure more in.
Hi, The code for displaying a results set in multiple columns (http://www.phpfreaks.com/forums/index.php?topic=95426.0) works really well and displays 1 2 3 4 5 6 7 8 Does anyone know how to change so it displays as 1 3 5 7 2 4 6 8 Any help would be greatly appreciated thanks a 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? 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. 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. 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 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. 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. 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. Hello.
I'm not sure whether this would come under PHP or HTML, but some sites display how many shares an article has had in a font, like this:
https://dl.dropboxus...0726.183853.png
What would the best way of doing this be?
Thanks.
I have a Php application that already has 2 buttons with input on the index page that perform some functions and output to different Php pages. Works good. How do I add a button with no input that would just perform a function and then just display a popup window showing the contents of a text file? I want to add several of these buttons for different functions and just display the contents of the resulting text files in popup windows. Any help would be greatly appreciated. Thanks in advance. Hi i have this edit form that allows user to mofy data but the problems on the text box is that it deletes the rest of the data after the space from the first word i tried to increase the size of the varChars on mysql but did no work why it happens how can i stop from happening?? this the form input <input type="text" name="name" id="name" class='text_box' value="<?php echo $_GET['name'];?>"/> Hello all , here is another problem of my project. I need to create a textarea , drop down list and submit button . At first , I can type whatever I want in the textarea , but for certain part I can just choose the word I want from drop down list and click submit , then the word will appear in the textarea as my next word . But I have no idea how to make this works , is there any simple example for this function ? Thanks for any help provided . I'd like to use a text editor like this one: http://tinymce.moxiecode.com/examples/full.php for my forums. But I am not sure exactly how I would prevent abuse and injects to messed up the page, rather than being contained in the designated area it is meant for. Could some one please help me, I know htmlspecailchars will not work, since some of the code needs to render as html Hi there. How do I reflect the text content of the variable $a in this text form: <input type="text" name="artist"> Regards Morris Hi, I am writing several scripts and some are used to amend extra information to a text file. However, I added a hyperlink to the text file so that the user can go back to a page where they can add extra information. However, since I have done this every time I amend more text to the text file, the extra text appears below the hyperlink rather than above it, and I was wondering if there was a way around this. My amend code is as follows: Code: [Select] <html> <head> <title>Amend File</title> <link rel="stylesheet" type="text/css" a href="rcm/stylesheet.css"> </head> <?php if($_POST['append'] !=null) { $filename="C:/xampp/htdocs/rcm/denman2.txt"; $file=fopen($filename, "a"); $msg="<p>Updated Information: " .$_POST['append']. "</p><br>"; fputs ($file, $msg); fclose($file); } ?> <body> <h1>Do you want to append to a document?</h1> Enter Updated Information: <form action="amendfile2.php" method="post"> <input type="text" size="40" name="append"><br><br> <input type="submit" value="Add updated information to report"> </form> <form action="viewfile3.php" method="post"> <input type="submit" size="40" value="View Web Blog"> </form> <form action="loginform.php" method="post"> <input type="submit" value="Click here to go to the Log In Screen"> </form> </body></html> And my text file is as follows: Code: [Select] <h1>Accident Report</h1> <p>First Name: Andrew Last Name: Denman Age: 18 Complete Weeks Since Accident: 2<br> <a href="amendfile2.php">Amend to this file</a> Any help would be appreciated |