PHP - Text Link To A Url Variable From A Database
Hello all! I am somewhat new to PHP and SQL, but I think I have a basic understanding of how the language works. I have read through a million different websites and forums, and have tried a million different ways but am just not getting anywhere!
This is what I am trying to do... I have a text link that I want to click through to an outside URL from my website. This outside URL was already entered into an SQL database, and I just cant seem to get the text link to bring up the outside URL from the database. This is what I have so far... 1.) My webpage that I am working on is www.mywebsite.com/articles.php 2.) I want the text "Read more..." on this webpage to click through to an outside URL, like "http://www.google.com", which was already entered into an SQL database under the title of "article_link" in a new window 3.) So I would like for "Read more..." to click through the outside URL that was entered into "article_link" in the database Code: [Select] <?php echo <p><a href="\' . $article_link . '\" target="_blank">Read more...</a></p>; ?> Nothing I have tried has worked so far, nothing clicks through to the outside URL in the "article_link" entry from the database. Sorry if I am being redundant, I have been at this all day! Please help and thank you in advance!! Similar TutorialsCode: [Select] <?php echo $row_Recordset1['name']; ?> i want to convert the name in to like <a href=main.php?name= $row_Recordset1['name'] >> in databse i has 3 name Steve Mark Lisa i want that names into link like main.php?name=mark and so on how to do it help me h 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 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
Quote i need to store a variable from database like if i have "copies" in one of my column in my database then i have to store a particular value for copies store it to $copies here i want that i can store value of copies into $copies $update_book="update book set copies=copies-1 where bookid='$bookid'"; $result=mysql_query($update_book,$linkID1); if($result) { print "<html><body background=\"header.jpg\"> <p>book successfully subtracted from database</p></body></html>"; } else { print "<html><body background=\"header.jpg\"> <p>problem occured</p></body></html>"; } } 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 Hi there. How do I reflect the text content of the variable $a in this text form: <input type="text" name="artist"> Regards Morris 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); Hy, How can I put a link to a variable without doing like: Code: [Select] <a href='#'>$var</a> I heard that can be other ways. Thanks Hi, I'm trying to use a variable- "$newdbname" in a script that sets up a new database. I'm using this variable because I have an include file that sets all login info and the database name as variables. here's the code. or at lest the relevant part. <?php require 'dbinfo.inc.php'; $db = mysql_connect($servname,$dbusername,$dbpassword) or die ('Unable to connect. Check your connection parameters.'); mysql_select_db($database, $db) or die(mysql_error($db)); // create the user table $query = 'CREATE TABLE ($newdbname)( user_id int(30) NOT NULL AUTO_INCREMENT, username varchar(20) NOT NULL, password varchar(41) NOT NULL, PRIMARY KEY (user_id) ) ENGINE=MyISAM'; mysql_query($query, $db) or die (mysql_error($db)); if I run the script like this, I get the following error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '($newdbname)( user_id int(30) NOT NULL AUTO_INCREMENT, usernam' at line 1 if I run the code as this, without parentheses around the variable, it creates a table named "$newdbname" <?php require 'dbinfo.inc.php'; $db = mysql_connect($servname,$dbusername,$dbpassword) or die ('Unable to connect. Check your connection parameters.'); mysql_select_db($database, $db) or die(mysql_error($db)); // create the user table $query = 'CREATE TABLE $newdbname ( user_id int(30) NOT NULL AUTO_INCREMENT, username varchar(20) NOT NULL, password varchar(41) NOT NULL, PRIMARY KEY (user_id) ) ENGINE=MyISAM'; mysql_query($query, $db) or die (mysql_error($db)); what am I doing wrong? This is driving me crazy .... Need to use a variable for the database name on this code ... Code: [Select] <!DOCTYPE html> <html> <head> <title>Table Definition's Tool</title> <style type="text/css"> th { font-size: 110%; border-bottom: 2px solid black; } td { padding: 3px; border-bottom: 1px solid #aaa } </style> </head> <body> <h1>ITG's table's definition</h1> <table> <?php error_reporting (E_ALL ^ E_NOTICE); //Variables $instance=$_REQUEST['instance']; $database_name= $_REQUEST['database_name']; $table=$_REQUEST['table']; require 'utils.php'; // Connect via Windows authentication $server = $instance; $connectionInfo = array( 'CharacterSet' => 'UTF-8' ); $db = sqlsrv_connect($server, $connectionInfo); if ($db === false) { exitWithSQLError('Database connection failed'); } /* Set up and execute the query. */ $query = "SELECT COLUMN_NAME, ORDINAL_POSITION, COLUMN_DEFAULT, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH FROM $database_name.INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='$table'"; // Run query $qresult = sqlsrv_query($db, $query); if ($qresult === false) { exitWithSQLError('Query of product data failed.'); } echo '<tr><th>COLUMN NAME</th><th>POSITION</th><th>DEFAULT</th><th>TYPE</th><th>LENGHT</th></tr>'; // Retrieve individual rows from the result while ($row = sqlsrv_fetch_array($qresult)) { echo '<tr><td>', htmlspecialchars($row['COLUMN_NAME']), '</td><td>', htmlspecialchars($row['ORDINAL_POSITION']), '</td><td>', htmlspecialchars($row['COLUMN_DEFAULT']), '</td><td>', htmlspecialchars($row['DATA_TYPE']), '</td><td>', htmlspecialchars($row['CHARACTER_MAXIMUM_LENGTH']), "</td></tr>\n"; } // null == no further rows, false == error if ($row === false) { exitWithSQLError('Retrieving schema failed.'); } // Share Release result liststatement resource and close connection sqlsrv_free_stmt($qresult); sqlsrv_close($db); ?> </table> </body> </html> Is a simple code where the main MS-SQL query is Code: [Select] SELECT COLUMN_NAME, ORDINAL_POSITION, COLUMN_DEFAULT, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH FROM $database_name.INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='$table' The user should be able to introduce the database and table's name and above query will display the table's schema. However, does not work. I am able to use a variable for the table, but the program does nothing when I use $database_name inside the query. What am I doing wrong? Help, please .... I'm stumped on what's causing this problem. $descriptor2 is entering "0". But $_POST['States'] does have a value. I put $testable in as a variable to test that in place of descriptor2 and it works just fine. Code: [Select] $descriptor1 = isset($_GET['id']) ? (int)$_GET['id'] : null; $descriptor2 = isset($_POST['States']) ? (int)$_POST['state'] : null; $descriptor3 = isset($_POST['continent_regions']) ? (int)$_POST['continent_regions'] : null; $descriptor4 = isset($_POST['Continents']) ? (int)$_POST['Continents'] : null; $descriptor5 = isset($_POST['Country']) ? (int)$_POST['Country'] : null; $testable = $_POST['States']; // my test variable $query = "INSERT INTO plant_locations_link(plant_id,state,continent_regions,continents,country) VALUES ($descriptor1,$descriptor2,$descriptor3,$descriptor4,$descriptor5)"; // if I change descriptor2 to testable, it inputs the number I need. I have this link "https://localhost/what/index.php?album=parent%2Fsubalbum&image=1coffee.jpg" Am trying to insert a variable(eid=86) so that it comes before all other variables to read thus "https://localhost/what/index.php?eid=86&album=parent%2Fsubalbum&image=1coffee.jpg" Regards trying to post a link to the database Code: [Select] $amessage ="<a href="link.php">this is a link </a>"; then return that link later on another page. I have a page that lists out some basic information about each quiz this particular student has taken (call it "quiz summary"). I am creating another page that will have all details of a particular quiz by itself (call it "quiz detail"). If I have a link for each quiz on the "quiz summary" page, how do I tell the "quiz detail' page which link they clicked on? Or which quiz they have selected. I was thinking it would work if I assigned a session variable to each link and then the "quiz detail" page could verify which returns true still and show details for that quiz. Would this logic work? Npot sure how to do it anyone though. thanks for any help! ive done a page that works fine but id like to add links to the results so i can view the models. working page here http://sts.hostei.com/dsgi/list_records.php in the make column i want a link that will only show the make clicked. if this was a fixed page i no how to do it but i cannot figure out to make it from the way ive discribed. i know i have to alter this line <td><div align="center"><?php echo $rows['make']; php?></div></td> but no idea how to do this. do i create a new page for the query? if so how do i pass the $var? is it possable to do this from the same page? ie appear undr the main table. Thanks <?php include("config.php"); // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql = "SELECT make, COUNT(*) AS total, SUM(IF(comments = \'pass\', 1, 0)) AS withComments FROM dsgi_serval GROUP BY make ORDER BY COUNT(*) DESC"; $result=mysql_query($sql); php?> <table width="319" border="1"><tr> <td colspan="4"><font size="4" face="Verdana"> <strong><div align="center">Validation Total's </div></strong></font> </td> </tr> <tr> <td width="137" align="center"><strong>Make</strong></td> <td width="85" align="center"><strong>Total</strong></td> <td width="75" align="center"><strong>Validated</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ php?> <tr> <td><div align="center"><?php echo $rows['make']; php?></div></td> <td><div align="center"><?php echo $rows['total']; php?></div></td> <td><div align="center"><?php echo $rows['withComments']; php?></div></td> </tr> <?php } php?> <tr> <td><div align="center">Totals</div></td> <td> <div align="center"> <?php // counts all rows $query = "SELECT make, COUNT(make) FROM dsgi_serval "; $result1 = mysql_query($query) or die(mysql_error()); // Print out result while($row1 = mysql_fetch_array($result1)){ echo $row1['COUNT(make)']; } ?> </div></td> <td><div align="center"> <?php // counts passes $query = "SELECT make, COUNT(make) FROM dsgi_serval where comments like 'pass'"; $result2 = mysql_query($query) or die(mysql_error()); while($row2 = mysql_fetch_array($result2)){ echo $row2['COUNT(make)']; } ?> </div></td> </tr> </table> <?php mysql_close(); php?> Hi. I have a sort of security script which checks a few things, how can i save the url of the link that was clicked, so i can pass it through the script then if all is good, continue on to the url, if not send them somewhere else let me try to explain better with a little text picture user clicks link ----------------------> link goes to my security script --------------------> if the check passes, continue to original links url so basically i just need to know how to save the links url as a variable Hi guys, I want to find the most efficient way of setting a php variable through a link.
What I'm trying to achieve is to allow the user to select a category and their location and store the two variables to update my database results. I first used the GET method, but since the page refreshes when the user selects any other Get variable, so it ends up reseting the variables. Currently I have the category and locations as drop down menu with links to each of the options. I'll appreciate any help. Thank you. :]
Quote i want to store a value from a database and use it as variable in php code can anyone help me out in this code i want to store value of copies in a php variable and want that it should be more than 0 (zero) for furthur calculations $update_book="update book set copies=copies-1 where bookid='$bookid'"; $result=mysql_query($update_book,$linkID1); if($result) { print "<html><body background=\"header.jpg\"> <p>book successfully subtracted from database</p></body></html>"; } else { print "<html><body background=\"header.jpg\"> <p>problem occured</p></body></html>"; } I am trying to take a variable from a database. But it keeps equaling nothing. Ive tried using mysql_error() and sI get nothing. I also keep tryed mysql_num_rows() and I get 3(just what Id exspect). Here is the code. Code: [Select] <?php if($userb) { $q1 = " SELECT sub FROM login_info WHERE user='$user_log' LIMIT 1 "; $s1 = mysql_query($q1); $scribe = mysql_fetch_assoc($s1); $sub = explode('![sep]!' ,$scribe['sub']); foreach($sub as $key => $name) { $q2 = " SELECT * FROM subscribe WHERE user = '$name' "; echo 'Llama'; $s2 = mysql_query($q2); $num1 = mysql_num_rows($s2); echo '<h3>' .$name .' Posted ' .$num1 .' Storie(s)! </h3>'; while($stor = mysql_fetch_assoc($s2)); { $story = $stor['stor']; $sid = $stor['sid']; $q3 = " SELECT * FROM story_info WHERE id = $sid "; echo $q3 .'<br />'; $s3 = mysql_query($q3) or die(mysql_error()); $rows = mysql_fetch_assoc($s3); $viewsdb = $rows['views']; $titledb = $rows['title']; $userdb = $rows['user']; $catdb = $rows['cat']; $ratdb = $rows['rating']; $id_db = $rows['story_id']; $sumdb = shorten($rows['sum']); echo "<h3><a href='?p=page&id=$id_db'> $titledb </a> </h3>"; echo "<div id='fun_info'>"; echo "$sumdb <br />"; echo "By <a href='?p=profile&user=$userdb'> $userdb </a> <br /> "; echo "$viewsdb Views | Rated: $ratdb | Catagory: <a href='?p=cat_view&gen=$catdb'> $catdb </a> </div>"; } } } else { login('?p=sub'); } |