Solved

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

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

738 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