PHP - Php/mysql Tags
Hi Guys
Whats the easiest way to store tags in a database from a php form? If I have a text field called tags, and each tag is comma seperated how do I process the data? I have a table called tags, with 3 fields, tag_id, post_id and tag Basically how would I basically turn this input: a tag, b tag, c tag from a form field to tag_id cat_id tag 1 dont worry about me, i can work this out! tag a 2 dont worry about me, i can work this out! tag b 3 dont worry about me, i can work this out! tag c Many Thanks Similar TutorialsSay I have the following text stored in a MySQL database... Code: [Select] <b>Classic Quote from movie</b> and I retrieve it into a variable called $text, how do I properly echo that so that it keeps the bold tags and actually display the text "Classic quote from movie" in BOLD? I'm doing something wrong somewhere along the line (simply doing "echo $text;") because it displays on the page as... Code: [Select] <b>Classic Quote from movie</b> Instead of... Classic Quote from movie Any info on properly storing and echoing back HTML would be very appreciated. I have a tag column in the table of posts. I store tags as "tag1,tag2,tag3,...". When displaying tags in the post, I explode to have an array. Everything is OK, but I cannot create a tags cloud; as I need to have the occurrence of each tag to increase the font. What is a practical trick to create tag clouds? I think the common method is to build a table for post tags and store each single tag in a separate cell. But I hope to keep my database tidy. Hello, so i made table with Tags row which is Text(126).. and idea is to put text like "PHP, MySQL, Forum, Blog" etc etc...
I have problem searching tags my search code:
$requestedtag = $con->real_escape_string($_GET['tag']); $sql = "SELECT * FROM images WHERE tags = '$requestedtag' ORDER BY ID DESC LIMIT 12"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { $image_id = $row["ID"]; $image_title = $row["Title"]; $image_url = $row["ImgURL"]; $image_tags = $row["Tags"]; echo '<div class="col-3"><div class="thumb"><a href="/image.php?id='.$image_id.'" title="'.$image_title.'"><img src="'.$image_url.'"></img></a></div></div>'; } } But it doesnt return anything. I think the problem is that row["Tags"]; is divided by "," from tags and i should split it somehow but i dont really know what to do... hi everyone, did not know what to make the subject, but here is what I want to do: I have a string, which gets returned to me from a linux app on my server, it looks something like this: Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8"> <TITLE> </TITLE> <META NAME="GENERATOR" CONTENT="OpenOffice.org 3.2 (Linux)"> <META NAME="AUTHOR" CONTENT="Administrator"> <META NAME="CREATED" CONTENT="20110106;14170000"> <META NAME="CHANGEDBY" CONTENT="HOD"> <META NAME="CHANGED" CONTENT="20110522;16540000"> <STYLE TYPE="text/css"> <!-- @page { margin: 0.26in } P { margin-bottom: 0.15in; direction: ltr; color: #000000; line-height: 0.15in; text-align: justify; widows: 2; orphans: 2 } P.western { font-family: "Arial", sans-serif; font-size: 10pt; so-language: en-US } P.cjk { font-family: "Batang", "바탕", serif; font-size: 10pt } P.ctl { font-family: "Times New Roman", serif; font-size: 10pt; so-language: ar-SA } A:link { color: #0000ff } --> </STYLE> </HEAD> <BODY LANG="en-US" TEXT="#000000" LINK="#0000ff" DIR="LTR" STYLE="border: 5.05pt double #000000; padding: 0.67in 0.92in"> <P>I want this and the tags around it, just not the html, head, body and their closing tags.</P> </BODY> </HTML> within the body, the tags are each styled for example: <p style="color: red"></p> so I cannot just get rid of all html, I want to get only all the content within the body tags, but without the body tags obviously strip_tags does not work as i need, I only want to strip certain tags. If someone can help me with this i will much appreciate it. I am asking out of curiosity, how does this problem usually get solved, when using a tag system to sort content, and users enter similar tags. For example: flower and flowers... which means the difference between singular and plural. Judging by other sites which are around, this problem is not solved at all, they simply let you add as many tags as you want and then rank the most used tags, it indeed is a solution, but seems more like a walk-around solution to me. Any ideas how somebody could approach to solve this one? EDIT: My suggestion would be an analysis function, which analyzes the entered tag and then suggests the user that similar tags have been already entered and perhaps he wants to choose one of those which have been already entered. This does work though with a high traffic websites what can happen is the following: php and php5 You can end up with two similar tags which are both widely used though have different meanings to the user base. This one could be solved by simply prohibiting similar tags with little additions or changes, and so to speak "forcing" the user to choose something which is already there. May be a way, though it can turn out as a bad solution as well. Do anyone know how i can put the html tags in the same line as the other html tags? Here's an example: Code: [Select] Images | Link | Delete | Enabled On my code, it break the tags to the new line without put on the same line as the other tags. Here's the code: Code: [Select] [code]<?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'myusername'); define('DB_PASSWORD', 'mypass'); define('DB_DATABASE', 'mydbtable'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); if($username == '') { $errmsg_arr[] = 'username ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD ID missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $qry="SELECT * FROM members WHERE username='$username' AND passwd='$password'"; $result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if(mysql_num_rows($result) > 0) { $qrytable1="SELECT images, id, public FROM members WHERE username='$username'"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result1)) { echo '<p id="images"> <a href="images.php?id='.$row['id'].'">Images</a></td> | <a href="http://' . $row["links"] . '">Link</a> </td> | <a href="delete.php?id='.$row['id'].'">Delete</a> </td> | <p> <p id="test">'.$row['Public'].'</td>''; } } } ?>[/code] Hello i said to replace the short php tags (<??>) with long php tags (<?php ?>) but it is giving me Parse errors -.- the parse error apears if i have <?php//NOTE ?> With <?//NOTE?> Is all ok and it dosnt give me that error .. could anyone please tell me why dos it give the error and some more details about the tags etc Thanks in advance alright I've seen and use Code: [Select] <?php Code: [Select] <?but never before do I recall seeing Code: [Select] <?= Nor do I even know where to look that up, so.. anyone ever see that used before, if so, any insight as to why someone would choose that? How does PHP continuity exist in different php tags? for example, if i connect to a database in a header, and close the tag, can I still work off of the same database in another tag? I have just been given some code that is live on a web site. I pulled it down to my local linux machine and the php will not run. I have worked out the issue the php tags are <? scripting ?> it is missing the php. I have a couple of questions how do I get my local linux machine get <? scripting ?> this to work and I have a lot of code that is like this and I am sure that it is no longer secure is this right? I found this code on a website: <?php //Reads ID3v1 from a MP3 file and displays it $mp3 = "1.mp3"; //MP3 file to be read //make a array of genres $genre_arr = array("Blues","Classic Rock","Country","Dance","Disco","Funk","Grunge", "Hip-Hop","Jazz","Metal","New Age","Oldies","Other","Pop","R&B", "Rap","Reggae","Rock","Techno","Industrial","Alternative","Ska", "Death Metal","Pranks","Soundtrack","Euro-Techno","Ambient", "Trip-Hop","Vocal","Jazz+Funk","Fusion","Trance","Classical", "Instrumental","Acid","House","Game","Sound Clip","Gospel", "Noise","AlternRock","Bass","Soul","Punk","Space","Meditative", "Instrumental Pop","Instrumental Rock","Ethnic","Gothic", "Darkwave","Techno-Industrial","Electronic","Pop-Folk", "Eurodance","Dream","Southern Rock","Comedy","Cult","Gangsta", "Top 40","Christian Rap","Pop/Funk","Jungle","Native American", "Cabaret","New Wave","Psychadelic","Rave","Showtunes","Trailer", "Lo-Fi","Tribal","Acid Punk","Acid Jazz","Polka","Retro", "Musical","Rock & Roll","Hard Rock","Folk","Folk-Rock", "National Folk","Swing","Fast Fusion","Bebob","Latin","Revival", "Celtic","Bluegrass","Avantgarde","Gothic Rock","Progressive Rock", "Psychedelic Rock","Symphonic Rock","Slow Rock","Big Band", "Chorus","Easy Listening","Acoustic","Humour","Speech","Chanson", "Opera","Chamber Music","Sonata","Symphony","Booty Bass","Primus", "Porn Groove","Satire","Slow Jam","Club","Tango","Samba", "Folklore","Ballad","Power Ballad","Rhythmic Soul","Freestyle", "Duet","Punk Rock","Drum Solo","Acapella","Euro-House","Dance Hall"); $filesize = filesize($mp3); $file = fopen("1.mp3", "r"); fseek($file, -128, SEEK_END); $tag = fread($file, 3); if($tag == "TAG") { $data["song"] = trim(fread($file, 30)); $data["artist"] = trim(fread($file, 30)); $data["album"] = trim(fread($file, 30)); $data["year"] = trim(fread($file, 4)); $data["comment"] = trim(fread($file, 30)); $data["genre"] = $genre_arr[ord(trim(fread($file, 1)))]; } else die("MP3 file does not have any ID3 tag!"); fclose($file); while(list($key, $value) = each($data)) { print("$key: $value<br>\r\n"); } ?> How would i edit this to look in a directory, and sub-directories and get information for every mp3 and add the data to a mysql database (the latter i can do easily) Hi guys, i have not started this as of yet, however i will be given a project to make a micro-blogging website similar to that of Twitter or Facebook but obviously on a much smaller scale I have been searching on google however i have not found anything. Maybe i haven't been using the right words in my query, not sure :-/ I have been trying to do some research, however i can't seem to find how to incorporate @ tags found in Twitter / Facebook. e.g. If i want to tag a person in a Status Update: Hey @John Smith, Football in the park at 3pm? If anyone is able to help i would be grateful Thank You Hi there. I'm doing a calendar page with php. It's based on a template and in this template all the output text and html-tags are saved into a xml string. I want to add a tooltip/hovering effect and found one on the net. I applied this script but it doesn't work. It works on "plain html", but when it is within the php it just won't work.. This is how my code looks like: START: $xml = '<?xml version="1.0" ?><response><content><![CDATA['; --- kode -- kode -- kode --- $xml.="<div class='calevent'> <a href='' class='someClass' title='<img src=1.jpg>'>Curabitur dolor eros</a> <a href='java script:navigate(\"\",\"\",\"".$row[0]."\")'>"; $xml.=$erow[0]; $xml.="</a></div>"; END: echo $xml; ------------- The script is supposed to add tooltips when an element is declared "someClass" and it works on plain html on the same page.. Take a look: http://clubbinghagen.dk/calendar/ Links in the calendar have no tooltip, but the Admin link in the center bottom (a bit hard to see!) has a working image as a tooltip. Any ideas?? I wish to have all my products show in an XML for googles product search. Also when I try to view this in internet explorer I get an error about quote marks (") being invalid. Code: [Select] <? header('Content-Type: text/xml; charset=UTF-8'); include("includes/functions.php"); $connected = dbConnect(); // the DATE_FORMAT is to make the date RFCwhatsit compliant $datetocheck = date("Y-m-d H:i:s"); $sql = "SELECT * FROM `products` ORDER BY `productTitle` ASC"; $resultset = mysql_query($sql); //echo("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ? >\n"); echo("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); ?> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <? echo('<atom:link href="http://www.site.com/rss.php" rel="self" type="application/rss+xml" />'); ?> <channel> <ttl>1</ttl> <title>Welcome - RSS Feed</title> <link>http://www.site.com?s=rssimg</link> <description>RSS Feed</description> <language>en-us</language> <pubdate><?=gmdate("D, d M Y H:i:s \G\M\T");?></pubdate> <lastbuilddate><?=date("D, d M Y H:i:s \G\M\T");?></lastbuilddate> <generator>OnTheFly</generator> <image> <title>Welcome - RSS Feed</title> <url>http://www.site.com/images/header.png</url> <link>http://www.site.com?s=rssimg</link> <width>88</width> <height>31</height> </image> <?php while ($result = @mysql_fetch_assoc($resultset)) { $submitteddatetime = date("D, d M Y H:i:s \G\M\T", strtotime($datetocheck)); ?> <item> <title><![CDATA[<? echo(htmlentities(stripslashes($result[productTitle]))); ?>]]></title> <guid>http://www.site.com<? echo("/?v=" . $result[Pid] . "&h=r"); ?></guid> <pubdate><? echo($submitteddatetime); ?></pubdate> </item> <?php } ?> </channel> </rss> I have a string $str that contains a web page information. it has multiple title tags [title][/title] within it. How do I get the contents within all these title tags thanks I made a script to grab the data between these tags on my page: Code: [Select] <td class="numbers"> </td> It shows only the numbers and that's what I want (see Ex: ) but if I view the source code it shows this: Code: [Select] Andreea - <td class="numbers">111</td><br /> Claudia - <td class="numbers">30</td><br /> Daniel - <td class="numbers">37</td><br /> Adela - <td class="numbers">4</td><br /> Is there a way to display the result without those tags ? Ex: Andreea - 111 Claudia - 30 ............ As you can see, I only need the numbers, there's nothing else inside those tags. I am tweaking a function which takes data that was entered into a Form TextArea and wraps each paragraph with <p></p> tags so things are properly marked up. It seems to be working okay, except for two annoying things... 1.) When I go to View ---> Source, I do NOT want to see paragraph after paragraph all on the same line. I tried adding a \n into the preg_replace but it is adding an extra carriage return in the output. 2.) Right now, if my code sees 2 \n's it will convert that to "</ p><p>", which is fine. However it does the same thing if there are 20 \n's which is technically wrong, because maybe someone wanted the extra 18 carriage returns between their paragraphs?! For example, in the line below "I decided to start..." that line should get wrapped in <p></p> and then there should be a <br /><br /> because the User added two *extra* carriage returns, and then the next line "My boss is a jerk..." should get wrapped in <p></p> because it is also a paragraph. I'm sure this one is impossible to do, but the end goal is simple... Regardless of how many carriage returns there are between blocks of text, the blocks of text should first get wrapped in <p> </p> but then any additional line spacing should be preserved. Hope that makes sense?! Here is the code I am working with... $text="I decided to start my own business because I want to be my own boss! My boss is a jerk and never appreciates anything that I do for him, so why put up with the abuse?! He takes me for granted and doesn't appreciate all of my talents. Running my own business will give me a chance to do things as I see fit... Line One Line Two Line Three Line Four Line Eight"; $text2 = htmlentities($text, ENT_QUOTES); function nl2p($string, $line_breaks = true) { // Remove existing HTML formatting to avoid double tags. //^ $string = str_replace(array('<p>', '</p>', '<br>', '<br/>'), '', $string); // Replace Carriage Return with Empty String. // Replace multiple Newlines with closing & opening paragraph tags. // Replace single Newline with break tag. if ($line_breaks == true) { return '<p>'.preg_replace(array("#\r#","#\n{2,}#", "#\n#"), array("","</p><p>", "<br />\n"), $string).'</p>'; }else{ return '<p>'.preg_replace("#\n#", "</p><p>", trim($string)).'</p>'; } } echo nl2p($text2, TRUE); Oh, btw, as you can see, adding a \n after the line break (i.e. "<br />\n") actually added the line break in my Source as I wanted. It is just when you add a \n in between the paragraphs that my code misbehaves (i.e. "</p>\n<p>"). Can these two problems be fixed?? Thanks, Debbie Hi all This probarly looks really bad but im trying to replase tags that change. So far it only replaces the last tag and not well either. I will try to show you Code: [Select] function testfunc($value) { if ($value=='gallery'){$return .= "this gallery has worked = --$value--";} if ($value=='email'){$return .= "this email has worked = --$value--";} return $return; } $test = "this is a test {%email%} message {%gallery%} rtfgdsfgdsfg"; $test = preg_replace("#(.*){%(.*?)%}(.*)#is",'$1' . testfunc('$2') . '$3', $test); echo $test; this outputs this is a test {%email%} message rtfgdsfgdsfg but im trying to get this this is a test this email has worked = --email-- message this gallery has worked = --gallery-- rtfgdsfgdsfg Im sure im way off but I hope you can understand. Thank you for taking the time to read this post. I am working on a poject, where the search functions doesnt work as the user wishes. The coding is technically correct, but the idea behind it is wrong. Basically at the moment, the script receives this: thesite.com/search.php?q=xxxx&Submit=Search The search script then runs a database query to search the tag coloumn, looking for like $q. This would work, however the structure of the coloumn is tag1, tag2, tag3, tag4. So my resolutions is this so far: I explode the $q variable, via the + (if you search more than one term "thesite.com/search.php?q=search+stuff&Submit=Search" I then count the elements in the array and write the database function accordingly Code: [Select] $var = @$_GET['q'] ; $trimmed = trim($var); $searchpieces = explode("+", $trimmed); $dbquery=""; $count = count($searchpieces); for ($i = 0; $i < $count; $i++) { if($i == 0){$dbquery.="tags = $searchpieces[$i]";} elseif($i > 0){$dbquery.=" OR tags = $searchpieces[$i]";} } So my database query is $sql = "select * from gallery where $dbquery order by date DESC " . $limit; so my question is this.. how to i eplode the tags database coloumn, so my datase query an look at each tag fro "tag1, tag2, tag3" as "tag1" "tag2" "tag3" I am not even sure if this is possible, but its the system that is already in place. The problem with the current system, is because the pictures have alot of tags and the database query is $like $q, it just shows all images in the database as the result hi freaks, still working on my email bot. im currently trying to escape <>-tags to be displayed- but not the browser wont exectute it (i.e. xls-tags) i want them as chars. so whin my $content is like <xsl:stylesheet> <xsl:template match="/"> <more xls...> it shows a stylesheet. i just want the chars. Here is what ive been trying so far: but its bad Code: [Select] <?php $string='<tag> > < asdasf'; $bomb=array( '<', '>', ); $defusal=array( '-', '!', ); $string= preg_replace($bomb,$defusal,$string); echo $string; ?> error: Warning: preg_replace() [function.preg-replace]: No ending matching delimiter '>' found in C:\xampp1\htdocs\code.php on line 13 donno any further now |