|
-
May 28th, 2007, 11:40 PM
#1
Thread Starter
WiggleWiggle
While Loop, CSS layout
Ok i have to do a while loop with mysql and what not, i can do that on my own, but the site is using CSS, and i dont know how i can display the info.
here is the code without the PHP:
Code:
<div class="left_side">
<div class="right_articles">
<p><img src="images1/image.gif" alt="Image" title="Image" class="image" /><b>Profile Name </b><br />
Summary of the featured profile. </p>
</div>
</div>
<div class="right_side">
<div class="right_articles">
<p><img src="images1/image.gif" alt="Image" title="Image" class="image" /><b>Profile Name </b><br />
Summary of the featured profile. </p>
</div>
</div>
The problem is the ' class="left_article" ' and ' class="right_article" '.
I am needing to get 2 records from the db and display them there.
hope i made myself clear enough
My usual boring signature: Something
-
May 29th, 2007, 09:34 AM
#2
Lively Member
Re: While Loop, CSS layout
Do the query before the html and break in with the variables:
PHP Code:
<?php
// assumed all connection and error handling....
$result = mysql_query('your query');
$row = mysql_fetch_row($result);
?>
<div class="left_side">
<div class="right_articles">
<p><img src="images1/image.gif" alt="Image" title="Image" class="image" /><b><?php echo $row[0]; ?> </b><br />
Summary of the featured profile. </p>
</div>
</div>
<div class="right_side">
<div class="right_articles">
<p><img src="images1/image.gif" alt="Image" title="Image" class="image" /><b><?php echo $row[0]; ?> </b><br />
Summary of the featured profile. </p>
</div>
</div>
I assumed you are returning one row with your query.
http://us.php.net/manual/en/function...-fetch-row.php
Just as well can use mysql_fetch_assoc:
http://us.php.net/manual/en/function...etch-assoc.php
-
May 29th, 2007, 11:10 AM
#3
Re: While Loop, CSS layout
if he's making a while loop, he is returning more than one row.
so, if you just have a left and right side, you can use a variable to indicate which side might be being used.
PHP Code:
<?php
$sql = "SELECT values FROM table WHERE 1 LIMIT 2";
$q = mysql_query($q);
$side = 0; //start on left side. left = 0; right = 1;
while($a = mysql_fetch_array($q)){
$class = ($side == 0) ? 'left' : 'right';
?>
<div class="<?php echo $class; ?>">
<div class="right_articles">
<?php echo $a['values']; ?>
</div>
</div>
<?php } ?>
-
May 29th, 2007, 01:36 PM
#4
Lively Member
Re: While Loop, CSS layout
Hard to say, based on the context of the html it doesn't seem like a while loop situation. I more assumed 2 columns and not records.
Good luck.
-
May 29th, 2007, 02:18 PM
#5
Re: While Loop, CSS layout
PHP provides an alternative syntax that makes inserting control structures into markup a breeze:
PHP Code:
<div class="right_side">
<?php foreach($right_articles as $article): ?>
<div class="right_article">
<p><?php echo $article['blahblah'] ?></p>
<!-- etc. -->
</div>
<?php endforeach; ?>
</div>
As ever, do all of your processing before outputting the markup; preferably, this should be done in separate code files.
-
May 29th, 2007, 06:02 PM
#6
Thread Starter
WiggleWiggle
Re: While Loop, CSS layout
i am using to to display 2 random records from the database. I will try Kows' code Think it might work.
My usual boring signature: Something
-
May 29th, 2007, 06:16 PM
#7
Thread Starter
WiggleWiggle
Re: While Loop, CSS layout
kows code worked. Thanks again kows
My usual boring signature: Something
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|