Looping problem?

This is a discussion on Looping problem? within the PHP General forums, part of the PHP Programming Forums category; require 'database.php'; $t_02 = "subnets"; $sql_subs = mysql_query("SELECT * FROM $t_02",$db)or die(mysql_error()); while(list($...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-06-2004
Jas
 
Posts: n/a
Default Looping problem?

require 'database.php';
$t_02 = "subnets";
$sql_subs = mysql_query("SELECT * FROM $t_02",$db)or
die(mysql_error()); while(list($id,$sub,$msk,$dns01,$dns02,$rtrs,$rnge )
= mysql_fetch_array($sql_subs)) {
$num = mysql_num_rows($sql_subs);
for($z = 0; $z < $num; $z++) {
$vlans[] = "subnet $sub<br>netmask $msk {<br>option domain-name-servers
$dns01, $dns02;<br>option routers $rtrs;<br>range $rnge;<br>}<br>"; }
}
// Write everything out formated...
echo $vlans[$z]<br />\n;

Right now it only pulling the last record???
Jas
Reply With Quote
  #2 (permalink)  
Old 01-07-2004
Calico Jack
 
Posts: n/a
Default Re: Looping problem?

Jas wrote:
> require 'database.php';
> $t_02 = "subnets";
> $sql_subs = mysql_query("SELECT * FROM $t_02",$db)or
> die(mysql_error());
> while(list($id,$sub,$msk,$dns01,$dns02,$rtrs,$rnge ) =
> mysql_fetch_array($sql_subs)) {
> $num = mysql_num_rows($sql_subs);
> for($z = 0; $z < $num; $z++) {
> $vlans[] = "subnet $sub<br>netmask $msk {<br>option
> domain-name-servers $dns01, $dns02;<br>option routers $rtrs;<br>range
> $rnge;<br>}<br>"; }
> }
> // Write everything out formated...
> echo $vlans[$z]<br />\n;
>
> Right now it only pulling the last record???
> Jas

Try this instead using the mysql_fetch_array function:

require "database.php";
$query = "SELECT * FROM subnets";
$result = mysql_query();
while ($row = mysql_fetch_array($result)) {
... all your array vars are in $row[];
}

--

-Calico Jack-
http://www.scriptsharks.com/

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:51 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0