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
https://forums.phpfreaks.com/topic/36965-solved-for-statment/
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
https://forums.phpfreaks.com/topic/36965-solved-for-statment/#findComment-176462
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.