PHP - Embedded <a Href> Code Cut Short, Undesired Results
i have an admin page that lists all the rows from a table. One of the fields is generated using FCKEditor, so the field has HTML Code in it. I would like to only show the first 100 or so chars of the field, but if the 100 chars ends in the middle of HTML code, specifically in this case <a href>, it cuts off, and creates "havoc" in my page. Is there a way to avoid this by seeing that the 100 char is in the middle of an <a href> tag (or any tag for that matter?
Here is what the generated html can look like :: <td class="tdresults">We are very excited to offer three great events at the <a href="http://www.mylongwebsite.c</td> <td class="tdresults">next field data</td> Thank you in advance. Pete Similar TutorialsAs you can see, this array is setting each colorvalue to each idvalue. Code: [Select] <?php include("config.php"); include("db.php"); $arrid=$_POST['id']; $arrcolor=$_POST['color']; foreach ($arrid as $idvalue) { foreach ($arrcolor as $colorvalue) { $sql = "UPDATE colors SET color='$colorvalue' WHERE id = '$idvalue'"; mysql_query($sql) or die("Error: ".mysql_error()); echo $sql; } } header("Location: " . $config_basedir . "adminhome.php"); ?> I have been able to pull the html of a given node Hello everybody,
i have an easy short code to upload multiple photos to "images" directory.
after upload each file, i give it unique name.
the problem i have is:
i want see the name of uploaded files and print this using echo as in line 21.
the line 21 gives me names but not the same names of uploaded files!
thank you very much for your help.
Rafal
<?php foreach ($_FILES['file']['name'] as $i => $name) { $types = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $name); $extension = end($temp); if ($_FILES["file"]["size"][$i] < 10240000 && in_array($extension, $types)) { if ($_FILES["file"]["error"][$i] > 0) { echo "Return Code: " . $_FILES["file"]["error"][$i] . "<br>"; } else { if (file_exists("images/" . $name)) { } else { move_uploaded_file($_FILES["file"]["tmp_name"][$i], "images/" . uniqid() . "." . $extension); echo "uploaded " . $_FILES["file"] , uniqid() . "." . $extension ; echo "<br>"; } } } else { $error = "Invalid file"; } } ?> <html> <head> <title></title> </head> <body> <form enctype="multipart/form-data" action="photo.php" method="POST"> <input type="file" name="file[]" id="file" ><br> <input type="file" name="file[]" id="file" ><br> <input type="file" name="file[]" id="file" ><br> <input type="file" name="file[]" id="file" ><br> <input type="submit" value="upload"> </form> </body> </html> PHP = 5.5.14
MySQL = 5.2.17
This simple .php script works as a standalone OK:
<?php require '<snip partial URL>mysqli.php'; // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT `callsign`, `qth`, `submitted` FROM `lqplogs` ORDER BY `callsign`"); echo "<table> <tr> <th><u>CALLSIGN</u></th><th><u>QTH</u></th><th><u>LOG SUBMITTED</u></th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['callsign'] . "</td>"; echo "<td>" . $row['qth'] . "</td>"; echo "<td>" . $row['submitted'] . "</td>"; echo "</tr>"; } echo "</table>"; mysqli_close($con); ?>A separate .html page with other info works by itself OK too, but when I try to embed the PHP script (with PHP start & end tags, of course) *between* these HTML tags: <table> <tr> <td> ... Full PHP Script Embedded here... </td> </tr> </table> I get this mess: "; while($row = mysqli_fetch_array($result)) { echo ""; echo ""; echo ""; echo ""; echo ""; } echo " CALLSIGN QTH LOG SUBMITTED " . $row['callsign'] . " " . $row['qth'] . " " . $row['submitted'] . " "; mysqli_close($con); ?>Any thoughts as to why are appreciated. Thanks! - FreakingOUT Hi guys; I've managed to find my way into something of a maze. <td> <a href="'Details/21/index.php'"?id= . $id .'>" . $row['id'] . "</a> </td> I'm looking at this line in the code. I realise it's currently in the wrong syntax but I'm just trying multiple different variations. At the moment I'm actually just trying to make it go to a static link but my real goal is to - get it to pick up the id number, of the id row I click, and concatenate that with the rest of my address string. Then use that as the href. Something like this: - "'Details/' + $id + '/index.php'" It's really confusing me though inside this loop and for some reason the id number is being picked up as an int, by the looks of things. It's getting above my level of understanding. Any chance one of you masters would through a n00b a lifeline?
This is my code below
<!DOCTYPE html> <html> <head> <title>LifeSaver DB</title> <h1> LifeSaver Database </h1> </head> <body> <table> <tr> <th>Id</th> <th>Location</th> <th>Initials</th> <th>TimeStamp</th> <th>Notes</th> </tr> <?php $conn = mysqli_connect("localhost", "meh", "pas", "DB"); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM LifeSaver1 ORDER BY id DESC"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { //for href row $id = $row['id']; $Footage = ['Footage']; echo "<tr> <td> <a href="'Details/21/index.php'"?id= . $id .'>" . $row['id'] . "</a> </td> <td>" . $row["Location"] . "</td> <td>" . $row["Initials"]. "</td> <td>" . $row["TimeStamp"]. "</td> <td>" . $row["Notes"] . "</td> </tr>";} //show table echo "</table>"; } else { echo "0 results"; } $conn->close(); ?> </table> </body> <style> table, td, th { border: 1px solid black; margin: auto; } table { border-collapse: collapse; color: #000; <!--font colour --> font-family: monospace; font-size: 18px; text-align: center;} th { background-color: #337AFF; color: white; font-weight: bold; } tr:nth-child(odd) {background-color: #add8e6} </style> </html> Edited February 8, 2020 by JonnyDriller I'm working on this database that was built by somebody else, and I'm having issues with. I'm attaching a photo of the database. The problem I'm having is that even when I hard-code variables in the statement, it still brings back "Sorry, but we can not find an entry to match your query" Is there something that I'm not seeing, or something that I'm doing wrong here? You can clearly see in the photo that I'm trying to grab the info with the id_pk 300000. Code: [Select] <?php //$search = $_POST['search']; //$search = '300000'; $data = mysql_query("SELECT * FROM page_listings WHERE id_pk = '300000'"); while($result = mysql_fetch_array( $data )) { $name = $result['page_name']; $id = $result['id_pk']; $page = $result['html']; $cat = $result['category']; $dir = $result['directory']; echo "ID: " .$id ."<br>Page: ". $name ."<br>HTML: ". $page ."<br>Category: ". $cat ."<br>Directory: ". $dir ."<br />"; } $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } ?> Thanks in advance [attachment deleted by admin] i basically have a php search form on a property website, and depending on what area/type of property/number of bedrooms and price range the search form should bring up results based on that. at the moment it just bring up everything. how would i make it bring up the correct results depending on the search made? here my php code: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Mumtaz Properties</title> <link rel="stylesheet" href="cutouts/style.css"/> </head> <body> <!--Main Div Tag--> <div id="wrapper"> <div id="header"> <div id="logo"><a href="index.html"><img src="cutouts/Homepage/logo.png" alt=""/></a></div> </div> <div id="navigation"> <a id="Home" href="index.html" title="home"><span>home</span></a> <a id="Sale" href="forsale.html" title="for sale"><span>for sale</span></a> <a id="Rent" href="forrent.html" title="for rent"><span>for rent</span></a> <a id="Contact" href="contact.html" title="contact us"><span>contact us</span></a> </div> <div id="main"> <div id="results"><img src="cutouts/Homepage/results.png"></div> <?php $server = ""; // Enter your MYSQL server name/address between quotes $username = ""; // Your MYSQL username between quotes $password = ""; // Your MYSQL password between quotes $database = ""; // Your MYSQL database between quotes $con = mysql_connect($server, $username, $password); // Connect to the database if(!$con) { die('Could not connect: ' . mysql_error()); } // If connection failed, stop and display error mysql_select_db($database, $con); // Select database to use // Query database $result = mysql_query("SELECT * FROM Properties"); if (!$result) { echo "Error running query:<br>"; trigger_error(mysql_error()); } elseif(!mysql_num_rows($result)) { // no records found by query. echo "No records found"; } else { $i = 0; echo '<div style="font-family:helvetica; font-size:14px; padding-left:15px; padding-top:20px;">'; while($row = mysql_fetch_array($result)) { // Loop through results $i++; echo '<img class="image1" src="'. $row['images'] .'" />'; //image echo "<span style=\"color:#63be21;\">Displaying record $i<br>\n<br></span>"; echo "<b>Location:</b> ". $row['Location'] . "<br>\n"; // Where 'location' is the column/field title in the database echo "<b>Property Type:</b> ". $row['Property_type'] . "<br>\n"; // as above echo "<b>Bedrooms:</b> ". $row['Number_of_bedrooms'] . "<br>\n"; // .. echo "<b>Purchase Type:</b> ". $row['Purchase_type'] . "<br>\n"; // .. echo "<b>Price:</b> ". $row['Price_range'] . "<br>\n"; // .. } echo '</div>'; } mysql_close($con); // Close the connection to the database after results, not before. ?> </div> </div> </body> </html> Would like to thank you in advance. Hello, Here's the weird thing, some of the pages shows the results, and some pages just won't show results at all, and I'm not getting any errors here is the one that doesn't Code: [Select] <? function display_mptt($user) { global $db; // retrieve the left and right value of the $root node $sql2 = "SELECT * from mptt where id='25'"; $result2 = mysql_query($sql2 ,$db); if(!$row2 = mysql_fetch_array($result2)) echo mysql_error(); echo '<h1>Users List</h1>'; // start with an empty $right stack $right = array(); // now, retrieve all descendants of the $root node $sql = "SELECT * from mptt WHERE 'left' BETWEEN '".$row2['left']."' AND '".$row2['right']."' ORDER BY 'left' ASC"; $result = mysql_query($sql ,$db); // display each row while ($row = mysql_fetch_array($result)or die(mysql_error())) { // only check stack if there is one $count = mysql_num_rows($result); if (count($right)>0) { // check if we should remove a node from the stack while ($right[count($right)-1]<$row['right']) { array_pop($right); } } // display indented node title // add this node to the stack $var3 = '10'; echo "<table width='589' border='1'> <tr> <th>ID</th> <th>Name</th> </tr>"; echo "<tr><td><a href=\"user.php?id=".$row['id']."\">".$row['id']."</a></td>"; echo "<td>" . $row['title'] ." </td>"; echo "</tr>"; echo "</table>"; $right[] = $row['right']; } } display_mptt(1); ?> and here is the page that does Code: [Select] <? function display_mptt($user) { global $db; $id = $_GET['id']; // retrieve the left and right value of the $root node $sql2 = "SELECT * from mptt where id= ".$id.""; $result2 = mysql_query($sql2 ,$db); if(!$row2 = mysql_fetch_array($result2)) echo mysql_error(); echo '<h1>Your Tree</h1>'; // start with an empty $right stack $right = array(); // now, retrieve all descendants of the $root node $sql = "SELECT * from mptt WHERE `left` BETWEEN ".$row2['left']." AND ".$row2['right']." ORDER BY 'left' ASC"; $result = mysql_query($sql ,$db); // display each row while ($row = mysql_fetch_array($result)) { // only check stack if there is one if (count($right)>0) { // check if we should remove a node from the stack while ($right[count($right)-1]<$row['right']) { array_pop($right); } } // display indented node title echo str_repeat(' ',count($right)).$row['title']."<br>"; // add this node to the stack $right[] = $row['right']; } } display_mptt(1); ?> Hey guys, Having a slight problem with part of the code in my index.php file Code: [Select] mysql_select_db('db_name', $con); $result = mysql_query("SELECT * FROM spy ORDER BY id desc limit 25"); $resulto = mysql_query("SELECT * FROM spy ORDER BY id desc"); $count = mysql_num_rows($resulto); while($row = mysql_fetch_array($result)) { ?> <div class="contentDiv">Someone is looking at <?=$row[title];?> Stats for "<a href="/<?=$row[type];?>/<?=$row[code];?>/<?=$row[city];?>"><?=$row[code];?> <?=$row[city];?></a>"</div> <?}?> </div> <div id="login"></div> <? include("footer.php"); ?> </div> </body> </html> I'm getting the following error when viewing the file Code: [Select] Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in ~path to file/index.php on line 70 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in ~path to file/index.php on line 71 where lines 70 and 71 are $count = mysql_num_rows($resulto); while($row = mysql_fetch_array($result)) Any ideas on how to fix this? am total newbie to programming, apart from knowing SQL, the thing is i have been given a MYSQL database containing various information about kids diseases and a web interface written in php to create reports from the database that can be accessed via the interface. there are almost 25 different variables that need to be computed in the report, i have written sql queries to compute all these values, but i don't know anything about PHP, if i have all these queries isn't there a way for me to combine all these sql queries to be display results on a webpage and come up with this report without writing PHP code? Thanks for your help very sorry if this is too basic This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=330251.0 hi guys, i just finished highschool starting to do webdesign at uni, and for one of my major project i want to make a search engine as simple as google that searches for example 10 websites and with the keyword given it brings out the results. im doing a website on jetski sales results so if someone want to buy a jetski they come to this website and just choose the choose one from those 10 website without going to them individually. so it brings out all search resuts in a nice results format, and when you click on each results it take you to the website but i wanna be able to show their photo and price so just like brings their results into your site but combing 10 website results. and i need to have an advance search option where they can search year price age of jetski, and all these variables are also in the 10 websites that im getting the results from. i have been doing some searching and i cant get my head around i need some help LOL i dont wanna fail... cheers guys 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 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=355144.0 'm trying to set up short urls on my page and what I need to do is insert a url from a parent frame page into an input. So on the child iframe I'm using this to pull the referers url Code: [Select] <?php $url="".$_SERVER['HTTP_REFERER']; echo $url; ?> which works great Then I want to insert it in an input on the same page Code: [Select] $site = my_SITE; echo <<<HTML <form method="post" action=""> <input type="text" name="url" value="Insert Here" size="30" /> <input type="submit" value="submit" /> </form> HTML; Any Help? What is the best way to handle an auto database check? could php do this without the help of JQUERY or JAVASCRIPT? Hey eveyone, I have this great idea I would love to do but I have some questions and whenever I have questions I come here and they always get answered :-) Anyway what do you guys know about SMS short codes (you know those commercials on TV that are like text ringtone1 to 555)? I did some quick reading and it seems they are super expensive?!? Is there anyway to get them free or cheaper if you can write your own code? Has anyone had any experience with sms short codes? Also is there anyway for a site to receive a SMS and then charge that persons service provider with php? Thanks I am re-using a simple script that works good to get random files from a folder to get embed codes into a jquery slider(to embed videos)to create a video slider/gallery( http://www.awkward.se/demo/showcase/).The reason for the embed is there will be 50 and more videos in gallery and that's bad for page weight/page load. I have taken out the random element for this code because i just want videos to get embeded when icons are clicked(the onclick is already set up with the jquery script-->no worry about that). I have change a few things (in red) and i thought i would work, but i am really not sure how to make it work at this point??? I get this error message: Quote Fatal error: Cannot use object of type DirectoryIterator as array The original random code to get files which works perfect: Quote <?php function getRandomFile($path) { $files = array(); foreach( new DirectoryIterator($path) as $file ) { if($file->isFile()) { $files[] = $path . $file->getFilename(); } } $i = array_rand($files); return $files[$i]; } $path = "vids"; $file = getRandomFile($path); $final= substr($file, 4); ?> It inserts into the html like this: Quote <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="280" height="210" id="FLVPlayer"> ... <param name="FlashVars" value="&MM_ComponentVersion=1&skinName=Clear_Skin_2&streamName=vids/<?php echo ($final); ?>&autoPlay=false&autoRewind=false" /> <param name="swfversion" value="8,0,0,0" /> ... I modified it like this to get files to embed in the jquery gallery(changed values in blue): Quote <?php function getEmbedFile($path) { $filesEmbed = array(); foreach( new DirectoryIterator($path) as $filesEmbed ) { if($filesEmbed->isFile()) { $filesEmbed[] = $path . $filesEmbed->getFilename(); } } $i = array_rand($filesEmbed); return $filesEmbed[$i]; } $path = "thumbEmbed"; $filesEmbed = getEmbedFile($path); ?> <div> <?php echo ($filesEmbed); ?> It inserts into the html like this: Quote <div class="showcase-thumbnail" > <img src="images/ShowcaseThumbs/video1.GIF" alt="01" width="55px" /> <div class="showcase-thumbnail-caption">Play video 1</div> To give you a better idea this a pic of the jquery slider: HI,
I'm using;
https://github.com/o.../PHP-Pagination
It works on my local test server, but on EC2, short tags are apparently not enabled by default.
The pagination is printing php:
<div class="pagination"><ul class="<?php= implode(' ', $classes) ?>"> <li class="<?php= implode(' ', $classes) ?>"><a href="<?php= ($href) ?>"><?php= ($previous) ?></a></li> <li class="number active"><a data-pagenumber="<?php= ($current) ?>" href="#"><?php= ($current) ?></a></li> <li class="number"><a data-pagenumber="<?php= ($current + $x + 1) ?>" href="<?php= ($href) ?>"><?php= ($current + $x + 1) ?></a></li> <li class="number"><a data-pagenumber="<?php= ($current + $x + 1) ?>" href="<?php= ($href) ?>"><?php= ($current + $x + 1) ?></a></li> <li class="<?php= implode(' ', $classes) ?>"><a href="<?php= ($href) ?>"><?php= ($next) ?></a></li>I tried replacing <? with <?php to no avail. Not sure if the fact that one dependency is named "render.inc.php" instead of just ".php" which is causing the issue. Any ideas why apache is doing this? I'd rather not edit the .ini. Thanks.. Edited by arbitrageur, 03 November 2014 - 01:00 AM. |