Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
Draco_03
Forum Regular
Posts: 577 Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada
Post
by Draco_03 » Mon Dec 22, 2003 1:11 pm
mhhh i dunno why but my while just doesn't doesnt stop...
Code: Select all
$host = "you";
$user = "guess";
$pswd = "what";
mysql_select_db ("spanking_is_good");
$connect = mysql_connect($host, $user, $pswd)
or die("Could not connect: " . mysql_error());
$database = mysql_select_db('spanking_is_good')
or die(MySQL_Error());
$sql = "SELECT * FROM catalogue";
$result = mysql_query($sql) or die(MySQL_Error());
$row=0;
while($row <= mysql_num_rows($result)){
$get = mysql_fetch_row($result);
print "$get[0] : $get[1]<br />";
}
mysql_close($connect);
That output something like
Code: Select all
1 : www.i_like_to_be_spanked.com
:
:
:
etc
AVATAr
Forum Regular
Posts: 524 Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:
Post
by AVATAr » Mon Dec 22, 2003 1:14 pm
Increment $row in the wihle ($row++)
Draco_03
Forum Regular
Posts: 577 Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada
Post
by Draco_03 » Mon Dec 22, 2003 1:16 pm
..........
let's just say i never posted that
ty avatar
AVATAr
Forum Regular
Posts: 524 Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:
Post
by AVATAr » Mon Dec 22, 2003 1:34 pm
it happens
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Tue Dec 23, 2003 3:04 am
You could simplify this:
Code: Select all
$row = 0;
while($row <= mysql_num_rows($result)){
$get = mysql_fetch_row($result);
print "$get[0] : $get[1]<br />";
$row++;
}
to
Code: Select all
while ($row = mysql_fetch_row($result)) {
print $row[0].' : '.$row[1];
}
BTW, if you used [php_man]mysql_fetch_assoc[/php_man]() you could use the column names instead of having to remember in which order they are in the table. Displaying according to order in the table could cause a lot of problems if the table structure is changed.
Mac
Draco_03
Forum Regular
Posts: 577 Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada
Post
by Draco_03 » Tue Dec 23, 2003 9:20 am
Ty very much Twig