Re: First record not diplaying

From: Date: Mon, 22 Dec 2008 15:51:22 +0000
Subject: Re: First record not diplaying
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-284969@lists.php.net to get a copy of this message
so the correct way to do this is remove the $row_rsSearch = mysql_fetch_assoc($rsSearch); from my recordset query code. Thank you SanTa -- - Gary Maddock-Greene ""Sándor Tamás (HostWare Kft . )"" <sandortamas@hostware.hu> wrote in message news:DBB55D182B624F26BE7F5125E592D32D@STgepe... > Yes, the error is here. > > You get the record count with a mysql_fetch_assoc(), which reads the first > record, and then step onto the next one. So the first record's datas will > disappear at the next mysql_fetch_assoc() line (which can be found in your > while loop). > > You should NOT fetch the first record, unless you fetch it in a variable > to process datas at a later time. > > SanTa > > > ----- Original Message ----- > From: "Gary Maddock-Greene" <gmg@maddock-greene.co.uk> > To: <php-general@lists.php.net> > Sent: Monday, December 22, 2008 3:49 PM > Subject: Re: [PHP] First record not diplaying > > >> Thanks Dan, >> >> So my error is here? >> $colname_rsSearch = "-1"; >> if (isset($_GET['product_name'])) { >> $colname_rsSearch = $_GET['product_name']; >> } >> mysql_select_db($database_sondia_lighting, $sondia_lighting); >> $query_rsSearch = sprintf("SELECT * FROM products WHERE product_name LIKE >> %s", GetSQLValueString("%" . $colname_rsSearch . "%", "text")); >> $rsSearch = mysql_query($query_rsSearch, $sondia_lighting) or >> die(mysql_error()); >> $row_rsSearch = mysql_fetch_assoc($rsSearch); >> $totalRows_rsSearch = mysql_num_rows($rsSearch); >> >> -- >> - Gary Maddock-Greene >> ""Dan Shirah"" <mrsquash2@gmail.com> wrote in message >> news:a16da1ff0812220635j6a77c35ga2e74588671dc300@mail.gmail.com... >>> > >>>> Hi, I seem to have a bug in my code but can't see why. My first >>>> record >>>>>> does >>>>>> not display when I run a search. Can anyone spot what I have done >>>>>> wrong? >>>>>> Thanks >>>>>> >>>>>> if (0 == $totalRows_rsSearch) { >>>>>> echo "<h3>Sorry no products were found</h3>"; >>>>>> } else { >>>>>> echo "<h3>Please click on a product for further information.</h3>"; >>>>>> while ($row_rsSearch = mysql_fetch_assoc($rsSearch)){ >>>>>> echo "<div class=\"productitem\"><img src=\"products". >>>>>> $row_rsSearch['product_image']."\"> >>>>>> >>>>>> - Gary Maddock-Greene >>>>>> >>>>> >>>>> Is this another one of your classes? I see your email address links >>>>> to a >>>>> web page created for a class. >>>>> >>>>> Without the rest of the code (the code above what you have placed) and >>>>> the >>>>> end of the echo line you have provided, all any of us can do is a >>>>> guess. >>>>> >>>>> However one thing to note, this list was not created to help you with >>>>> your >>>>> homework and with the previous postings you have written, it is >>>>> pointedly >>>>> answering different places you have stumbled in your work and haven't >>>>> checked your book, the online resources, or a TA. >>>>> >>>>> Wolf >>>> >>>> >>> Like Wolf said...we need more code :) >>> >>> My "guess" would be that you probably have the default value of your row >>> count set to start at 1...but the results of an array start at >>> 0...therefore >>> your first row is being cutoff? >>> >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >

« previous php.general (#284969) next »