PHP - Changine One Row In Mysql And Listing Them (in Lack Of Better Description Lol)
Hi,
I have a little problem that I can't seem to solve myself. My coding skills are very limited, just wanted to mention that . I have a list of rows, bascially banners that members submit. They have to be manually approved by me before they are put on air. So to quicken up this process I made this little code in my admin panel. $bq = mysql_query("SELECT id, usrid, bname, burl, btarget FROM ban_rotator WHERE status = 'Waiting'"); $pb = mysql_num_rows($bq); if ($_GET['ap']) { $bid = $_GET['ap']; mysql_query("UPDATE ban_rotator SET status = 'Active' WHERE id = '$bid'"); It works perfectly except for one thing. It will always show the banner I just approved in addition to the remaining ones that are waiting. Any tips would be appreciated. I have to add that this code is a part of a fairly large admin panel php file. Just realized i need a bit more explanation. If I hit refresh in the browser the one I just approved will be gone. As I would like it to be after hitting Approve on the banner in question. If I just approve the second banner (after approving the first), the first will be gone from the list of waiting and the second will still show until I either hit approve on the third or hit refresh in the brower. Alka Similar TutorialsHi. I'm making a website where users can upload files along with title, description and image. I can get them making the page (str replace) but I only know how to list the files with just the file title in a basic links directory. Any ideas how I could include title, description and a picture (as well as the link to the page). Sort of like with Youtube search results or engine001.com/games.htm? Any help would be greatly appreciated. Thanks hi all,
Firstly I am new to the php language,
hopefully this is not a silly question or a no brainer.
I have looked over my code.. and for some reason when I insert data from a cms into a mySql database thers two fields that swop around..
HERES THE CODE IM WORKING WITH :
<?php //if form has been submitted process it if(isset($_POST['submit'])){ $_POST = array_map( 'stripslashes', $_POST ); //collect form data extract($_POST); //very basic validation if($title ==''){ $error[] = 'Please enter the title.'; } if(!isset($error)){ try { //insert into database $stmt = $handler->prepare('INSERT INTO event_calendar (title,event_date,description) VALUES (:title, :description, :event_date)') ; $stmt->execute(array( ':title' => $title, ':description' => $description, ':event_date' => date('Y-m-d') )); //redirect to index page header('Location: index.php?action=added'); exit; } catch(PDOException $e) { echo $e->getMessage(); } } } //check for any errors if(isset($error)){ foreach($error as $error){ echo '<p class="error">'.$error.'</p>'; } } ?> <form action='' method='post'> <p><label>Title</label> <input type='text' name='title' value='<?php if(isset($error)){ echo $_POST['title'];}?>'></p> <p><label>Description</label><br /> <textarea name='description' cols='50' rows='5'><?php if(isset($error)){ echo $_POST['description'];}?></textarea></p> <p><label>Date of Event : (y-m-d) :</label><input name="event_date" type="date" value='<?php if(isset($error)){ echo $_POST['event_date'];}?>'></p> <p><input type='submit' name='submit' value='Submit'></p> </form>Could anyone please just look through it.. My database structure is simple.. id, title, description, event_date Thanks in advance hello guys, I'm stuck he I have a table called customer_messages which has a entryid, custid, fromname, message, flag i have written a script to enter data into this. and another script to count the number of entries in the table. now i want to display entries in the table on to a script what i did was this: flag is by default '0' which mean unread. insertion code: Code: [Select] insert into customer_messages (customer_id,customer_fname,customer_message,flag) values('21','mike','hello!','0') fetching number of unread messages Code: [Select] select count(*) from customer_messages where flag = '0' $q = "select count(*) from customer_messages where flag = '0'"; $w = mysql_query($q); $r = mysql_fetch_array($w); $t = $r[0]; $t now gives me total number of unread messages in the db. now, I want to display these messages on to a page in the following format: ----------------------------------------------------------------------------------------------- | sender | message | mark as read | ----------------------------------------------------------------------------------------------- | name_from_db | message_from_db | check box | ----------------------------------------------------------------------------------------------- | name_from_db | message_from_db | check box | ----------------------------------------------------------------------------------------------- how do I do this? I'm assuming that I have to use a loop here, I put the code in a while loop, but that didnt work out for me. can I use a for loop here? if yes how do i use it? my brain's froze now so, i cant think atm, can someone help me out please? ================================================================================= in short i need the data from database to be listed as listbox control in asp.. is it possible? Right, it's hard to explain, but I'll try my best. Litterally, I have a 'tab' box on my homepage. And a table called 'news'. Now, the table has the rows "shorttitle" "shortstory" and "image" in it. I want the title the three latest titles to be on the three tabs, and the story and image in the respective content areas. (The table auto increments the ID, and so order by ID descending limit of 3 yes?) Now, the code for the tabs is: Code: [Select] <?php $query = "SELECT * FROM news where published = '1' ORDER by id DESC LIMIT 3"; $row_news = mysql_fetch_array($query); ?> <div id="myTabs"> <ul> <li><a href="#firsttab"></a><? echo $row_news['shorttitle']; ?></li> <li><a href="#secondtab">newsID2</a></li> <li id="last"><a href="#thirdtab">newsID3 </a></li> </ul> <div id="firsttab" class="tab_content"> <div class="rafat"> <img src="<? echo $row_news['image']; ?>" /> <p> <? echo $row_news['shortstory']; ?> </p> </div> </div> <div id="secondtab" class="tab_content"> <div class="rafat"> <img src="newsIMAGE2" /> <p> newsSTORY2 </p> </div> </div> <div id="thirdtab" class="tab_content"> <div class="rafat"> <img src="newsIMAGE3" /> <p> newsSTORY3 </p> </div> </div> </div> Now, i've filled in the first tab with the MYSQL queries, but i'm unsure how to fill in the other two, because of the way it's coded.. I can't do a 'repeating' code, because of the IDs of the divs, and the three tabs are bunched together.. Anyone any ideas? Much apreciated. Thanks Luke Hi I have used TCPDF to generate documents with single values from a mysql table. Now I want to generate a calendar. I have a table events_pbw which contains (amongst others) the fields id, date and name. I would like to generate a pdf which lists all of the results for entries after a particular date (eg Jan 1st) I have this: // get data from events_pbw table $result = mysql_query("SELECT id, date, name FROM events_pbw WHERE `date` > 2011-01-01" "); while($row = mysql_fetch_array($result)) { $appid = $row['id']; $date = $row['date']; $name = $row['name']; } But I don't know how to get the full list of results into the pdf. I'm sure this is very easy but I'm not great on php coding! Does anyone have any examples or help they could give me? Many thanks Hi all, I have a MySQL table with the field 'number'. When I SELECT * from that field, I get a return for the rows of 'number' in the order 1, 2, 3, 4, etc... SELECT * FROM products;Is there a way where I can get a return in the reverse order, so highest to lowest (4, 3, 2, 1, etc...)? Edited by Phaelon, 13 May 2014 - 03:23 AM. Hi there im not quite sure how to do something and was wondering if anyone can help me, I am going to create a large database with lots of fields and these are going to be displayed on a page i want to limit it to 20 per page and be able to sort them aswell by ID (default) and then a-z or z-a, i dont know how to do this and i also need to know how to create the next previous and last and first links im guessing theres a count++ involved ? im not quite sure but anyway if someone can help it will be great. Thanks, Blink359 Hello Php Freaks! I have decided to create a website and got exactly how i want it in my head, but the problem is.... i can't really program any php, so i've been reading different tutorials for every bit of those things i need for my site.... Still its very hard.... So i were wondering if anyone could give me some help? A tutorial, or help me with the errors i encounter and so on. Here is what i plan on getting: (The site will be for a guild in a game) 1. Login 2. News 3. Some sort of photo/video archieve 4. Rankings 5. Profile pages (With name, age, character name and so on). 6. Medals (Hooked up with Rankings mostly). 7. Private messages 8. Application site 9. calender And thats it, its quite alot of work... But i believe that if i read though alot of tutorials i miiight get it all done one day... But first i guess i gotta learn how to set up a site so it looks good xD!... - Seems like im a lost cause, anyways... anybody who got any kind of help ?... Would be soo appriciated. Quick question about the dependency manager Composer with PHP. I have it installed and am pulling in a few libraries, it works pretty well as far as I can tell. I have a question that might be dumb, so I apologize in advance. When connecting to your application it's still required to use the lines similar to the following? <script src="vendor/components/jquery/jquery.min.js"></script> <link rel="stylesheet" href="vendor/twbs/bootstrap/dist/css/bootstrap.css" > Also I'm trying to figure out how to install the x3dom library, but cannot get composer to do it. (https://www.x3dom.org/) I read the conditions for hosting at PHP Fog, and they state that I can't use session variables as such variables are not copied between servers. Therefore I changed session variables for login info, language selection etc to cookies. Hence my own code is now free from session varibables, but Zend that I use for e.g. OAuth is not. Is it typical that cloud hosting providers disallow session variables for the above reason, or are there others that can handle such replication between servers? If not, is work going on to remove use of session variables from popular frameworks? Cheers, Anders Hi I have the following code, this code is suppose to get the data from the galleries table and the pages table. I think my problem is the sql statement but I'm not sure. Code: [Select] public function galleries(){ foreach($this->_params['list'] as $gallery){ $id = $gallery['id']; $name = $gallery['name']; $select = "SELECT * FROM pages, galleries WHERE pages.name = {$gallery['name']}"; $this->_params['item'] = $this->_model->get(array("pages.name = 'galleries.name'")); } the code Code: [Select] $this->_params['item'] = $this->_model->get(array("pages.name = 'galleries.name'")); works just fine with the home page and all the other pages. I have 2 galleries called gallery 1 and gallery 2, now my problem is that I need the sql to go through the galleries table look for the name and then look through the pages table and get the meta data from the same name. There is no foreign id because I only need it for the galleries and nothing else. Thank you I set up the following code to successfully individual items based on the id number. ?id=1 etc. However, I thought it would be simple to change to show another row so I changed all the terms to 'description'. However, if I enter ?description=abcde it shows nothing. But if I type in ?description=description is bizarrely shows everything. The only thing I can only put it down to is numbers. Does $_GET react differently react differently to numbers or does it require commas surrounding the string? <?php if( isset($_GET['description'])) $_GET['description']; $query = "SELECT * FROM productfeed WHERE description = $description LIMIT 0, 10"; $fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>'); while($row = mysql_fetch_array($fetchdata)) { $id = $row['id']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; echo "<div class='productdisplayshell'> <div class='productdisplayoutline'> <div class='productborder'><center> <a href='$link' target='_blank'><img src='$image'/></a> </center> </div></div> <div class='productdescriptionoutline'> <div class='productdescriptionbox'> <a href='$link' target='_blank' >$description</a> </div> <div class='productfulldescriptionbox'>$fulldescription</div> </div> <div class='productpriceoutline'> <div class='productpricebox'> <center>&#163; $price</center> </div> <div class='productbuybutton'> <center><a href='$link' target='_blank' ><img src=/images/buybutton.png /></a></center> </div> </div> </div>"; } ?> so i set names for every pages, like $pageName = 'home'; //index page Code: [Select] if($pageName == 'categories'){ $find = "Birds & Bees"; $result = strpos($title,$find); echo '1'; }else if($pageName == 'categories'){ $find1 = "Money & Honey"; $result = strpos($title,$find1); echo '2'; } now the issue is with categories.php page, which is just one page but displays different title and according to matching title i wish to change the description but its not happening, everywhere only 1 prints, why? Hi I am trying to pull title and meta description from an URL.. To pull the URL I am using the code from http://www.dreamincode.net/code/snippet4625.htm... function getTitle($Url){ $str = file_get_contents($Url); if(strlen($str)>0){ preg_match("/\<title\>(.*)\<\/title\>/",$str,$title); return $title[1]; } } //Example: echo getTitle("http://www.cnn.com"); And to pull the meta description I am using the code from http://php.net/manual/en/function.get-meta-tags.php. // Assuming the above tags are at www.example.com $tags = get_meta_tags('http://www.cnn.com/') or die("Could not fetch meta tags"); // Notice how the keys are all lowercase now, and // how . was replaced by _ in the key. echo $tags['author']; // name echo $tags['keywords']; // php documentation echo $tags['description']; // a php manual echo $tags['geo_position']; // 49.33;-86.59 So my complete code looks like this: <html> <head> </head> <body> <?php function getTitle($Url){ $str = file_get_contents($Url); if(strlen($str)>0){ preg_match("/\<title\>(.*)\<\/title\>/",$str,$title); return $title[1]; } } //Example: echo getTitle("http://www.cnn.com"); // Assuming the above tags are at www.example.com $tags = get_meta_tags('http://www.cnn.com/') or die("Could not fetch meta tags"); // Notice how the keys are all lowercase now, and // how . was replaced by _ in the key. echo $tags['author']; // name echo $tags['keywords']; // php documentation echo $tags['description']; // a php manual echo $tags['geo_position']; // 49.33;-86.59 ?> Test! </body> </html> But it wont work... All I get is "Could not fetch meta tags".. I've tried different URLs and such but still wont work .. Anyone have an idea? Hi, I've been passed the below code which converts rss to php and then displays HTML. It works well. However, I've 2 issues with it: 1) I'd like to set it so only say 5 posts are shown 2) How can I truncate the description, so it only shows say 100 chars or 20 words? Any help is much appreciated. Here's the code: <?php // DO NOT EDIT BELOW THIS LINE date_default_timezone_set("GMT"); $itemArray = array(); if($text = preg_replace("/[\t\r\n]/", " ", htmlentities(@file_get_contents($rss_feed_url), ENT_QUOTES))) { while(strpos($text, "â") == true) { $text = substr($text, 0, strpos($text, "â")) ."'". substr($text, strpos($text, "â")+9, strlen($text)); } $items = explode("<item>", html_entity_decode($text)); foreach($items as $item) { $title = ""; $link = ""; $desc = ""; $pubdate = ""; $image = ""; $item = html_entity_decode($item, ENT_QUOTES); $item = preg_replace('/&(?!amp;|quot;|nbsp;|gt;|lt;|laquo;|raquo;|copy;|reg;|bul;|rsquo;|mdash;|#)/', '&', $item); $item = str_replace("<![CDATA[","", $item); $item = str_replace("]]>","", $item); if(stripos($item, "</item>") == true) { if(preg_match('|<title>(.*)</title>|', $item, $match)) { $title = $match[1]; } if(preg_match('|<pubDate>(.*)</pubDate>|', $item, $match)) { $pubdate = strtotime($match[1]); } if(preg_match('|url="(.*)|', $item, $match)) { $search = $match[1]; $imageArray = explode('"', $search); $image = $imageArray[0]; } if(preg_match('|<description>(.*)</description>|', $item, $match)) { $desc = $match[1]; $desc = strip_tags($desc); } if(preg_match('|<link>(.*)</link>|', $item, $match)) { $link = $match[1]; $link = end(explode("*", $link)); } if($title && $link && $desc) { array_push($itemArray, "$pubdate|$title|$link|$desc|$image|"); } } } } else { print "<p>Whoops! We could not connect to: <a href=\"$rss_feed_url\">$rss_feed_url</a></p>"; } if(sort($itemArray)) { foreach(array_reverse($itemArray) as $iA) { list($pubdate,$title,$link,$desc,$image) = explode("|", $iA); $timenow = time(); $difference = $timenow-$pubdate; $days = 0; $hours = 0; $minutes = 0; print "<p>"; if($hotlink_images && $image) { if($open_links_in_new_window) { print "<a class=\"thumb\" href=\"$link\" onclick=\"openInNewWindow('$link'); return false\">" . "<img src=\"$image\" alt=\"$title\"></a>"; } else { print "<a class=\"thumb\" href=\"$link\"><img src=\"$image\" alt=\"$title\"></a>"; } } if($open_links_in_new_window) { print "<a href=\"$link\" onclick=\"openInNewWindow('$link'); return false\">$title</a><br>"; } else { print "<a href=\"$link\">$title</a><br>"; } if($pubdate) { print "<span class=\"sub\">Posted "; if(sprintf("%01.0d", $difference/(60*60*24))) { $days = sprintf("%01.0d", $difference/(60*60*24)); $difference -= $days*(60*60*24); if($days > 1) { print "$days days "; } else { print "$days day "; } } if(!(sprintf("%01.0d", $difference/(60*60*24))) && sprintf("%01.0d", $difference/(60*60))) { $hours = sprintf("%01.0d", $difference/(60*60)); $difference -= $hours*(60*60); if($hours > 1) { print "$hours hours "; } else { print "$hours hour "; } } if(!(sprintf("%01.0d", $difference/(60*60*24))) && sprintf("%01.0d", $difference/60)) { $minutes = sprintf("%01.0d", $difference/60); if($minutes > 1) { print "$minutes minutes "; } else { print "$minutes minute "; } } print "ago</span><br>"; } print "$desc</p>\n<div class=\"hr\"> </div>\n"; } } ?> Thanks again I have a website here [redacted] and it is an affiliate website where I just find products and promote them. All I have to do is give product a title, affiliate url, the description, an image and a price. I am trying to make the product description area hold more text than it does now, because at the moment in the admin side of my website it says "product description 275 max characters" That is really a short sentence. Can anyone please help me I have no php skills but really wish I did, if you need more info I will be happy to share anything I need to. Edited October 27, 2019 by requinixremoved link G'day all, i've got this script that I found on the net some time back but not entirely sure where, however it works well except I want to add a feature so it shows the image details from a txt file. Here is the gallery script: <?php function getDirectory( $path = '.', $level = 0 ){ $ignore = array( 'cgi-bin', '.', '..' ); $dh = @opendir( $path ); while( false !== ( $file = readdir( $dh ) ) ){ if( !in_array( $file, $ignore ) ){ if( is_dir( "$path/$file" ) ){ $dir = $path . $file; echo "<h2>$file</h2><p>"; $dh1 = @opendir( $dir ); while( false !== ( $image = readdir( $dh1 ) ) ){ if( !in_array( $image, $ignore ) ){ if( !is_dir( "$dir/$image" ) ){ if (preg_match("/.jpg/", $image)) { echo "<a href=\"$dir/$image\" rel=\"lightbox\"><img src=\"gallery-thumbnail.php?file=$file/$image\" border=2 style='border-color: #981C1E'></a>\n"; } } } } echo "</p>"; $level++; } } } closedir( $dh ); } getDirectory('gallery/'); ?> Now, what i'm wanting is to read a txt file either in the root or 'gallery' directory, where it has the file name, title, description, photographer. (something like filename.jpg|title of image|description about image|J King). so when the image is displayed, a script reads the text file and will show the image info beside it. Now i've got this bit of snippet from an old script I used once, but can't seem to get it to work anywhere, so any help is greatly appreciated. $text = "gallery.txt"; $fh=fopen($text, "r"); while(!feof($fh)) { $temp = explode("|", $line); $title[$temp[0]] = $temp[1]; $description[$temp[0]] = $temp[2]; $photographer[$temp[0]] = $temp[3]; $line=fgets($fh); unset($temp); } On the index page of http://www.sportskevesti.co i have the meta tags of Title, Description, Keyword.... and other element, but it is necessary to show them in name of the other pages, socer, basketbal, handbal, tennis...., and there fore news spetial. in this moment, i have this meta tag double. for example: www.sportskevesti.co/index.php Quote <meta name="title" content="Sportske Vesti"> <meta name="description" content="Najnovije sportske vesti iz Srbije i ostatka sveta. Sve na jednom mestu."> <meta name="keywords" content="sport, vesti, fudbal, tenis, kosarka, odbojka, rukomet, auto, moto, trke"> http://sportskevesti.co/index.php?opcija=vest&vest_id=60067 Quote <meta name="title" content="Sportske Vesti"> <meta name="description" content="Najnovije sportske vesti iz Srbije i ostatka sveta. Sve na jednom mestu."> <meta name="keywords" content="sport, vesti, fudbal, tenis, kosarka, odbojka, rukomet, auto, moto, trke"> <meta name="title" content="Danas je derbi!" /> <meta name="description" content="Na stadionu Crvene zvezde danas se igra ..." /> <meta name="keywords" content="danas, derbi, "/> Since I assume that this is not good for SEO optimization, how to avoid this and show only one meta per page ? |