SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Hybrid View
-
Apr 29, 2006, 05:01 #1
- Join Date
- Apr 2006
- Location
- Australia
- Posts
- 28
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
IF with multiple ORs in WHILE - Cant find correct syntax
I am a beginner with PHP MySQL and working on a basic Content Managment System for a 'few years old static site'. A table column repeats 2 cells with content in each followed by a spacer td that lines content up with other columns content. I am using 'while ($row = mysql_fetch_array($result))' to output the content and want to add the spacer td to every second loop. I have created and repeatedly modified an 'if statement with many ORs', that wont work. I have researched syntax models and all changes have not worked. Example of code I have tried is bellow. I am grateful for correct syntax and related advice.
Code:while ($row = mysql_fetch_array($result)) { echo '<tr><td height="25" width="325"><b>' . $row[update_text] . '</b></td> </tr>' ; if ($row[id]==3 || $row[id]==5 || $row[id]==7 || $row[id]==9){ echo '<tr><td height="5" width="325"></td></tr>' ; } endif; }
-
Apr 29, 2006, 05:19 #2
- Join Date
- Apr 2006
- Posts
- 23
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Something like this?
Code:$oddCounter = 0; while ($row = mysql_fetch_array($result)) { echo '<tr><td>.. row content ..</td></tr>'; if (!(++$oddCounter % 2)) { // Outputing separator echo '<tr><td>.. separator ..</td></tr>'; } }
-
Apr 29, 2006, 05:41 #3
- Join Date
- Apr 2006
- Location
- Australia
- Posts
- 28
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks for reply and help. I tried the code and it did not work. When I use the while loop minus either if statement output works, but content doesn't line up minus spacer. I have been working on code all day and this is the first time I have been unable to get things to work right away.
-
Apr 29, 2006, 06:01 #4
- Join Date
- Oct 2004
- Location
- Hackettstown, NJ
- Posts
- 418
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This is how I do it. If you want more columns just change the var at top.
PHP Code:$columns = 2;
if(mysql_num_rows($results)){
print "<table>";
$i = 0;
while($row = mysql_fetch_assoc($results)){
if(!($i%$columns))
print "<tr>";
print "<td>".$row['name']."</td>";
if($i%$columns == $columns-1)
print "</tr>";
$i++;
}
if($i%$columns != 0){
for($x=($i%$columns);$x<$columns;$x++)
print "<td> </td>";
print "</tr>";
}
print "</table>";
}
-
Apr 29, 2006, 07:59 #5
- Join Date
- Apr 2006
- Location
- Australia
- Posts
- 28
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Fixed
I have got my original code to work. I overlooked that I was not previewing from my server. Thanks for great responces.
-
Apr 29, 2006, 09:15 #6
- Join Date
- Apr 2006
- Location
- Australia
- Posts
- 28
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks for code Eugene
I settled on your code Eugene. Alot crisper than mine!!! Thanks for help.
Bookmarks