RE: MySQL Array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It's not incrementing $c. Start out with $c=0;, then Add $c++; after
the while line (not after the whole while statement).

Like this:
 $c = 0;	
 print("<tr>");
 while($row = mysql_fetch_array($dbResult))
        $c++;
 	{
 	print("<td>{$row['server_name']}</td>");
     	if(($c % 4) == 0) 
 		{ 
 		print("</tr><tr>"); 
		}
 	}

You'll also need a print("</tr></table>") at the end, but I assume
you knew that...

--- "Chevalier, Arthur" <arthurc@scn.spawar.navy.mil> wrote:
> You are right about my query.  I am only pulling down one column. 
> 
> As you guys can probably tell I am pretty inexperienced with this. 
> I tried
> what you said and still got the same results.
> 
> Here are snippets of my code and maybe this will depict what I am
> doing
> wrong:
> 
> After creating the connection:
> 
> $query = "select server_name from servers where midtier =
> '$server'";
> $dbResult = mysql_query($query,$dblink);  
> 
> $c = 1;	
> print("<tr>");
> while($row = mysql_fetch_array($dbResult))
> 	{
> 	print("<td>{$row['server_name']}</td>");
>     	if(($c % 4) == 0) 
> 		{ 
> 		print("</tr><tr>"); 
> 		}
> 	}
> 
> 
> 
> -----Original Message-----
> From: 1LT John W. Holmes [mailto:holmes072000@charter.net] 
> Sent: Thursday, December 05, 2002 3:26 PM
> To: Ryan Jameson (USA); Art Chevalier; php-db@lists.php.net
> Subject: Re:  MySQL Array
> 
> I think he meant that he is only pulling one column, i.e. "field1"
> with each
> mysql_fetch_array and he wants that in four columns.
> 
> $c = 1;
> echo "<tr>";
> while($ar = mysql_fetch_array($result))
> {
>   echo "<td>{$ar['field1']}</td>";
>   if(($c % 4) == 0) { echo "</tr><tr>"; }
> }
> 
> You'll have to account for incomplete rows and clean up the output,
> but
> hopefully that gives you an idea.
> 
> ---John Holmes...
> 
> ----- Original Message -----
> From: "Ryan Jameson (USA)" <RJameson@usa.ibs.org>
> To: "Art Chevalier" <arthurc@scn.spawar.navy.mil>;
> <php-db@lists.php.net>
> Sent: Thursday, December 05, 2002 3:05 PM
> Subject: RE:  MySQL Array
> 
> 
> while ($ar = mysql_fetch_array($rs))
>   echo "<tr><td>".
> $ar['field1']."</td><td>".$ar['field2']."</td></tr>";
> 
> 
> Make sense?
> 
> -----Original Message-----
> From: Art Chevalier [mailto:arthurc@scn.spawar.navy.mil]
> Sent: Thursday, December 05, 2002 12:44 PM
> To: php-db@lists.php.net
> Subject:  MySQL Array
> 
> 
> Hello,
> 
> I am pulling one column out of a MySQL table in an array.  I want
> to place
> each element into a HTML table 4 rows across.  I am currently doing
> this
> with the mysql_fetch_array() function. How can I pull out 4 array
> elements
> in one pass through a while loop?
> 
> Thanks
> 
> Art Chevalier
> 
> 
> 
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


=====
Mark Weinstock
mark_weinstock@yahoo.com
***************************************
You can't demand something as a "right" unless you are willing to fight to death to defend everyone else's right to the same thing.
-Stolen from the now-defunct Randy's Random mailing list.
***************************************

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux