Solved

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

Posted on 2014-03-02
4
509 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

896 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

13 Experts available now in Live!

Get 1:1 Help Now