From: Ashley Sheridan on
On Wed, 2010-06-23 at 16:14 +0100, Mike Davies wrote:

> On Wed, 2010-06-23 at 09:09 -0400, Daniel Brown wrote:
> > Hold everything, Mike!
> >
> > On Wed, Jun 23, 2010 at 05:18, Mike Davies <mike(a)integrawebdesign.co.uk> wrote:
> > [snip!]
> > >
> > > <?php
> > > mysql_select_db($database_general, $general);
> > > $query_details = "SELECT * FROM news WHERE news_id = '$_GET[id]'";
> >
> > /**
> > * Above line is placed here so that we can be easily,
> > * deliberately, and permanently destroyed. Of course,
> > * I suppose we *could* avoid that by sanitizing the input.
> > * Perhaps mysql_real_escape_string() or something....
> > */
> >
> > > $details = mysql_query($query_details, $general) or die(mysql_error());
> > > $row_details = mysql_fetch_assoc($details);
> > > $totalRows_details = mysql_num_rows($details);
> > >
> > > mysql_select_db($database_general, $general);
> >
> > // You don't need to reconnect to the database between queries.
> > // Since you're using the same here as above, the same link is fine.
> >
> > > $query_thumbs = "SELECT * FROM news_thumbs";
> > > $thumbs = mysql_query($query_thumbs, $general) or die(mysql_error());
> >
> > // You don't need to tell mysql_query() which database to use every time
> > // either, when using the same database for queries.
> >
> > > $totalRows_thumbs = mysql_num_rows($thumbs);
> >
> > // Doesn't look like you use this --- at least in this code
> > snippet. Necessary?
> >
> > > $i = 1;
> >
> > // I'd lose the above line as well. You'll see why in a second....
> >
> > /** REPLACE THIS:
> > > while ($row_thumbs = mysql_fetch_assoc($thumbs)){
> > > $thumbsarray[$i] = $row_thumbs;
> > > $i++;
> > > }
> > **/
> >
> > // WITH THIS:
> > while($row_thumbs = mysql_fetch_assoc($thumbs)) {
> > $thumbsarray[] = $row_thumbs;
> > }
> >
> > > //print_r($thumbsarray);
> > > ?>
> >
> >
> > > This is exactly the same as the code which is working for the 'projects'
> > > pages.
> >
> > Okay. On the database to which you're connecting, use phpMyAdmin,
> > the MySQL CLI, or something other than this and run the following
> > query:
> >
> > SELECT * FROM news_thumbs;
> >
> > Is anything returned?
> >
> Nothing is returned for SELECT query as there is nothing in the table as
> yet. Perhaps this is the problem. Typically all projects would have an
> associated thumb image but all news items may not. Perhaps a thumb image
> is necessary to stop this warning? Should I change the code to allow for
> there being no thumb image, if so can you suggest how I might modify it?
>
> Thanks to everyone who has responded, it has been most useful.
>
> regards,
> Mike
> --
> Mike Davies
> Integra Web Design, Rhynie, By Huntly, AB54 4LS
> 01464 861535 www.integrawebdesign.co.uk
>
>


If you haven't in your code, then make sure you define $thumbsarray as
an array before you attempt to use it in the loop. This will have no
effect where rows are returned, but it will ensure an empty array exists
if your code expects it and there is no data in the database to populate
it.

Thanks,
Ash
http://www.ashleysheridan.co.uk


From: Daniel Brown on
On Wed, Jun 23, 2010 at 11:14, Mike Davies <mike(a)integrawebdesign.co.uk> wrote:
>>
> Nothing is returned for SELECT query as there is nothing in the table as
> yet. Perhaps this is the problem. Typically all projects would have an
> associated thumb image but all news items may not. Perhaps a thumb image
> is necessary to stop this warning? Should I change the code to allow for
> there being no thumb image, if so can you suggest how I might modify it?

With no rows returned, there's no array. The while() loop doesn't
even trigger there.

You could either add some dummy data, populate the rows, or adjust
the code like so:

<?php
if (isset($thumbsarray) && is_array($thumbsarray)) {
while (list($key, $value) = each($thumbsarray)) {
// ...
}
} else {
// There are no thumbs. Oh, my God, the horror! No thumbs!
}
?>

--
</Daniel P. Brown>
UNADVERTISED DEDICATED SERVER SPECIALS
SAME-DAY SETUP
Just ask me what we're offering today!
daniel.brown(a)parasane.net || danbrown(a)php.net
http://www.parasane.net/ || http://www.pilotpig.net/
From: Mike Davies on
On Wed, 2010-06-23 at 16:22 +0100, Ashley Sheridan wrote:
> On Wed, 2010-06-23 at 16:14 +0100, Mike Davies wrote:

> If you haven't in your code, then make sure you define $thumbsarray as
> an array before you attempt to use it in the loop. This will have no
> effect where rows are returned, but it will ensure an empty array
> exists if your code expects it and there is no data in the database to
> populate it.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>

Thanks Ash and to everyone else. I added :
$thumbsarray=array()

above the first instance and the warning no longer appears. Hopefully
nothing else will be affected.

Many thanks for all your time.

regards,
Mike
--
Mike Davies
Integra Web Design, Rhynie, By Huntly, AB54 4LS
01464 861535 www.integrawebdesign.co.uk

First  |  Prev  | 
Pages: 1 2 3
Prev: fetching DB entries
Next: Stripping Characters