Re: Why dosen't this work!!!(No parse errors etc)

From: Date: Wed, 19 Jun 2002 13:22:46 +0000
Subject: Re: Why dosen't this work!!!(No parse errors etc)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-102923@lists.php.net to get a copy of this message
First of all, the query looks a bit strange. Are you sure you you do want year <= $year and not year = $year ??? But that is not related to the problem I think ;-) Do you get no result at all. I think that the first row is lost from the result. This due to the fact that you do not proces the first $row = mysql_fetch_array($result) that is before the for-loop Another strange thing is that you use a for loop that has a fixed ending $i <5 It should be $i < $num_results Or not?? Instead of using a for-loop, you could consider: $result=mysql_query($query); while($row=mysql_fetch_array($result)) { echo '<p>'; echo $row['qoute']; echo '</p><p align="right"><i>-- '; echo $row['author']; echo '</i></p><hr noshade>'; } good luck René webmaster@tececo.com wrote:
I have the following code: $week = date("W"); $year = date("Y"); echo "$week<br>$year";
    $query = "SELECT * FROM qoutes WHERE year <= $year AND week <= $week";
    $result = mysql_query($query);
    $row = mysql_fetch_array($result);
    $num_results = mysql_num_rows($result);
       for ($i=0; $i <5; $i++)
     {
      $row = mysql_fetch_array($result);
echo '<p>'; echo $row['qoute']; echo '</p><p align="right"><i>-- '; echo $row['author']; echo '</i></p><hr noshade>'; It returns nothing... Why? Here is a SQL dump from the table qoutes. # phpMyAdmin MySQL-Dump # http://phpwizard.net/phpMyAdmin/ # # Host: 216.89.24.247 Database : co2busters # -------------------------------------------------------- # # Table structure for table 'qoutes' # CREATE TABLE qoutes ( id int(9) unsigned NOT NULL auto_increment, week int(2) DEFAULT '0' NOT NULL, year int(4) DEFAULT '0' NOT NULL, qoute text NOT NULL, author varchar(200) NOT NULL, PRIMARY KEY (id) ); # # Dumping data for table 'qoutes' # INSERT INTO qoutes VALUES ( '1', '25', '2002', 'The supreme reality of our time is ...the vulnerability of our planet..', '- John F. Kennedy (1917-1963)<br>Thirty-fifth U.S. President<br>Speech 28, June 1963'); INSERT INTO qoutes VALUES ( '2', '26', '2002', 'Nature shows us only surfaces, but she is a million fathoms deep.', 'Ralph Waldo Emerson (1803-1882)<br>Major American Author, Philosopher &amp; Poet'); I have done this function earliar in the page(It works elsewhere so I don't believe connecting to the database is the problem, The user and password have been replaced with *'s for obvious security reasons) function co2busters_open_db(){ $link = mysql_pconnect("216.89.24.247", "**********", "**********") or die("Could not connect"); mysql_select_db("co2busters") or die("Could not select database"); } I hope someone could shed some light onto this. Goodnight... JJ Harrison webmaster@tececo.com <mailto:webmaster@tececo.com> www.tececo.com <http://www.tececo.com>


« previous php.general (#102923) next »