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>'; } } ?> Link to comment https://forums.phpfreaks.com/topic/108997-condition-help/ 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 } Link to comment https://forums.phpfreaks.com/topic/108997-condition-help/#findComment-559160 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'] == "") { Link to comment https://forums.phpfreaks.com/topic/108997-condition-help/#findComment-559164 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 (&&), (||), (!) Link to comment https://forums.phpfreaks.com/topic/108997-condition-help/#findComment-559168 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 Link to comment https://forums.phpfreaks.com/topic/108997-condition-help/#findComment-559192 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.