PHP - Echo A Href?
Hi, my PHP skills are kinda weak and I've been trying to get this to work, but for some reason, the href isn't linking properly. Can anyone help me with this?
Code: [Select] $titlehigh = preg_replace ( "'($var)'si" , "<strong> \1</strong>" , $row_linkcat[ 'sid' ] ); $linkhigh = preg_replace ( "'($var)'si" , "<strong> \1</strong>" , $row_linkcat[ 'title' ] ); $linkdesc = preg_replace ( "'($var)'si" , "<strong> \1</strong>" , $row_linkcat[ 'creator' ] ); $filehigh = preg_replace ( "'($var)'si" , "<strong> \1</strong>" , $row_linkcat[ 'file' ] ); $linkpic = preg_replace ( "'($var)'si" , "<strong> \1</strong>" , $row_linkcat[ 'parent' ] ); foreach($trimmed_array as $trimm){ if($trimm != 'b' ){ $titlehigh = preg_replace( "'($trimm)'si" , "<strong> \1</strong>" , $titlehigh); } //end highlight ?> <p> <center> <?php echo "<a href='http://www.wootability.com/WootStrips/newstrips.php?id='" . $linkpic . "'>$linkhigh</a>"; ?><br /> For some reason, the href is just a blank id. I'd be very appreciate if anyone could help. Thanks! Similar Tutorialshow to echo href id value Thanks ! Code: [Select] if (isset($_GET['edit']) && $_GET['edit'] == 'textupdate') { echo " {$_GET['id']} ! <br>" ; } <a href= \"{$_SERVER['PHP_SELF']}?edit=textupdate\" id=\"edit{$row['id']}\" >Edit</a> Hi guys, I'm trying to add this link <a href="<?php CONFIG_SITE_PATH ?>/settings.php"> to somewhere in the red text below. Can someone please show me how/where I would do this. $userObj->_userId = $_SESSION['G_userId'.CONFIG_SITE_NAME]; $userObj->getUserDetails(); echo '.$userObj->_name.'</span> / <a href="logout.php" >Logout</a></span>'; I can't figure out how to write the a href part to make it blend in with the existing img syntax. How do I alter this? Code: [Select] <?php echo '<a href=\"{$r['feedusername']\"><img src="', getUserAvatar($r['feedusername']), "\" class=\"avatar mediumsmall newspadding f_left mrl\" title=\"${r['associate_name']}\" alt=\"${r['associate_name']}\" /></a>"; ?> Hi guys; I've managed to find my way into something of a maze. <td> <a href="'Details/21/index.php'"?id= . $id .'>" . $row['id'] . "</a> </td> I'm looking at this line in the code. I realise it's currently in the wrong syntax but I'm just trying multiple different variations. At the moment I'm actually just trying to make it go to a static link but my real goal is to - get it to pick up the id number, of the id row I click, and concatenate that with the rest of my address string. Then use that as the href. Something like this: - "'Details/' + $id + '/index.php'" It's really confusing me though inside this loop and for some reason the id number is being picked up as an int, by the looks of things. It's getting above my level of understanding. Any chance one of you masters would through a n00b a lifeline?
This is my code below
<!DOCTYPE html> <html> <head> <title>LifeSaver DB</title> <h1> LifeSaver Database </h1> </head> <body> <table> <tr> <th>Id</th> <th>Location</th> <th>Initials</th> <th>TimeStamp</th> <th>Notes</th> </tr> <?php $conn = mysqli_connect("localhost", "meh", "pas", "DB"); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM LifeSaver1 ORDER BY id DESC"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { //for href row $id = $row['id']; $Footage = ['Footage']; echo "<tr> <td> <a href="'Details/21/index.php'"?id= . $id .'>" . $row['id'] . "</a> </td> <td>" . $row["Location"] . "</td> <td>" . $row["Initials"]. "</td> <td>" . $row["TimeStamp"]. "</td> <td>" . $row["Notes"] . "</td> </tr>";} //show table echo "</table>"; } else { echo "0 results"; } $conn->close(); ?> </table> </body> <style> table, td, th { border: 1px solid black; margin: auto; } table { border-collapse: collapse; color: #000; <!--font colour --> font-family: monospace; font-size: 18px; text-align: center;} th { background-color: #337AFF; color: white; font-weight: bold; } tr:nth-child(odd) {background-color: #add8e6} </style> </html> Edited February 8, 2020 by JonnyDriller OK, have no idea what's going on... I've done this a million times... why wont this output!?? I must have a major brain meltdown and dont know it yet!!! Code: [Select] <?php // this echoes just fine: echo $_POST['testfield']; // but this wont echo: echo if (isset($_POST['testfield'])) { $_POST['testfield'] = $test; } echo $test; /// or even this DOESNT echo either!: $_POST['testfield'] = $test; echo $test; ?> Hi All, I'm trying to echo the response from an SLA query, the query works and returns the data when I test it on an SQL application.. but when I run it on my webpage it won't echo the result. Please help? <?php $mysqli = mysqli_connect("removed", "removed", "removed", "removed"); $sql = "SELECT posts.message FROM posts INNER JOIN threads ON posts.pid=threads.firstpost WHERE threads.firstpost='1'"; $result = mysqli_query($mysqli, $sql); echo {$result['message']}; ?> So I need to echo a row from my database with php, but where i need to echo is already inside an echo. This is my part of my code: $con = mysql_connect("$host","$username","$password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("main", $con); $result = mysql_query("SELECT * FROM Vendor"); while($row = mysql_fetch_array($result)) { //I need to echo right here .................. but I get a blank page when I try this. Please Help. echo '<option value=$row['vendor_id']>'; echo $row['vendor_id']; echo '</option>'; } mysql_close($con); Result: A Blank page. Thanks in advance! I have a log system that allows 10 logs on each side(Left and right). I am trying to make it so that the left side has the 10 most recent logs, then the right as the next 10. Any ideas? Hi
I try to echo out random lines of a html file and want after submit password to whole content of the same html file. I have two Problems.
1st Problem When I echo out the random lines of the html file I don't get just the text but the code of the html file as well. I don't want that. I just want the text. How to do that?
for($x = 1;$x<=40;$x++) { $lines = file("$filename.html"); echo $lines[rand(0, count($lines)-1)]."<br>"; }I tried instead of "file("$filename.html");" "readfile("$filename.html");" But then I get the random lines plus the whole content. Is there anything else I can use instead of file so that I get the random lines of text without the html code?P.S file_get_contents doesn't work either have tried that one. 2nd Problem: As you could see in my first problem I have a file called $filename.html. After I submit the value of a password I want the whole content. But it is like the program did forget what $filename.html is. How can I make the program remember what $filename.html is? Or with other words how to get the whole content of the html file? My code: if($_POST['submitPasswordIT']){ if ($_POST['passIT']== $password ){ $my_file = file_get_contents("$filename.html"); echo $my_file; } else{ echo "You entered wrong password"; } }If the password isn't correct I get: You entered wrong password. If the password is correct I get nothing. I probably need to create a path to the file "$filename.html", but I don't know exactly how to do that. Hi all, I have written a piece of code querying the database to display the last ten posts from different users on a forum/blog. This is displaying the titles of the posts but I am unsure how to create a link (complete novice) to read the content of those posts. I get the syntax etc but can't really get my head around the target, if you catch my drift. I have created a new php file called recentposts but am unsure of how to take it from there. The code for both is below. The first piece of code works fine but when I click read more I am getting an undefined variable message on line 11 (I'm guessing there should be a link between the two pieces of code) and I am getting mysqli_fetch_array() expects parameter 1 to be mysqli_result on line 12. Any thoughts/hints/suggestions welcome. Thanks in advance. Code: [Select] <?php $connection = @mysqli_connect('localhost','root','','BLOG_PROJECT') //Make a connection to the database or die(mysqli_connect_error("Could not connect to the server")); //If it doesn't connect give the error message $latestposts= mysqli_query($connection,"SELECT author_id, title FROM blogposts ORDER BY timeofpost DESC LIMIT 9");//Query the database while($displayposts=@mysqli_fetch_array($latestposts)){ //go and get the information echo "{$displayposts['title']}</br>"; echo "<a href='recentposts.php'>Read more</a></br>"; } ?> And the recentposts.php is Code: [Select] <?php $connection = @mysqli_connect('localhost','root','','BLOG_PROJECT') or die(mysqli_connect_error("Could not connect to the server")); $detail= mysqli_query($connection,"SELECT * FROM blogposts WHERE 'title', 'content', 'timeofpost' = $content"); while($singlepage = mysqli_fetch_array($connection,$detail)){ extract($singlepage); echo "<h2>{$singlepage['title']}</h2></br>"; echo "{$singlepage['content']}</br>"; echo "{$singlepage['timeofpost']}"; } ?> this one is form2 .php and there is action link button where im want the target to open new browser for example now m using google chrome so when im click the action link it will open another browser which is bit actually the photo is in one im dont know how to combine that why im splitted but how to target like that Good day: Im trying to get the image of an article, which is stored in a folder, and href it with a page and the article id, which is the variable to be passed to the next page. I had href it but when I add the id to be passed I get an error. Here is the code: Code: [Select] <?php $connection = mysql_connect("localhost", "username", "password"); mysql_select_db("articles", $connection); $query="SELECT imagename, description, articledid FROM article_description ORDER BY visits DESC LIMIT 0,9"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table width ="1000" border="1" cellspacing="2" cellpadding="2"> </tr> <?php $j=0; $f6='articles.php'; while ($j < $num) { $f8=mysql_result($result,$j,"articleid"); $f9=mysql_result($result,$j,"imagename") ?> <td><a href="<?php echo $f6?aid=$f8; ?>"> <img src="articleimages/<?php echo $f9; ?>"alt="" name="picture" width="100" height="70" border="1" /> </a> </td> <?php $j++; } ?> Any help will be appreciated. Hi, im trying to create a link where it takes the row reference number and direct user to the revelant page, however i can get it work, this is my URL HREF can u please tell me what im doing wrong? thanks <td><?php echo $reference; ?><?php echo "a href='display.php?reference=".$row['reference']."'?>View Here</a>"</td> Hey there. Firstly may I apologise if this is the wrong forum for this question. I wasn't overly sure. I'm currently developing an aplication within php which allows a user to upload a file which is saved to a directory and information on the file which is saved to a databse (including the file name). This information is then displayed in a table along with the directory location concatinated with the file name to provide a file location. My only issue is that being new to PHP I am unsure how to change this address to a workable link using a href. Any help in adapting the below script would be much apreciated. Thanks, Rick. echo "<table border='1'><tr>"; for($fieldIterator = 1; $fieldIterator < $numFields; $fieldIterator++) { echo "<th>".mysql_field_name($result, $fieldIterator)."</th>"; } echo "</tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row[1] . "</td>"; echo "<td>" . $row[2] . "</td>"; echo "<td>" . $row['Price'] . "</td>"; echo "<td>" . $row['Genre'] . "</td>"; echo "<td>" . $row['Category'] . "</td>"; echo "<td>$ref= C:\wamp\www/.$row[ImageAddress] </td>"; echo "</tr>"; } echo "</table>"; Hi there! I'm trying to put 2 variables using href. Ive got it already, but when I tried to insert the page=1, which is the the variable for my paginated code.It doesn't work. When I used the codes below, from other page (I don't used variable) it works Code: [Select] <a href='module_viewpaginated.php?page=1' but when I used this code, I've got the variable $course and $program, but I don't know how to insert page for my pagination Code: [Select] <a href='module_viewpaginated.php?course=".$courseid."&program=".$program." ' I hope my problem is clear. I want to combine the two. Any help would be greatfull!! How do I post data when a user clicks a link? I know that for a submit button you just use the name attribute, but I'm not sure how to do it with a link. I'm using the code from Chapter 12 in Beginning PHP4 to display my data. For some reason, the hyperlinks that are suppose to sort columns do not work neither does the "View Record" function. The "Next" button also fails to load the next set of data. I also set register_global=on in the php.ini. Below is the code: Code: [Select] <?php include "./common_db.inc"; function list_records() { global $default_dbname, $user_tablename; global $default_sort_order, $default_order_by, $records_per_page; global $sort_order, $order_by, $cur_page; global $PHP_SELF; $link_id = db_connect($default_dbname); if(!$link_id) error_message(sql_error()); $query = "SELECT count(*) FROM $user_tablename"; $result = mysql_query($query); if(!$result) error_message(sql_error()); $query_data = mysql_fetch_row($result); $total_num_user = $query_data[0]; if(!$total_num_user) error_message('No User Found!'); $page_num = $cur_page + 1; $total_num_page = $last_page_num = ceil($total_num_user/$records_per_page); html_header(); echo "<CENTER><H3>$total_num_user records found. Displaying the page $page_num out of $last_page_num.</H3></CENTER>\n"; if(empty($order_by)) { $order_by_str = "ORDER BY $default_order_by"; $order_by = $default_order_by; } else $order_by_str = "ORDER BY $order_by"; if(empty($sort_order)) { $sort_order_str = $org_sort_order = $default_sort_order; $sort_order = 'DESC'; } else { $sort_order_str = $org_sort_order = $sort_order; if($sort_order == 'DESC') $sort_order = 'ASC'; else $sort_order = 'DESC'; } if(empty($cur_page)) { $cur_page = 0; } $limit_str = "LIMIT ". $cur_page * $records_per_page . ", $records_per_page"; $query = "SELECT project, route, config FROM $user_tablename $order_by_str $sort_order_str $limit_str"; $result = mysql_query($query); if(!$result) error_message(sql_error()); ?> <DIV ALIGN="CENTER"> <TABLE BORDER="1" WIDTH="90%" CELLPADDING="2"> <TR> <TH WIDTH="25%" NOWRAP> <A HREF="<?php echo "$PHP_SELF?action=list_records&sort_order=$sort_order&order_by=route"; ?>"> Route </A> </TH> <TH WIDTH="25%" NOWRAP> <A HREF="<?php echo "$PHP_SELF?action=list_records&sort_order=$sort_order&order_by=project"; ?>"> Project </A> </TH> <TH WIDTH="25%" NOWRAP> <A HREF="<?php echo "$PHP_SELF?action=list_records&sort_order=$sort_order&order_by=config"; ?>"> Config </A> </TH> <TH WIDTH="25%" NOWRAP>Action</TH> </TR> <?php while($query_data = mysql_fetch_array($result)) { $route = $query_data["route"]; $project= $query_data["project"]; $config = $query_data["config"]; echo "<TR>\n"; echo "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">$route</TD>\n"; echo "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">$project</TD>\n"; echo "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">$config</TD>\n"; echo "<TD WIDTH=\"25%\" ALIGN=\"CENTER\"> <A HREF=\"javascript:open_window('$PHP_SELF?action=view_record& project=$project');\">View Record</A></TD>\n"; echo "</TR>\n"; } ?> </TABLE> </DIV> <?php echo "<BR>\n"; echo "<STRONG><CENTER>"; if($page_num > 1) { $prev_page = $cur_page - 1; echo "<A HREF=\"$PHP_SELF?action=list_records&sort_order=$org_sort_order& order_by=$order_by&cur_page=0\">[Top]</A>"; echo "<A HREF=\"$PHP_SELF?action=list_records&sort_order=$org_sort_order& order_by=$order_by&cur_page=$prev_page\">[Prev]</A> "; } if($page_num < $total_num_page) { $next_page = $cur_page + 1; $last_page = $total_num_page - 1; echo "<A HREF=\"$PHP_SELF?action=list_records&sort_order=$org_sort_order& order_by=$order_by&cur_page=$next_page\">[Next]</A> "; echo "<A HREF=\"$PHP_SELF?action=list_records&sort_order=$org_sort_order& order_by=$order_by&cur_page=$last_page\">[Bottom]</A>"; } echo "</STRONG></CENTER>"; html_footer(); } function view_record() { global $default_dbname, $user_tablename; global $project; global $PHP_SELF; if(empty($project)) error_message('Empty User ID!'); $link_id = db_connect($default_dbname); if(!$link_id) error_message(sql_error()); $query = "SELECT route, project, config, opfieldc, opfieldrd, mod FROM $user_tablename WHERE project = '$project'"; $result = mysql_query($query); if(!$result) error_message(sql_error()); $query_data = mysql_fetch_array($result); $route = $query_data["route"]; $project = $query_data["project"]; $config = $query_data["config"]; $mod = $query_data["mod"]; html_header(); echo "<CENTER><H3> Record for User No.$route - $project($config) </H3></CENTER>"; ?> </TR> </TABLE> </DIV> <?php } html_footer(); switch($action) { case "view_record"; view_record(); break; default: list_records(); break; } ?> Appreciate any insight you can offer Hello, I have created a webpage that essentially generates an sql query and then puts the results into a table that is displayed. On one of the columns in this displayed table, I want to allow the user to click on each of the values which will in turn execute a php function. I have the hyperlink working but this is to a separate page. What I actually need to do is firstly - just ran a php function that will create a new table beneath the currently displayed one. Secondly, once this is achieved, I need to pass some value to the function so that the generated table is dependent on the value that was clicked. I've tried a few things and researched but I am struggling. I am a beginner. Any help would be greatly appreciated. Here is an extract of the code used for inputting data into the original table - showValuesSR is the function name <?php while (!$rsMetrics->EOF) { ?> <tr> <?php for ($x=0; $x<$numberOfFields; $x++) { if ($fieldNames[$x] == "Values_SR"){ ?> <td><a href= ?showValuesSR><?php echo $rsMetrics->fields[$fieldNames[$x]]->Value?></a></td> <?php } else{ ?> <td><?php echo $rsMetrics->fields[$fieldNames[$x]]->Value?></td> <?php } } ?> </tr> <?php $rsMetrics->MoveNext(); } ?> </table> <?php function showValuesSR(){ ?> <table border="0" cellpadding="5" width="100%"> <tr><td background="../images/table_toolbar_bkg.gif" align="center"><font color="Blue" face="verdana" size="2"><strong>function working</strong></td></tr> </table> <?php } ?> how can i pass more then one value via href with this kind of method echo "<a href=\"submit_docs.php?prop_id=".$prop_id."\">Click </a>"; tnx Howdy, I'm in trouble here. Does someone know how to wrap a url which is in the string with href tag without writing like a few hundred line long code? Example: Befo "This is a url http://www.domain.com and then some text" After: "This is a url <a href="http://www.domain.com">http://www.domain.com</a> and then some text" the string is to be received by a flash application right after. |