Re: MySQL and Array's REALLY simple question but I'm not GETTING it .. Ugh..
| From: | Brad Bonkoski | Date: | Fri, 06 Sep 2002 20:44:39 +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-115571@lists.php.net to get a copy of this message | ||
It doesn't matter what variables you assign to "fetch" the data, one of the effects of mysql_fetch_array() is to increment the database result variable. It does this without you even knowing it. check out the mysql_data_seek() function to see how you can make the adjustments yourself. i.e. mysql_data_seek($result, 0) would set you back at the beginning, record one.
-Brad
Steve Gaas wrote:
OK, this works.. This is wonderful.. But I don't get it.. I assigned two separate variables to that array function.. I don't understand why this works now, but thanks a lot for the help. I hope I don't inadvertently run into this again... -steve $sql2 = mysql_connect("localhost", "eweb", "dbfun") or die("Could not connect using default username and password LINE 14 <BR>"); mysql_select_db("actionregs", $sql2); $top_level = mysql_query("SELECT * FROM williams", $sql2) or die("Could not do query sql1 to find username. Link might not have been made. What's up? LINE 19 <BR>"); // $sql2_results = mysql_fetch_array($top_level); $query_sql2_rows = mysql_num_rows($top_level); $rows = 0; echo $query_sql2_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>"; -----Original Message----- From: Brad Bonkoski [mailto:bbonkosk@tampabay.rr.com] Sent: Friday, September 06, 2002 3:34 PM To: Steve Gaas Cc: php-general@lists.php.net Subject: Re: [PHP] MySQL and Array's REALLY simple question but I'm not GETTING it .. Ugh.. 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 thisisthe 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 Iwantin 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.