PHP - Need To Turn Result Into Link..
I've tried to find an answer in the forum and although there have been posts similar I am unable to covert the answer to fit what I've got (mostly because I know very very little about php - sorry).
What I need is one of the results to be added to the end of a url in order to create a link. Basically I have a storefront (www.storefront.com/) and the result NAME can be added onto the end of our url to create a link to the product page. (www.storefront.com/NAME) Code: [Select] <?php $dbhost = ""; $dbuser = ""; $dbpass = ""; $dbname = ""; //Connect to MySQL Server mysql_connect($dbhost, $dbuser, $dbpass); //Select Database mysql_select_db($dbname) or die(mysql_error()); // Retrieve data from Query String $price = $_GET['price']; $taxable = $_GET['taxable']; $weight = $_GET['weight']; // Escape User Input to help prevent SQL Injection $age = mysql_real_escape_string($price); $sex = mysql_real_escape_string($taxable); $wpm = mysql_real_escape_string($weight); //build query $query = "SELECT * FROM Products WHERE taxable = '$taxable'"; if(is_numeric($price)) $query .= " AND price <= $price"; if(is_numeric($weight)) $query .= " AND weight <= $weight"; //Execute query $qry_result = mysql_query($query) or die(mysql_error()); //Build Result String $display_string = "<table>"; $display_string .= "<tr>"; $display_string .= "<th>Name</th>"; $display_string .= "<th>Price</th>"; $display_string .= "<th>Taxable</th>"; $display_string .= "<th>Weight</th>"; $display_string .= "</tr>"; // Insert a new row in the table for each person returned while($row = mysql_fetch_array($qry_result)){ $display_string .= "<tr>"; $display_string .= "<td>'<a href="www.storefront.com/">' . $row[name] . ' </a>'/td>"; $display_string .= "<td>$row[price]</td>"; $display_string .= "<td>$row[taxable]</td>"; $display_string .= "<td>$row[weight]</td>"; $display_string .= "</tr>"; } echo "Query: " . $query . "<br />"; $display_string .= "</table>"; echo $display_string; ?> I know the way it is setup in the code is wrong. Can anyone help me out? Would really appreciate it. Thanks - and again, sorry for my lack of php knowledge. Similar TutorialsHello Everyone, I have a quick question for you all, I think its fairly simple... I have created a database and I am using PHP to grab the data: $usera = $_SESSION['username']; $query2 = "SELECT * FROM tracker WHERE id = '$usera', hidden = yes"; mysql_query($query2) or die('Error, query failed : ' . mysql_error()); This hopefully will return multiple rows which look like this in the database. id username date reps hidden 1 supremebeing 2011-01-02 30 yes 4 supremebeing 2011-04-02 46 yes How would i turn each result into a variable eg: $date1 = 2011-01-02; $date2 = 2011-04-02; $reps1 = 30; $reps2 = 46; I think i have explained that well enough for you to understand, please reply if not though and i will provide more information. Thanks in Advance This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=320284.0 How can I add a link when my query result is >= 6 ? Do I have to use mysql_num_rows? Could anyone please help about making a search result with links. To be specific, I have a list of names in my database. I want to create a search that will list names with links. Its been 5 hours and cant still figure out how it goes. Thank you I'm trying to add a link to edit my results. Not sure the best way to create the link, nothing I've tried works. There's probably a better way than what I've tried: echo 'There were ', mysql_num_rows($result), ' Matching Photographers:'; while ($row = mysql_fetch_array($result)) { echo "<br />Photographer Info:<br />"; echo "Photographer Name: $row[name]<br />"; echo "Photographer Email: $row[email]<br />"; echo "Photographer ID: $row[PHOTOGRAPHERID]<br />"; echo "Photographer Company: $row[c_name]<br />"; echo "Edit Photographer <a href="update.php?id=' . $row[PHOTOGRAPHERID] . '">Here</a>"; } Hi Everyone. I get the following data from a result from database search <?php echo $rsjobs['CompanyURL'];?> It prints out the url but when I try to turn it into a clickable link it does not work Here is the coding I have so far. <a href="<?php echo $rsjobs['CompanyURL'];?>"><?php echo $rsjobs['CompanyURL'];?></a> What am I doing wrong ? please help. Hello. I am working on a php script for searching a database table. I am really new to this, so I used the this tutorial http://www.phpfreaks.com/tutorial/simple-sql-search I managed to get all the things working the way I wanted, except one important and crucial thing. Let me explain. My table consist of three columns, like this: ID(bigint20) title(text) link (varchar255) ============================= ID1 title1 link-1 ID2 title2 link-2 etc... Like I said, I managed to make the script display results for a search query based on the title. Want I want it to do more, but I can't seem to find the right resource to learn how, is to place a "Download" button under each search result with its corresponding link from the table. Here is the code I used. <?php $dbHost = 'localhost'; // localhost will be used in most cases // set these to your mysql database username and password. $dbUser = 'user'; $dbPass = 'pass'; $dbDatabase = 'db'; // the database you put the table into. $con = mysql_connect($dbHost, $dbUser, $dbPass) or trigger_error("Failed to connect to MySQL Server. Error: " . mysql_error()); mysql_select_db($dbDatabase) or trigger_error("Failed to connect to database {$dbDatabase}. Error: " . mysql_error()); // Set up our error check and result check array $error = array(); $results = array(); // First check if a form was submitted. // Since this is a search we will use $_GET if (isset($_GET['search'])) { $searchTerms = trim($_GET['search']); $searchTerms = strip_tags($searchTerms); // remove any html/javascript. if (strlen($searchTerms) < 3) { $error[] = "Search terms must be longer than 3 characters."; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } // If there are no errors, lets get the search going. if (count($error) < 1) { $searchSQL = "SELECT title, link FROM db WHERE title LIKE '%{$searchTermDB}%'"; $searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); if (mysql_num_rows($searchResult) < 1) { $error[] = "The search term provided {$searchTerms} yielded no results."; }else { $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$row['title']}<br /> Download - this is the button I want to link to the title results - and maybe other links too - <br /> "; $i++; } } } } function removeEmpty($var) { return (!empty($var)); } ?> <?php echo (count($error) > 0)?"The following had errors:<br /><span id=\"error\">" . implode("<br />", $error) . "</span><br /><br />":""; ?> <form method="GET" action="search?" name="searchForm"> Search for title: <input type="text" name="search" value="<?php echo isset($searchTerms)?htmlspecialchars($searchTerms):''; ?>" /> <input type="submit" name="submit" value="Search" /> </form> <?php echo (count($results) > 0)?"Rezultate lucrari de licenta sau disertatie pentru {$searchTerms} :<br /><br />" . implode("", $results):""; ?> $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$row['title']}<br /> Download - this is the button I want to link to the title results - and maybe other links too - <br /> "; $i++; I would like the results to be displayed like this Results for SearchItem: Result 1 Download | Other link Result 2 Download | Other link etc.... or something like this. So, how do I add the data from the link row into a text(Dowload), within an <a href> tag (well, at least I guess it would go this way) ? My first tries (fueled by my lack of knowledge) where things like $results[] = "{$row['title']}<br /> <a href="{$row['link']}">Download</a> <br /> "; but I keep getting lots of errors, and then I don't know much about arrays and stuff (except basic notions); So there it is. I am really stuck and can't seem to find any workaround for this. Any suggestions? (examples, documentation, anything would do, really) Thanks, Radu I am really lost here with this date issue of mine. The below code is the last part of a query: Code: [Select] $defendercheck_3 = $row_checkifattacked3['atdate']; $defendercheck1_3 = strtotime("$defendercheck_3"); $defendercheck2_3 = date("D", $defendercheck1_3); The query does not return any results as expected, but when echoing the various steps I get following: echo "$defendercheck3"; = nothing (as expected) echo "$defendercheck1_3"; = nothing (as expected) echo "$defendercheck2_3"; = result! (NOT expected) why does it return anything on "date("D", $defendercheck1_3)" when "$defendercheck1_3" is blank? Hi. I have made profile pages available for users.. How do I turn off <?php ?> for those pages? I would like javascript enabled however. All suggestions are welcome!! Thanks How to turn off notices in PHP 5.3. Is it possible to turn it off in php.ini? Hi. I have a problem with output buffering. I'm using wamp. I've tried setting the php.ini file to output_buffering = 0 and off I've tried using flush() and ob_flush(), separetly and together. I've tried turning on implicit_flush. Nothing works. Any ideas? I'm using the flowing code to test right now: Code: [Select] echo 'starting...<br/>'; for($i = 0; $i < 5; $i++) { print "$i<br/>"; flush(); sleep(2); } print 'DONE!<br/>'; Hi, How would I do this, I'm trying to create a function to turn the octal (not sure whats its called exactly) input into its numberic representation, like so: <?php function octal_to_number($input) { //do something... return $number; } //would turn 0x17c into 380... echo octal_to_number('0x17c'); ?> i have apache 2.2 and php 5.0 installed on my pc, i have a html page and i need to turn it into php and also i need to include a header and a footer, i tryed doing it but the webpage won't display, what am i doing wrong? here is my page which i tryed turning into php <!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" xml:lang="en" lang="en"> <!--index.html is basically an introductory page to this website, this page introduce us to this website. This page tell us, this page is called index.html because that's the name of the first page on any website, this page tell us wat type of website this is, name of this website, name of the person(in this case that's me) who made it, a light description of what type of contents we will find inside this website etc. This page tell us the name of this lab assignment which is " --> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>INTN2201 - Lab 1</title><!--title of this page --> <link href="./css/intn2201.css" rel="stylesheet" type="text/css" /></head> <body> <table border="1" > <tr> <td class="navmenu"><img src="images/my_logo.jpg" alt="My Logo" /></td> <td class="page_header"><h1>INTN 2201: Lab Assignment 1: HTML Pages</h1></td> </tr> <tr> <td valign="top"> <a href="index.html" >MY HOME PAGE</a> <br /> <a href="lab1.html" >LAB 1:HTML Intro</a> <br /> <a href="lab2.html" >LAB 2:HTML Tables</a> <br /> <a href="lab3.html" >LAB 3:CSS Styles</a> </td> <td class="main_body"><h2> Purpose of this website</h2> <p class="p1"> This website was created for first lab assignment of <a href="http://opentech.durhamcollege.ca/~pufferd/intn2201">INTN2201</a>, <a href="http://opentech.durhamcollege.ca/~pufferd/intn2201">INTN2201</a> is the course code for "INTERNET DEVELOPMENT I" course, at <a href="http://www.durhamcollege.ca">Durham College</a> every first year student<br/> of Computer System Technology program(3 years) have to take this course, main purpose of this site is to get a first feel for creating a basic html website<br/> but also to get a feel of how to use it in website creation, during the creation of this page i get to know programs like notepad++,<br/> WINSCP, learned how to login to course webserver(opentech.durhamcollege.ca), another purpose for this site is to test webpage creator's( in this case that's me)<br/> knowledle about HTML tags, XHTML, W3C validator, HTML stands for Hyper Text,it is not a programming language it is a Markup Language,<br/> I(creater of this website) wanted to learn about differen't html tags and one of the best ways to learn about html tags is to try create<br/> a html webpage. </p> <hr/> <h2>ol { margin-left : 200px; } </h2> <p class="p2"> in this style tag i used Margine properties to define a list in lab2.html, bottom of the page u will see lists, so margine basically sets all the margin properties in one declaration.</p> <hr/> <a href="http://www.durhamcollege.ca/"> <img width="300" src="images/durham_college_logo.jpg" alt="My Logo" /></a> <hr/> </td> </tr> <tr> <td class="navmenu" colspan="2" align="right"> ©2011 <p> <a href="http://validator.w3.org/check?uri=referer"> <img style="width:88px; height:31px; position:fixed; bottom: 81px; left:50px;" src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Transitional" /> </a> </p> <p> <a href="http://jigsaw.w3.org/css-validator/check/referer"> <img style="width:88px; height:31px; position:fixed; bottom: 45px; left:50px; " src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" /> </a> </p></td> </tr> </table> </body> </html> how do i turn this into php page and what goes in the header and footer? How do I turn a checkbox on or off programatically? My form has several checkboxes that are grouped together and I want them to be turned on initially when the user first sees the form.I can do that very easily by just including "checked" in the HTML for the checkbox. But if the user turns off the checkbox before he presses Submit, I want to make sure I show the ones that are off as off when I redisplay the form as a result of errors in other fields, like textareas. How do I turn the checkbox off or on within my PHP code? Edited June 9, 2019 by HenryCanHello All, I'm trying to put a lot of what I do into function calls now to make my code a bit tidier and consise. Take this simple if statement: if ($_GET['thedate'] =='') { $var = date('l, jS F, Y',time()); } else { $var = date('l, jS F, Y', strtotime($_GET['thedate'])); } How could I put this into a function and in some kind of switch statement? Thanks I've tried to use this http://www.bambalam.se/bamcompile/ .. but I cant get curl to work using the option to set the extension.. I need it to be able to sign into myspace or facebook with curl when it is in an exe.. everything else works fine with bambalam, everything but curl and connecting to an mysql db, I dont need to have mysql support, only curl.. what would be the easiest way to make this happen? btw the exe should just open a CLI and run the script, thanks Say I have a chunk of code that looks like this (contains imagesx): Code: [Select] <span style="color: #0000BB">$width </span><span style="color: #007700">= </span><span style="color: #0000BB">imagesx</span><span style="color: #007700">(</span><span style="color: #0000BB">$img</span><span style="color: #007700">); <br /> within the code I would like to make all the php functions link to php.net I thought that the following code would work, but it does not, well because there is no spaces around the above word public function phpLinks($string){ $words = explode(" ", $string); $str = array(); foreach($words as $word){ if(function_exists($word)){ $str[] = preg_replace("/$word/i", '<a href="//php.net/'.strtolower($word).'">'.$word.'</a>', $word); }else{ $str[] = $word; } } return implode(" ", $str); } I now can not think of a good way to do this, so I am asking does anyone have any suggestions? I think my eyes are going to fall out from all the searches ive made to find a solution for this that works on a shared host.
I tried this... but it doesnt work.
RewriteEngine on CheckSpelling onThe only Rough solution i got is to do the case manually with an internal redirect. Like this. RewriteEngine on RewriteBase /~quux/ RewriteRule ^foo\.html$ bar.htmlIs there absolutely no way to mention [a-z] and [A-Z] into a RewriteRule to get this done? I find it terribly stupid from Apache not to provide a simple solution for this. hello i keep seeing Ternary Operators like this Code: [Select] $action = (empty($_POST['action'])) ? 'default' : $_POST['action']; but how would i turn this if statement in to a Ternary Operator ? Code: [Select] if($a == $b){ echo 'hello'; }else{ //do nothing } thanks Hey guys, I am having a problem with making a system where it is turn based attacks. I want it so a user can attack a monster and the monster can attack back, the output I want is like. Code: [Select] You hit the monster for 5. The monster hit you for 7. You hit the monster for 3. The monster hit you for 6. and so on. I have been going at this for ages and cannot get what I want. I had problems such as: The monster attacking when it should be dead. Even when the monster was dead the user would still attack. This is the code I have now that is maybe totaly wrong, thats why I need your guys help! Code: [Select] $monster_hp = 10; $userhp =10; for ($i=1,$n=1; $i<=$monster_hp, $n<=$userhp; $n+=$damtaken, $i+=$damdone){ $damtaken = 1*rand(1,3) + rand(1,4) + 1 + 1; $damdone = 1*rand(1,2) + rand(1,2) + 1 + 1; echo "You hit the monster for $damdone.<br />"; echo "The monster hit you for $damtaken. <br />"; } The output for that is: Code: [Select] You hit the monster for 5. The monster hit you for 7. You hit the monster for 5. The monster hit you for 5. That is wrong due to the monster having 10 hp and I have hit him for 10hp overall. I know that thats because the echo is in the loop so it has to run but I have tried so many ways to get this to work and cannot do it. If I die, it should stop with the monsters attack and a message saying "The monster has killed you", if I win it should stop his next attack and say "You have killed the monster". Please help me guys, you have helped me before so I know how good some of you are. Thank you so much for anyhelp that is givin. Ruddy. |