Layout of mySQl query

This is a discussion on Layout of mySQl query within the PHP Language forums, part of the PHP Programming Forums category; Well thanks a lot man! Only thing i cannot seem to grasp yet is that !$column is the first, and ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-11-2004
knoak
 
Posts: n/a
Default Layout of mySQl query

Well thanks a lot man!
Only thing i cannot seem to
grasp yet is that !$column is the first, and then
you close it when it's not the first anymore.
To me this would seem like it would only give one collumn.

Apparently i'm mistaken. But why? :s

Greetings




Pedro Graca wrote:

[Why didn't you quote the previous posts?]
[Yes, I know Google groups suck]

knoak wrote:
> Yes, that works great! Thanks a bunch!
> Too bad i don't understand this (yet) completely...


[previous posts pasted back in]

> $result = mysql_query("SELECT * FROM datatable WHERE item=$searchterm
> ORDER BY item ASC",$db);


## start the table
echo '<table class="search_result" summary="search result">';

## initialize control variable
## $control will either be 0 or 1
## 0 means we're about to output the first column
## 1 means we're about to output the second column
$column = 0;

## for every record selected
while ($row = mysql_fetch_array($result)) {

## start a table row if it is the first column
if (!$column) echo '<tr>';
## print the data
echo '<td>', $row['whatever'], '</td>';
## end the row if it is not the first column
if ($column) echo '</tr>';

## swap between 1 and 0 every time this line executes
$column = !$column;
}

## if there were an odd number of records selected we will
## be left with an empty last cell -- fill it
if ($column) echo '<td>(empty cell)</td></tr>';

## end the table
echo '</table>';

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Reply With Quote
  #2 (permalink)  
Old 12-12-2004
Pedro Graca
 
Posts: n/a
Default Re: Layout of mySQl query

knoak wrote:
> Only thing i cannot seem to
> grasp yet is that !$column is the first, and then
> you close it when it's not the first anymore.
> To me this would seem like it would only give one collumn.
>
> Apparently i'm mistaken. But why? :s


Open the row on the first column, close it on the second -- just like
you say :-)


Compare these two versions between themselves and my original version

with $column being 1 and 2: with $column being 0 and 1:


$column = 1; $column = 0
loop() { loop() {
if ($column == 1) echo '<tr>'; if ($column == 0) echo '<tr>';
echo '<td>...</td>'; echo '<td>...</td>';
if ($column == 2) echo '</tr>'; if ($column != 0) echo '</tr>';
$column += 1;
if ($column == 3) $column = 1; $column = 1 - $column;
} }

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB 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 09:38 AM.


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