the_oliver Posted February 4, 2007 Share Posted February 4, 2007 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 Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 4, 2007 Share Posted February 4, 2007 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. Quote Link to comment Share on other sites More sharing options...
the_oliver Posted February 4, 2007 Author Share Posted February 4, 2007 Ok, so i use something like: while($query_data = pg_fetch_array($result)) {} Would is still need the for() statment or just put { echo $data["num"]; echo $spacer; } ? Quote Link to comment Share on other sites More sharing options...
the_oliver Posted February 4, 2007 Author Share Posted February 4, 2007 Scrap that, got it! Many Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.