nepzap2 Posted June 6, 2008 Share Posted June 6, 2008 I have a script that reads from a MYSQL database. I want to be able to create a condition that checks to see if there is a url associated with a title of a publication. If there is then make the title a link, if not just print the title. Here is what I had so far, But its not working. Any help is greatly appreciated. <?php include 'db_config.php'; // Collects data from "test" table $data = mysql_query("SELECT * from pubs WHERE pi LIKE '$name' AND label = 'S' ORDER by year DESC") or die(mysql_error()); // Print out the contents of the entry while($info = mysql_fetch_array($data)) { if($info['url'] = "") { print '<p>'.$info['author_1'].', ' .$info['author_2'].'. ' .$info['year'].'. ' .$info['title_secondary'].' ' .$info['volume'].': ' .$info['pages'].'</p>'; } else { print '<p>' .$info['author_1'].', ' .$info['author_2'].'. ' .$info['year'].'. <a rel="external" href="' .$info['url']. '">'.$info['title'].'</a>. ' .$info['title_secondary'].' ' .$info['volume'].': ' .$info['pages'].'</p>'; } } ?> Quote Link to comment Share on other sites More sharing options...
Wolphie Posted June 6, 2008 Share Posted June 6, 2008 if($info['url'] = "") You are using an assignment operator "=" not a comparison operator "==". if($info['url'] == "") However, you should be using: if(empty($info['url'])) { // do something } or if(strlen($info['url']) < 0) { // do something } Quote Link to comment Share on other sites More sharing options...
tapos Posted June 6, 2008 Share Posted June 6, 2008 u just put the assignment(=) operator instead on logical (==) operator. Please change the condition like following if($info['url'] == "") { Quote Link to comment Share on other sites More sharing options...
Wolphie Posted June 6, 2008 Share Posted June 6, 2008 tapos: (==) is not a logical operator. It's a comparison operator. Logical operators are (&&), (||), (!) Quote Link to comment Share on other sites More sharing options...
tapos Posted June 6, 2008 Share Posted June 6, 2008 tapos: (==) is not a logical operator. It's a comparison operator. Logical operators are (&&), (||), (!) ooops my bad thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.