Jump to content

[SOLVED] for statment


the_oliver

Recommended Posts

Hello,

 

Can someone tell me what im doing wrong hear?  The first value is printed but then just the spacer.  Eg. 937401 | | | | | |  when it should be 2345 | 234523 | 23452345 | and so on.

 

 

$query = "SELECT num FROM table WHERE id = '1'";
$result = pg_query($temp_pg_connection, $query);
$data = pg_fetch_array($result);
$entry_count = pg_num_rows($result);

$spacer = " | ";

if ($entry_count > 0)
                {
                for ($i=0; $i<$entry_count; $i++)
                        {
                        echo $data[$i];
                        echo $spacer;
                        }
                }                                                                               
                else
                {
                echo "no data apparently?";
                }

 

Many Thanks

Link to comment
Share on other sites

You select the first result, then try to access non existent rows in that result. You need to loop through the results using pg_fetch_array in a while loop - check the documentation page for pg_fetch_array, that will show you how to do this properly.

Link to comment
Share on other sites

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.