Solved

If there any link in mysql data row php echo "No link" text on a page

Posted on 2014-03-02
4
519 Views
Last Modified: 2014-03-15
How it possible to show text "No link" in page when mysql database isn't any link text in data row?

But when there is link text it read on page and that i get it work like this:
echo "<br><br><a href='avaa_tiedosto.php?id={$myrow['newsid']}'>{$myrow['name']}</a>";

Open in new window



I tested following but don't work. I get next error message "Fatal error: Call to a member function query() on a non-object in.."
<?php

include("config.php");



        $newsid = $_GET['newsid'];
        
        $result = mysql_query("SELECT * FROM uutiset_tiedostot WHERE newsid='$newsid' ",$connect);
        while($myrow = mysql_fetch_assoc($result))
             {
                     echo "<b>";
					 echo "<h2>";
                     echo $myrow['title'];
                     echo "</h2>";
					 echo "</b><br><i> Julkaistu:";
                     echo date("d.m.Y",strtotime($myrow['dtime']));
                     echo "</i><hr>";
                    
			   echo stripslashes(nl2br($myrow['text1']));
                     echo " ";
					 echo "<br><br>";
					 // tästä alkaa linkin piilotus
					 $kysely = "SELECT name FROM uutiset_tiedostot
		 WHERE newsid='$newsid' ";
		
		  $linkki = $dbLink->query($kysely);
		  
	
                // Make sure the result is valid
                if($linkki->num_rows == 1) {
		
					
					 echo "<br><br><a href='avaa_tiedosto.php?id={$myrow['newsid']}'>{$myrow['name']}</a>";
                    
                     echo "<br><br><a href=\"javascript:self.history.back();\"><-- Takaisin</a>";
             }
			 
			 
			 else {
                    echo 'No link.';
                }
				
				}
				
?>

Open in new window

0
Comment
Question by:Enska77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 39899101
The error indicates that $dbLink does not have a successful connection to the database. Fixing that would be a great start! Code to make that connection isn't shown, so you'll need to figure that out yourself, or post the code (but don't post your userid and password in clear text!)

If mysql_query() is working, then I'm not sure why you're using $dbLink->query()
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39899105
Which column would the link be in, if it was present? text1 maybe?
0
 

Author Comment

by:Enska77
ID: 39899905
Thanks TerryAtOpus. Links comes from column named "name". Text 1 comes another text.
 
Database connection is file config.php and it look like this:

<?php
$dbhost="localhost";  #SQL Database Hostname (Most is: localhost)
$dbusername="user";   #SQL Username
$dbpassword="pass";   #SQL Password
$dbname="db"; #SQL Database Name

$connect = mysql_connect($dbhost, $dbusername, $dbpassword);
//Select the correct database.
$db = mysql_select_db($dbname,$connect) or die ("Could not select database");
?> 

Open in new window

0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39900319
If you're going to be writing PHP code, it's a good idea to get some kind of a foundation in the PHP programming language.  You can't get that from copying bits of code you found on the internet, but this article can help guide you to solid learning resources.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

In the instant script it appears that procedural MySQL is mixed up with object-oriented MySQLi and you probably don't want to do that.  The familiar, but deprecated MySQL extension is prevalent in many scripts on the internet, but you can no longer rely on it and PHP is removing it, so you will want to go in the direction of the MySQLi or PDO extensions instead.

This is procedural:
$result = mysql_query("SELECT...

This is object-oriented:
$linkki = $dbLink->query($kysely);

How to make the conversion to the object-oriented extensions:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
0

Featured Post

Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question