PHP - How To Make A Image A Link When It Is Outputted Using Php?
I basically have a PHP Search Form, and when a user fills in a form it outputs the results. Each result displays a image of a property, how could i make them images have their own unique link which will take them directly to the page of the property being shown?
Im using PHP and mySQL tables Any help is appreciated, Thank You. Heres the PHP that outputs the results: Code: [Select] <?php require_once 'mstr_ref.php'; function san($input){ if(get_magic_quotes_gpc()){ $input=stripcslashes($input); } $output = mysql_real_escape_string($input); return $output; } if(isset($_POST['submit'])){ $pVars = array('area'=>$_POST['areas'], 'propType'=>$_POST['prop_type'], 'saleType'=>$_POST['ptype'], 'minB'=>$_POST['min_bedrooms'], 'maxB'=>$_POST['max_bedrooms'], 'minP'=>$_POST['min_price'], 'maxP'=>$_POST['max_price']); foreach ($pVars as $k=>$v){ $v = san($v); } $sql = new makeQuery(); $sql->manAdd('location_id', $pVars['area']); if($pVars['propType'] != 'Any'){ $sql->manAdd('catagory_id', $pVars['propType']); } if ($pVars['maxB'] > 0){ $sql->manAdd('bedrooms', $pVars['maxB'], '<='); } if($pVars['minB'] > 0){ $sql->manAdd('bedrooms',$pVars['minB'],'>='); } if($pVars['saleType'] != 'Any'){ if($pVars['saleType'] == "forsale"){ $sql->manAdd('market_type', 'sale'); if($pVars['minP'] != 0){ $pVars['minP'] = $pVars['minP'] * 1000; } if($pVars['maxP'] != 0){ $pVars['maxP'] = $pVars['maxP'] * 1000; } } if($pVars['saleType'] == 'forrent'){ $sql->manAdd('market_type', 'rent'); } } $qry = $sql->sqlStart.$sql->stmt.'Group By property.id'; $results = mysql_query($qry) or die (mysql_error()."<br />|-|-|-|-|-|-|-|-|-|-|-|-<br />$qry"); if(mysql_num_rows($results) < 1){ die ("Sorry, No Results Match Your Search."); } while($row = mysql_fetch_assoc($results)){ echo '<div class="container" style="float:left;">'; echo '<div class="imageholder" style="float:left;">'; echo "<img class='image1' src='{$row['image_path']}' alt='{$row['summary']}'> <br />"; echo '</div>'; echo '<div class="textholder" style="font-family:helvetica; font-size:14px; float:left; padding-top:10px;">'; echo "{$row['summary']}"; echo "<span style=\"color:#63be21;\"><br><br><b>{$row['bedrooms']} bedroom(s) {$row['bathrooms']} bathroom(s) {$row['receptions']} reception room(s)</b></span>"; if($row['parking'] != null){ echo "<span style=\"color:#63be21;\"><b> {$row['parking']} parking space(s)</b></span>"; } echo '</div>'; echo '<div style="clear:both"></div>'; } } else{ echo "There was a problem, please click<a href='index.php'> Here </a>to return to the main page and try again"; } ?> Similar TutorialsHi, When the user creates a contact, then edits the contact that final edited information is shown in a file called "my data.txt". After this, when I select my php file "save_contact_details.php" the details stored in the text file "my data.txt" are not retrieved. How can I retrieve them? At the moment the issue I'm having is that I see no data when I click on "save_contact_details.php" after I filled in all the contact persons information. Feel free to watch this video I recorded to help you understand what I am talking about. https://streamable.com/rbw6p save_contact_details.php code <html> <body> <?php $myFile=fopen("mydata.txt","r") or exit("Can’t open file!"); // Write each line of text into the text file file fwrite($myFile, $_POST["lastname"]."\r\n"); fwrite($myFile, $_POST["firstname"]."\r\n"); fwrite($myFile, $_POST["address01"]."\r\n"); fwrite($myFile, $_POST["address02"]."\r\n"); fwrite($myFile, $_POST["town"]."\r\n"); fwrite($myFile, $_POST["postcode"]."\r\n"); fwrite($myFile, $_POST["telephone"]."\r\n"); fwrite($myFile, $_POST["email"]."\r\n"); fclose($myFile); ?> <h1>My Contact Details</h1> <p>The contact details that you have submitted are shown below:</p> <table> <tr> <td align="right">Last name: </td> <td><?php echo $_POST["lastname"]; ?></td> </tr> <tr> <td align="right">First name: </td> <td><?php echo $_POST["firstname"]; ?></td> </tr> <tr> <td align="right">Address 01: </td> <td><?php echo $_POST["address01"]; ?></td> </tr> <tr> <td align="right">Address 02: </td> <td><?php echo $_POST["address02"]; ?></td> </tr> <tr> <td align="right">Town / city: </td> <td><?php echo $_POST["town"]; ?></td> </tr> <tr> <td align="right">Post code: </td> <td><?php echo $_POST["postcode"]; ?></td> </tr> <tr> <td align="right">Telephone: </td> <td><?php echo $_POST["telephone"]; ?></td> </tr> <tr> <td align="right">E-mail: </td> <td><?php echo $_POST["email"]; ?></td> </tr> </table> </body> </html>
<html> <body> <?php $myFile=fopen("mydata.txt","r") or exit("Can’t open file!"); // read each line of text from the text file $lastname = fgets($myFile); $firstname = fgets($myFile); $address01 = fgets($myFile); $address02 = fgets($myFile); $town = fgets($myFile); $postcode = fgets($myFile); $telephone = fgets($myFile); $email = fgets($myFile); fclose($myFile); ?> <h1>My Contact Details</h1> <p> The contact details on file are as shown below.<br> Edit the data and save your changes to file. </p> <form action="save_contact_details.php" method="post"> <table> <tr> <td align="right">Last name: </td><td> <?php echo "<input size=\"20\" type=\"text\" name=\"lastname\" value=\"$lastname\">"?> </td> </tr> <tr> <td align="right">First name: </td><td> <?php echo "<input size=\"20\" type=\"text\" name=\"firstname\" value=\"$firstname\">"?> </tr> <tr> <td align="right">Address 01: </td><td> <?php echo "<input size=\"30\" type=\"text\" name=\"address01\" value=\"$address01\">"?> </td> </tr> <tr> <td align="right">Address 02: </td><td> <?php echo "<input size=\"30\" type=\"text\" name=\"address02\" value=\"$address02\">"?> </td> </tr> <tr> <td align="right">Town / city: </td><td> <?php echo "<input size=\"20\" type=\"text\" name=\"town\" value=\"$town\">"?> </td> </tr> <tr> <td align="right">Post code: </td><td> <?php echo "<input size=\"10\" type=\"text\" name=\"postcode\" value=\"$postcode\">"?> </td> </tr> <tr> <td align="right">Telephone: </td><td> <?php echo "<input size=\"15\" type=\"text\" name=\"telephone\" value=\"$telephone\">"?> </td> </tr> <tr> <td align="right">E-mail: </td><td> <?php echo "<input size=\"50\" type=\"text\" name=\"email\" value=\"$email\">"?> </td> </tr> <tr> <td> </td> <td colspan="2" align="left"><input type="submit" value="Save Changes"></td> </tr> </table> </form> </body> </html> create contact html code <html> <body> <h1>The contact details</h1> <p>Please enter your contact details:</p> <form action="save_contact_details.php" method="post"> <table> <tr> <td align="right">First name: </td> <td><input size="20" type="text" maxlength="15" name="firstname"></td> </tr> <tr> <td align="right">Last name: </td> <td><input size="20" type="text" maxlength="15" name="lastname"></td> </tr> <tr> <td align="right">Address line 1: </td> <td><input size="30" type="text" maxlength="50" name="address01"></td> </tr> <tr> <td align="right">Address line 2: </td> <td><input size="30" type="text" maxlength="50" name="address02"></td> </tr> <tr> <td align="right">Town / city: </td> <td><input size="20" type="text" maxlength="20" name="town"></td> </tr> <tr> <td align="right">Post code: </td> <td><input size="10" type="text" maxlength="10" name="postcode"></td> </tr> <tr> <td align="right">Telephone: </td> <td><input size="15" type="text" size="20" maxlength="15" name="telephone"></td> </tr> <tr> <td align="right">E-mail: </td> <td><input size="50" type="text" maxlength="50" name="email"></td> </tr> <tr> <td> </td> <td colspan="2" align="left"><input type="submit" value="Submit"></td> </tr> </table> </form> </body> </html>
Im inserting HTML into a database, and then outputting it on a PHP page. Its an iframe code, so when I output it, it shows the iframe. I need it to just display the HTML code. How can I do this? I thought it would be something simple but I can find anyway to do it. Help very appreciated!! Thanks Hi I've got this database I created with fields ProductId ProductName Image I've managed to get it to list the ID,productname, and Image urls in a list. My next step is to have the image field actually display an image and make it clickable: heres what I've done so far: Code: [Select] <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("productfeed", $con); $result = mysql_query("SELECT * FROM productfeeds"); echo "<table border='0'> <tr> <th>Firstname</th> <th>Lastname</th> <th>Image</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['ProductID'] . "</td>"; echo "<td>" . $row['ProductName'] . "</td>"; echo "<td>" . $row['ImageURL'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Heres what I want to do: Code: [Select] while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['ProductID'] . "</td>"; echo "<td>" . $row['ProductName'] . "</td>"; // my changes beneath echo "<td>" . <a href="<?php echo $row['ImageURL'];?>"> <img src="<?php echo $row['LinkURL']; ?>"> </a>. "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Can you guys point me in the right direction? Many thanks Hey, What i want is that if a username inserts some text into a field like "Hey @martin how are ya" ? then it will display @martin as a link that takes you to site.com/martin, i searched php.net from preg_replace and str_replace...unfortunately for me things got so complicated that i don't even want to talk about it. Anyone who can do it will be my saviour! ok, how do I make this button go to the specific link that is set with it.......it goes to page without eventid=eventid: Code: [Select] <form action= \"editevent.php?eventid=".$row['eventid']."\" method=\"link\"><INPUT TYPE=\"submit\" VALUE=\"Edit\"></form>"; This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=307669.0 I have created a database that echos out the result on a webpage, what i want to do is create one of the echo results into a link - the code is as follows: "Web Address: $web_address <br>" . Is there an easy way to make the result a link as the input will always be a web address? Thanks in advance! Seems to be a basic question, but I couldn't find an answer nor figure it out on my own. Basically I have a script that takes out specific data out of the database, the script works on its own, now I just need a way to make the user execute it with a link or a button. Example: Category: [Smileys] - [Category2] - [Category3] - etc. As soon as the user clicks on [Smileys] all data in the database which contains the word smileys in the category field gets selected and outputted as a list. Again the script works, I just need to be able to execute it with a button. If I understood it correctly I have to run the script by adding a if (isset($_POST['Smileys'])) { in front of the script. But how do I build the connection with the text link? Hi People. I am doing quite well with my www.airfieldcards.com website which is information for pilots in the UK and ireland should they wish to visit another airfield. It is in the form of a flight guide for free. Each card is held in a database and the cards are shown on the site by loading the following script /php/results.php?id=132 In the above example the card for c-moor in Ireland would be loaded. I want to be able to add a link within the cards that will give the user "the code" to enter that card within their own website. Sort of a "click here to get the code to add to your website" Then opening a separate box in a new window that had something like this in it. Copy and Paste the following code into your website Code: [Select] <iframe width="720" height="1500" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://airfieldcards.com/php/results.php[b][i]"what goes here?"[/i][/b] What would I put into the bit "what goes here?" to dynamically load that specific card? and give the user the correct code to add into their own site? Thanks in advance, you guys on here have always been brilliant. Hi I would like to know how to make a link select certain stuff from the database. For example the link called cape town with the id 11 is selected then the link must search through the events table for the city_id 11 and take that information and display it in another page. I would like to know how to do that or can you let me know of place that I can look. I have tried google but I don't know how to put what I'm looking for in words I would like to know how to make my links show that it's active. For example if I click on a link that says overview then that link has to be highlighted. This is the code that I have: Code: [Select] <?php if (isset($this->_params['submenus']) && is_array($this->_params['submenus'])){ foreach ($this->_params['submenus'] as $submenu){ ?> <li class="active"><a href="<?php echo $this->get_uri("/{$submenu['controller']}/{$submenu['action']}") ?>" onclick="javascript:return setSubMenu(<?php echo $submenu['id'] ?>);"><?php echo strtoupper($submenu['name'])?></a></li> <?php } } ?> Unfortunately with this code all the links are selected as active. Lets say that I want to make a certain word (or words) on a page a link. How would I make it a link without having to code in a link. Some site have adds on certain words; one day and not the next day. I am looking for similar feature, but less intrusive. No pop-up, just a link. I have a site, and there is an image with a link to another page, how can I make it so this is the only way to get to that page is by clicking on that image, and not by typing www.mywebsite.com/page.php into the address bar in a browser? I have a table where it displays some data. How do I make this Code: [Select] echo "<td>" . $row['title'] . "</td>"; into a link? This is the code I have now however when you click next to view more results it says please enter a search..., (there is more code above this however I thought that the problem would be within the code provided.) $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?> I have a line like this it prints text link but I prefer image link how should i edit it I would appreciate some feedback Code: [Select] $templates['etiket'] = array('name' => t('ETİKET'), 'module' => 'uc_invoice_pdf', 'path' => $templates_uc_invoice_pdf_path, 'pdf_settings' => $pdf_settings); Hi, I've read a lot of places that it's not recommended to store binary files in my db. So instead I'm supposed to upload the image to a directory, and store the link to that directory in database. First, how would I make a form that uploads the picture to the directory (And what kinda directories are we talking?). Secondly, how would I retrieve that link? And I guess I should rename the picture.. I'd appreciate any help, or a good tutorial (Haven't found any myself). In the following code only one image is draggable.How can i make multible image in toolbar to be draggable dynamically?Anyone help me? <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Prototype</title> <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script> <script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.7.2.min.js"></script> <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.min.js"></script> <style> body{padding:20px;} #container{ border:solid 1px #ccc; margin-top: 10px; width:350px; height:350px; } #toolbar{ width:350px; height:35px; border:solid 1px blue; } </style> <script> $(function(){ // get a reference to the house icon in the toolbar // hide the icon until its image has loaded var $house=$("#house"); $house.hide(); // get the offset position of the kinetic container var $stageContainer=$("#container"); var stageOffset=$stageContainer.offset(); var offsetX=stageOffset.left; var offsetY=stageOffset.top; // create the Kinetic.Stage and layer var stage = new Kinetic.Stage({ container: 'container', width: 350, height: 350 }); var layer = new Kinetic.Layer(); stage.add(layer); // start loading the image used in the draggable toolbar element // this image will be used in a new Kinetic.Image var image1=new Image(); image1.onload=function(){ $house.show(); } image1.src="http://vignette1.wikia.nocookie.net/angrybirds/images/b/b6/Small.png/revision/latest?cb=20120501022157"; // make the toolbar image draggable $house.draggable({ helper:'clone', }); // set the data payload $house.data("url","house.png"); // key-value pair $house.data("width","32"); // key-value pair $house.data("height","33"); // key-value pair $house.data("image",image1); // key-value pair // make the Kinetic Container a dropzone $stageContainer.droppable({ drop:dragDrop, }); // handle a drop into the Kinetic container function dragDrop(e,ui){ // get the drop point var x=parseInt(ui.offset.left-offsetX); var y=parseInt(ui.offset.top-offsetY); // get the drop payload (here the payload is the image) var element=ui.draggable; var data=element.data("url"); var theImage=element.data("image"); // create a new Kinetic.Image at the drop point // be sure to adjust for any border width (here border==1) var image = new Kinetic.Image({ name:data, x:x, y:y, image:theImage, draggable: true, // restrict to allow horizontal dragging only dragBoundFunc: function(pos) { // if(pos.x<this.minX){ pos.x=this.minX; } // this.minX=pos.x; return { x: pos.x, y: this.getAbsolutePosition().y } } }); layer.add(image); layer.draw(); } }); // end $(function(){}); </script> </head> <body> <div id="toolbar"> <img id="house" width=32 height=32 src="http://vignette1.wikia.nocookie.net/angrybirds/images/b/b6/Small.png/revision/latest?cb=20120501022157"><br> </div> <div id="container"></div> </body> </html> Edited by Biruntha, 06 January 2015 - 08:10 AM. |