Solved

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

Posted on 2014-03-02
4
505 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
  • 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 108

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

743 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now