?
Solved

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

Posted on 2014-03-02
4
Medium Priority
?
522 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 2000 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 111

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

752 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