Jump to content

Recommended Posts

This is probably an easily solved problem, but I can't  figure it out...

Given the code:

<?#xml version="1.0" encoding="UTF-8"#
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.wc3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.wc3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <title>Music Never Stopped: Playlist</title>
    <link rel="stylesheet" type="text/css" href="stylesheets/playlist.css" />
    <meta content="">
    <style></style>
  </head>
  <body>
  <?php
  //turn on error reporting
  ini_set('display_errors', 'On');
  error_reporting(E_ALL | E_STRICT);

  //connect to database
  $con = mysql_connect("###","###","");
if (!$con){
  		die('Could not connect: ' . mysql_error());
  	}

mysql_select_db("###", $con);
//end connecting to database
?>
    <div id="masthead">
      <a href="index.html">
      <img src="images/logo.png" alt="###" />
      </a>
      <div id="logreg">
          <a href="dummylogin.html">Login</a>
  |
          <a href="dummyregister.html">Register</a>
      </div>
    </div>
    
    <div id="searchbox">
        <h1 class="search">search</h1>
        <input type="text" name="search" size="15" maxvalue="50" value="###" />
          <div id="results">
          <h1 class="search">results:</h1>
          <div id="results-box">
           <?php
          //start inital query with a listing of years -> songs played
          for($i=2009; $i<1959; $i--){
          	$result = mysql_query("SELECT * FROM songs WHERE artist == 'Ryan Adams'");
          	//debug
          	if(!$result){
          		echo "No Result!";
		}
		else{
			echo "Result!";
		}
          	if (mysql_num_rows($result) > 0) {
          		echo "Success! <br>";
		}
		else{
			echo "Failure! <br>";
		}
          	while($row = mysql_fetch_array($result)){
          		echo "<ol class=\"results-primary\">";
          		echo "<li>" . $i . "</li>";
          		echo "<li class=\"date\">" . $row['date'] . "</li>";
          		echo "<li class=\"song\" onmouseover=\"this.style.backgroundColor='yellow';\" onmouseout=\"this.style.backgroundColor='lightblue';\">" . $row['name'] . "</li>";
		}//end while
		echo "</ol>";
	}//end for
	?>
            <ol class="results-primary">
              <li>2000</li>
              <li>2001</li>
              <ol class="results-secondary">
                <li class="date">11-24-2001</li>
                <ol class="results-secondary">
                  <li class="set1">Set 1</li>
                  <?php
                  $result = mysql_query("SELECT * FROM songs");
                  while($row = mysql_fetch_array($result)){
				  echo "<li class=\"song\" onmouseover=\"this.style.backgroundColor='yellow';\" onmouseout=\"this.style.backgroundColor='lightblue';\">" . $row['name'] . "</li>";
  				  }
  				  ?>
                  
                  <li class="set2">Set 2</li>
                  
                  <li class="encore">Encore</li>
                  
                 </ol>
                <li class="date">12-31-2001</li>
              </ol>
              <li>2002</li>
              <li>2003</li>
            </ol>
          </div>
        </div>
      </div>
    
    <div id="activeplaylist">
      <table cellspacing="0">
        <caption>Active Playlist</caption>
        <thead>
          <tr>
            <th scope="column">Song</th>
            <th scope="column">Artist</th>
            <th scope="column">Date</th>
            <th scope="column">Location</th>
            <th scope="column">Extras</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td scope="row">Higgins ></td>
            <td>###</td>
            <td>2001-04-28</td>
            <td>Nokia Theater, New York, NY</td>
            <td>Comments, Others who like this Song</td>
          </tr>
          <tr class="coloralt">
            <td scope="row">You Should Be Glad</td>
            <td>###</td>
            <td>2004-06-22</td>
            <td>Red Rocks, Boulder, CO</td>
            <td>Comments, Others who like this Song</td>
          </tr>
        </tbody>
      </table>
    </div>

<!--    <div id="footer">
      <ul>
        <li><a href="Blog.html">Blog</a></li>
        <li><a href="About.html">About "Music Never Stopped"</a></li>
        <li><a href="contact.html">Contact Us!</a></li>
      </ul>
    </div>
    -->
    <?php
    mysql_close($con);//close mysql connection
    ?>
  </body>
</html>
  

 

Why is nothing displayed from the block:

<?php
          //start inital query with a listing of years -> songs played
          for($i=2009; $i<1959; $i--){
          	$result = mysql_query("SELECT * FROM songs WHERE artist == 'Ryan Adams'");
          	//debug
          	if(!$result){
          		echo "No Result!";
		}
		else{
			echo "Result!";
		}
          	if (mysql_num_rows($result) > 0) {
          		echo "Success! <br>";
		}
		else{
			echo "Failure! <br>";
		}
          	while($row = mysql_fetch_array($result)){
          		echo "<ol class=\"results-primary\">";
          		echo "<li>" . $i . "</li>";
          		echo "<li class=\"date\">" . $row['date'] . "</li>";
          		echo "<li class=\"song\" onmouseover=\"this.style.backgroundColor='yellow';\" onmouseout=\"this.style.backgroundColor='lightblue';\">" . $row['name'] . "</li>";
		}//end while
		echo "</ol>";
	}//end for
	?>

 

It seems like there should be some output...

Link to comment
https://forums.phpfreaks.com/topic/137836-not-seeing-echo-statement/
Share on other sites

What would you expect to be displayed if mysql_num_rows returned 0?

 

Being an old fogey, I'm not fully au fait with the latest bands in the hit parade, and have never heard of "Ryan Adams".... but I'm not that antiquated that I don't know the singer who did "Summer of '69", "She's Only Happy When She's Dancing", and some naff song for a bad Robin Hood film.

I might be confusing the two, or could you have made a typo?

you've used == in the WHERE, instead of the single =..

 

<?php
//start inital query with a listing of years -> songs played
for($i=2009; $i<1959; $i--){
	$result = mysql_query("SELECT * FROM `songs` WHERE `artist` = 'Ryan Adams'");
	//debug
	if(!$result){
		echo "No Result!";
	}
	else{
		echo "Result!";
	}
	if (mysql_num_rows($result) > 0) {
		echo "Success! <br>";
	}
	else{
		echo "Failure! <br>";
	}
	while($row = mysql_fetch_array($result)){
		echo "<ol class=\"results-primary\">";
		echo "<li>" . $i . "</li>";
		echo "<li class=\"date\">" . $row['date'] . "</li>";
		echo "<li class=\"song\" onmouseover=\"this.style.backgroundColor='yellow';\" onmouseout=\"this.style.backgroundColor='lightblue';\">" . $row['name'] . "</li>";
	}//end while
	echo "</ol>";
}//end for
?>

Thanks for the input guys,

 

@Mark Baker

What would you expect to be displayed if mysql_num_rows returned 0?

I would expect to see "Failure!"

as:

if (mysql_num_rows($result) > 0) {
         echo "Success! <br>";
      }
      else{
         echo "Failure! <br>";
      }

 

That's why I put in those if statements, to let me know if any result were coming back.

And yes, Ryan Adams is who I meant (really, really good country/rock, sad bastard music)

 

AND "Prince of Thieves" was awesome.

 

 

@RussellReal

I made those changes to the query and still no echo statements...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.