Forum Moderators: coopster

Message Too Old, No Replies

First Record In mysql table not showing

First Record In mysql table not showing

         

ecnaralc

10:00 am on Oct 27, 2009 (gmt 0)

10+ Year Member



Hi!
I have a problem with the first record not showing in my form.
This is the code that pulls the data. Anyone know why this would not show all records.. any advice appreaciated.
The section number is 1 and so on
<?php
$result = $connector->query("SELECT * FROM articles1 ORDER BY section ASC");
$row = $connector->fetchArray($result);
if (mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_object($result))
{
?>

Tommybs

12:53 pm on Oct 27, 2009 (gmt 0)

10+ Year Member



Is there anyway you can share with us what $connector->fetchArray actually does? Although you are reassigning $result to $row. Are you 100% sure your mysql statement is correct? Have you tried running the query on its own in phpmyadmin and seeing if the results differ to your scripts?

eelixduppy

3:35 pm on Oct 27, 2009 (gmt 0)



$connector->fetchArray()
seems to be moving the marker in the records ahead by one. From what I can see here, there is no reason by be calling this function. If you want to use the object's method instead of
mysql_fetch_object
then you need to replace it with the former. It should look like this, then:


$result = $connector->query("SELECT * FROM articles1 ORDER BY section ASC");
if(mysql_num_rows($result) > 0)
{
while($row = $connector->fetchArray($result))
{

Try that...

ecnaralc

9:24 pm on Oct 27, 2009 (gmt 0)

10+ Year Member



Hello eelixduppy.
Okay, so the table i am working with only has four records, so is easy to see whats being output to the edit page. Each record can be edited, is what the purpose for the output.
With your code, it fills the form with 4 records, but no data, no id etc.
with my code it only outputs 3 records.

These are the records fields but there is nothing in them, just 4 sections of empty records.

<?php echo $row->sectionname; ?>
<?php echo $row->pid; ?>
<?php echo $row->id; ?>
<?php echo $row->title; ?>
<?php echo $row->menutitle; ?>
<?php echo $row->tagline; ?>

Hope this makes sense.
This is how it looks on original code
Section name Main
SectionID 1
Article ID 1
Title Home Page
Title Home
Tagline This is the home Page
Added
Last Updated
Edit Content

This is how it looks with your code...

Section name
SectionID
Article ID
Title
Title
Tagline
Added
Last Updated
Edit Content

Everything is empty ...

eelixduppy

12:22 am on Oct 28, 2009 (gmt 0)



I guess it's because you originally were using the object form. Just switch the function used and it should work"

$result = $connector->query("SELECT * FROM articles1 ORDER BY section ASC");
if (mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_object($result))
{

Try that...

ecnaralc

12:50 am on Oct 28, 2009 (gmt 0)

10+ Year Member



Wow! hey thanks man.. that worked - all records now showing