PHP - Link
Hi Everyone,
So I am building a page that list records from a table, in this case customers, and I want to the printed last name (lname) of the record to be the link to the a detail php page that displays the detailed record. Any suggestions on how to do that? Here is what I'm using now. I don't like the button look, that's why i'm trying to make a link. Any Suggestions? Thanks <? session_start(); include 'menu.php'; include ("include/connect.php"); // how many rows to show per page $rowsPerPage = 10; // by default we show first page $pageNum = 1; // if $_GET['page'] defined, use it as page number if(isset($_GET['page'])) { $pageNum = $_GET['page']; } // counting the offset $offset = ($pageNum - 1) * $rowsPerPage; $sql = @mysql_query("SELECT * FROM customer ORDER BY id LIMIT $offset, $rowsPerPage"); $id = ''; echo "<table border='0' align='center'><tr><td align='left' colspan='2'>Last Name</td><td align='center'>Location</td><td align='right'>Date Posted</td></tr>"; while ($row = mysql_fetch_array($sql)) { if ($id != $row['id']) { echo "<tr><td><form action='customerdetail.php' method='post'><input type='hidden' name='locationp' value='{$row['location']}' /><input type='hidden' name='titlep' value='{$row['title']}' /><input type='hidden' name='idp' value='{$row['id']}' /><b><font size='4'><input type='submit' value='{$row['lname']}'></font></b></form></td><td> </td><td align='center'><b><font size='4'>{$row['location']}</font></b></td><td align='right'><b><font size='4'> {$row['datep']}</font></b> </td></tr><tr><td colspan='4'> </td></tr>"; $id = $row['id']; } } echo "</table>"; // how many rows we have in database $query = "SELECT COUNT(id) AS numrows FROM customer"; $result = mysql_query($query) or die('Error, query failed'); $row = mysql_fetch_array($result, MYSQL_ASSOC); $numrows = $row['numrows']; // how many pages we have when using paging? $maxPage = ceil($numrows/$rowsPerPage); // print the link to access each page $self = $_SERVER['PHP_SELF']; // creating previous and next link // plus the link to go straight to // the first and last page if ($pageNum > 1) { $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page\">[Prev]</a> "; $first = "<br><center> <a href=\"$self?page=1\">[First Page]</a> "; } else { $prev = ' '; // we're on page one, don't print previous link $first = '<br><center> '; // nor the first page link } if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " <a href=\"$self?page=$page\">[Next]</a> "; $last = "<a href=\"$self?page=$maxPage\">[Last Page]</a></center> "; } else { $next = ' '; // we're on the last page, don't print next link $last = ' </center>'; // nor the last page link } // print the navigation link echo $first . $prev . " Showing page $pageNum of $maxPage pages " . $next . $last; // and close the database connection mysql_close($con) // ... and we're done! ?> Similar TutorialsHi 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 Hello.
I have a bit of a problem. When I fetch the link field from the database.i don't see an actual link on the page.
One more thing, what type of field should I use to store the link in the database? Probably there is where I went wrong.
All help is
Hi Support, I have a form, where it collects user description input. I can collect the inputs and store it with newline. The issue is - how to collect the http link to actual hyperlink ref during display. The following is my code: <textarea name="description" cols="50" rows="10" id="description"><?php echo str_replace("<br>", "\n", $description);?></textarea></td> For example, User input: Hi, Check it out - http://www.google.com/ I would like to display google link as href so that Viewers can click the link and go to the page. Right now, it is not href and user need to copy the link to new tabs or pages and then it can come. Thanks for your help. Regards, Ahsan here's my code that i've used to send an email. Code: [Select] $link = "<a href=\"http://www.example.com/" . $num . "\">" . $num . "</a>"; $query = "SELECT content FROM emails"; $result = mysql_query($query) or die(); $email_content = mysql_result($result, 0); $email = sprintf($email_content, $first, $name, $from, $link, $record, $rec, $inc, $max); $email_body = stripslashes(htmlentities($email, ENT_QUOTES, 'UTF-8')); // this is sent to another php script via post.... $subject = $_POST['subject']; $message = nl2br(html_entity_decode($_POST['email_body'])); $to = "me@whatever.com"; $charset='UTF-8'; $encoded_subject="=?$charset?B?" . base64_encode($subject) . "?=\n"; $headers="From: " . $userEmail . "\n" . "Content-Type: text/html; charset=$charset; format=flowed\n" . "MIME-Version: 1.0\n" . "Content-Transfer-Encoding: 8bit\n" . "X-Mailer: PHP\n"; mail($to,$encoded_subject,$message,$headers); in the db, emails.content is of the text type and contains several lines of text with %4$s which inserts the value of $link into the body. when the email arrives, there is a link and it appears fine, with the value of $num hyperlinked. however when you click on it it doesn't go anywhere. when copying the link location from the email it gives me x-msg://87/%22http://www.example.com/16 what is x-msg? how can i get this to work properly? hi hope you all are fine. i have been working on a Email Form (like user fills up the form which send the information to our email) but i was having problem with (URL field i created) link of form is (http://services.shadowaura.com/allquotations/static.php) field which is not working is "Inspirational Website:" when i submit the form it says (Forbidden You don't have permission to access /allquotations/staticworking.php on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.) Can some one help me out ????????????? code behind this form is: Code: [Select] <?php /* Email Variables */ $emailSubject = 'Shadow Aura Contact Info!'; $webMaster = '*****@shadowaura.com'; /* Data Variables */ $Name = $_POST['Name']; $email = $_POST['email']; $Cell = $_POST['Cell']; $Phone = $_POST['Phone']; $CompanyName = $_POST['CompanyName']; $TypeOfBusiness = $_POST['TypeOfBusiness']; $Address = $_POST['Address']; $YourBudget = $_POST['YourBudget']; $HaveDomain = $_POST['HaveDomain']; $RunningWeb = $_POST['RunningWeb']; $WebLink = $_POST['WebLink']; $Inspiration1 = $_POST['Inspiration1']; $Inspiration2 = $_POST['Inspiration2']; $NumberPages = $_POST['NumberPages']; $UseFlash = $_POST['UseFlash']; $TimeFrame = $_POST['TimeFrame']; $Provided = $_POST['Provided']; $Comments = $_POST['Comments']; $body = <<<EOD <h1> Static Website Quotation </h1> <br> <b>Name of Client:</b>$Name<br> <b>Your Email:</b>$email<br> <b>Cell Number:</b>$Cell<br> <b>Line Phone Number:</b>$Phone<br> <b>Company Name:</b>$CompanyName<br> <b>Type of Business:</b>$TypeOfBusiness<br> <b>Address:</b>$Address<br> <b>Your Budget:</b>$YourBudget <br> <b>Do you have Domain:</b>$HaveDomain<br> <b>Your Site is Running:</b>$RunningWeb <br> <b>Website Link:</b><a href="$WebLink">$WebLink</a><br> <b>Inspiration:</b>$Inspiration1<br> <b>2nd Inspiration:</b>$Inspiration2<br> <b>Number of Pages:</b>$NumberPages<br> <b>Use Flash:</b>$UseFlash <br> <b>Time Frame:</b>$TimeFrame<br> <b>You will provide:</b>$Provided<br> <b>Comments:</b>$Comments<br> EOD; $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); /* Results rendered as HTML */ $theResults = <<<EOD <html> <head> <title>sent message</title> <meta http-equiv="refresh" content="3;URL=http://services.shadowaura.com/"> <style type="text/css"> <!-- body { background-color: #8CC640; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 20px; font-style: normal; line-height: normal; font-weight: normal; color: #fec001; text-decoration: none; padding-top: 200px; margin-left: 150px; width: 800px; } --> </style> </head> <div align="center">Your email will be answered soon as possible! You will return to <b>Shadow Aura Services</b> in a few seconds !</div> </div> </body> </html> EOD; echo "$theResults"; ?> Hi guys, I'm using a twitter script that grabs the title and publishings it like so: "Title - Read More at..." I was wondering how i would be able to post the direct link into twitter.. like news.php?id=1 for example. Code: [Select] $tweet->post('statuses/update', array('status' => ''.$_POST[title].' - more at MY URL')); This part is in the script to publish automatically when the users adds to the news database. How am i able to get the ID just after the posting of the news? Thanks! 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); Hello dear friends, Let say we have Code: [Select] $space ="hello world"; then remove spaces between the words by using Code: [Select] $title = str_replace(' ', '-', trim($space)); so it would be here as "hello-world" and let say we have stored title,article text...whever in an database table that call back all this using id then for an article with id=1 its link will be Code: [Select] site.com/index.php?id=1 it is clear that the Code: [Select] echo "$id"; //<--- 1 now some wordpress or/and blogs using rewrite .htaccess to make the link as Code: [Select] site.com/$title-$id (as our example site.com/hello-world-1) then how they know its $id = 1 to get any variables from database that needs the id i've tried but never works and only works if i made something like Code: [Select] site.com/$title_$id //<-- site.com/hello-word_1 cause it needs difference separate in order to understand the id so how to make it ? how to make it understand that the last separated is the id thanks Hello dear friends, Let say we have Code: [Select] $to = "gigi"; then we have link like this Code: [Select] mysite.com/$to_$id.html with indeed .htaccess code Code: [Select] RewriteRule -(.*)\.htm file.php?id=$1 it will works , Now what if i want to make the link like this Code: [Select] mysite.com/$id/$to.html what will be the .htaccess code in this way ??? I have a lovely RSS creation script which dynamically writes an RSS feed using the information from the database, which you can automatically update every time a blog entry (or anything else generated by a script) is added. The only issue with it, is that the Code: [Select] <strong> tags have had to be deleted using strip_tags() because the RSS doesn't like it. I want to keep the original formatting of the blog article but because I have to strip out the strong links, the hyperlinks are also removed. I don't know enough about RSS (IMHO) to work out how to put the links back in - do I need to format the STRONG tags differently, or do i need to change the PHP to str_replace() the strong tags with nothing? Here's some code that does work: Code: [Select] <item rdf:about="http://www.manteya.com/blog/Music-Improves-Productivity_24.html"> <title>Music Improves Productivity</title> <link>http://www.manteya.com/blog/Music-Improves-Productivity_24.html</link> <description>Research shows that music can improve speed of working within organisations. There is a double-edged sword to this article, however. Music with fast tempos can help the release of adrenalin and therefore increase the heart rate of the listener. Music producers here in the UK have taken advantage And here's some that doesn't: Code: [Select] <item rdf:about="http://www.manteya.com/blog/Music-Improves-Productivity_24.html"> <title>Music Improves Productivity</title> <link>http://www.manteya.com/blog/Music-Improves-Productivity_24.html</link> <description>Research shows that music can improve <strong>speed</strong> of working within organisations. There is a double-edged sword to this article, however. Music with fast tempos can help the release of adrenalin and therefore increase the heart rate of the listener. Music producers here in the UK have taken advantage I'm sure you geniuses (or geniei) can work it out, so any help would be very welcome indeed. This link dnt seem to work. Can someone help? echo "<td><a href =" . $rows['url'] .">"</a>"</td>"; Thankz. Just need a correction on this please, there is a Parse error, think I got the quote marks wrong somewhere? echo "<li>" . <a href="/stock/$stock.htm"> .$Stock . ": " . $Name . "</a></li>\n"; Thanks Please reply in simple terms, 'cause I'm simple! Hello all. If I have a list of links on a page like: >Manchester United >Manchester City >Aresnal How do I make clicking one of the links then query my database for that record? So I click on manchester united and the body of the page calls all the information on the database for that club? Surely I don't need each page to link to their own PHP page do I? The manchester united link doesn't need to point to manchester-united.php? Can I have all the links pointing to club.php that changes in content depending on the link that was clicked? How do I achieve this? What's this called? Please help! Thanks all in advance. Hello friends, If i've link as following myownsite.000/index.php?r=5774 and i want to convert it to be myownsite.000/5774 i've tried .htaccess Code: [Select] RewriteRule (.*)\ index.php?r=$1 but didn't worked ! can anyone write it thanks I have problem, there are users with "?" character in username, and their address to profile is /profile/username/. I have var: $username that is that username, now, how can i replace all that characters which cant open users profile.. I mean for "?" i need to put "%3F", how can i replace? I know with str_replace, but is there any other solution like htmlencode or something like that? :S Hello friends. I'm needing a bit of help with some code. I have this code to show my users their referral link: (this code goes in the reg.php file) Code: [Select] if($_COOKIE['referido']) { $ref = $_COOKIE['referido']; } else { $ref = $do->get_r_file_url(); $ref = str_replace(array(".html", "/"), "", $ref); if(eregi('.php', $ref)) { $ref=false; } setcookie("referido", $ref, time()+60*60*24*30); } And then this one on the user's profile to show their referral URL: Code: [Select] $dp = $do->get_loc()."reg.php/{$signin_username}.html"; So the result is "mysite.com/reg.php/referral.html" and I want it to be "mysite.com/reg.php?referral" I just need to get rid of the "/" I've seen sites like "thesite.com/?r=referral" How can i do something like that? Thanks! Hello friends! I just need the last help to have everything working ok. I'm having an issue because the input won't show the referral ID. Here is the .htaccess code: /*This changes the URL mysite.com/reg.php/referral.html to mysite.com/reg.php?referral*/ Code: [Select] Options +FollowSymlinks RewriteEngine on RewriteRule ^reg.php/(.*)\.html$ http://www.mysite/reg.php?$1 Then the code in the reg.php page: Code: [Select] if($_COOKIE['referido']) { $ref = $_COOKIE['referido']; } else { $ref = $do->get_r_file_url(); $ref = str_replace(array(".html", "/"), "", $ref); if(eregi('.php', $ref)) { $ref=false; } setcookie("referido", $ref, time()+60*60*24*30); } And then the input: <input size='3' style='width:170px;' id='referral' type='hidden' name='6' value='{$ref}' > So how do I do to make the input show the referral ID? Thanks! Hi, DaniWeb I'm doing a website for a music school and i have a table with all the instruments: And i want to click in one image and it goes to other page where's the instrument program. I mean, each image has 1 page with its own program. I have this code: Code: [Select] <?php include "db_connect.php"; $sql_imagem = "SELECT cod_curso, imagem_curso, nome_curso FROM curso ORDER BY nome_curso ASC"; $i=0; echo "<table width = 90% height = 45% align = center>"; $executa=mysql_query($sql_imagem,$connect); while($dados=mysql_fetch_array($executa)) { $i+=1; if ($i == 1) { echo "<tr> <td align = center>"; } else { echo "<td align = center>"; } echo "<img src=\"".$dados['imagem_curso']."\"/></a> <br /> ".$dados['nome_curso']; if ($i == 4) { echo "</td> </tr>"; $i=0; } else { echo "</td>"; } } echo "</table>"; ?> And i was thinking about using Arrays, but i don't know how to work with it. Can someone help me, please? Thank you, PF2G Quote Hi people, I've written a real simple class call User, wich has the most basic of functions in it The one called output returns some data from the database along with a delete link wich should call the delete function from the same class I have no idea why it won't run..... I'm stumped as to what i'm doing wrong PLEASE SHOW ME WHERE MY STUFF UP IS... Quote This is the class called user <?php class User extends Database { function read() { $this->query("SELECT * FROM sales_peepl;"); } function delete($id) { $this->query("DELETE * FROM sales_peepl WHERE salesid = {$id};"); } function output() { return $this->_row->sales_person ." - ". $this->_row->access . " " . '<a href="?=action=$this->delete&id='.$this->_row->salesid.'">delete</a>' . "<br/>"; } } ?> Quote and this is the output page wich shows the data and link <?php include_once($_SERVER['DOCUMENT_ROOT'] . '/sales/includes/global.php'); $t = new User(); $t->connect(HOST, USERNAME , PASSWORD, DATABASE); $t->read(); ?> <html><head><title></title> </head> <body> <?php while ( $t->next()) { echo $t->output() . " "; } ?> </body> </html> Quote As you can see its very basic...... But the bloody link won't work hello, i was wondering if there is a way to have a link do a command, but not to goto a page. my reason being is that the music player software i use has a built in web server and if you goto a certain page, it will process that command. so right now, i have an iframe that i do a target to. its pretty mickey mouse, but its what i knew how to do. thanks |