Re: MySQL and Array's REALLY simple question but I'm not GETTING it .. Ugh..
| From: | Brad Bonkoski | Date: | Fri, 06 Sep 2002 20:34:08 +0000 |
| Subject: | Re: MySQL and Array's REALLY simple question but I'm not GETTING it .. Ugh.. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-115567@lists.php.net to get a copy of this message | ||
Well, when you run the command:
$sql2_results = mysql_fetch_array($top_level);
The first time, it automatically increments the result...
so you fetch the data bu do nothing with it...
so when you get to your loop, you are already at the second entry in your database..
So, remove the first instance of that and see how it works..
HTH
-Brad
Steve Gaas wrote:
Can anyone tell me what's wrong with my code? All I get output from this is the LAST row of data from my Database. There are 2 rows, how do I make it pull data from all of the rows? It's not going through the loop like it should.... I need to be able to tell the mysql_fetch_array which row I want in each it iteration of the for loop. The For loop increments counter, but there is no syntax to add $counter to the result_type. The same goes with fetch_row... What am I forgetting!!?? I know it's something simple ******* $sql2 = mysql_connect("localhost", "eweb", "dbfun") or die("Could not connect <BR>"); mysql_select_db("actionregs", $sql2); $top_level = mysql_query("SELECT * FROM williams", $sql2) or die("Could not do query <BR>"); $sql2_results = mysql_fetch_array($top_level); $query_sql2_rows = mysql_num_rows($top_level); echo $query_sql2_rows; // echo's 2 rows print "<table style=\"font-family:Verdana; font-size:10pt\" border=0 cellpadding=4 width=90%>"; print "<tr bgcolor=\"#c0c0c0\"><th width=50>Action ID</th><th width=100>Owner</th><th width=250>Technology</th><th>Summary</th></tr>"; for ($counter=0; $counter < $query_sql2_rows; $counter++) { $tabledata = mysql_fetch_array($top_level); echo "<td>$tabledata[0]</td>"; echo "<td>$tabledata[6]</td>"; echo "<td>$tabledata[2]</td>"; echo "<td>$tabledata[3]</td>"; echo "</tr>"; } print "</table>"; Thanks.