0

I'm trying to create a while loop that will go through my query results and output my php and html. I'm trying to figure out what is the best way to output the following code.

I tried to echo the link and because the php is inside it I was getting multiple errors.

I've tried google searching but I don't really know what to put down to start finding the answer.

 <?php
 while ($row = mysql_fetch_assoc($result)) {
     <a href='#' data-reveal-id="echo $row["name"]" data-animation="none">
         <div class="grid_3">
             <p id="contexttitle"> echo $row[]; <span style="float:right;"> echo $row[]; </span> </p>
             <p id="accesssubmenu">Last Update: echo $row[]; </p>
         </div>
     </a> 
     <div id="echo $row[];" class='reveal-modal'>
         <h1> echo $row[]; </h1>
         <p>  echo $row[]; </p>
         <p4>Last Update: echo $row[]; </p4>
         <a class="close-reveal-modal">&#215;</a>
     </div>
 }
 ?>
0

2 Answers 2

1

replace your code with this:

<?php
    while ($row = mysql_fetch_assoc($result)) {
?>
<a href='#' data-reveal-id="<?php echo $row["name"] ?>" data-animation="none">
    <div class="grid_3">
        <p id="contexttitle"><?php echo $row[];?>
            <span style="float:right;"><?php echo $row[];?> </span> 
        </p>
        <p id="accesssubmenu">Last Update:<?php echo $row[];?> </p>
    </div>
</a> 
<div id="<?php echo $row[];?>" class='reveal-modal'>
    <h1><?php echo $row[]; ?></h1>
    <p><?php echo $row[]; ?> </p>
    <p4>Last Update:<?php echo $row[];?> </p4>
    <a class="close-reveal-modal">&#215;</a>
</div>

<?php }  ?>

Please specify field (column name) in $row[] .

For example $row["field_name_here"] .

Don't leave blank $row[].

Sign up to request clarification or add additional context in comments.

5 Comments

I love you, I was going nuts trying to figure this out I never thought that you could separate the loop like that and it makes perfect sense! Thanks SOOO much!!!!
Do you know if these is a way I can allow spaces and dots (.) in my reveal model? If I have them it doesn't work. If not thank you again! I just didn't want to make another question for such a small thing.
where you want space & dot please elaborate
In the SQL database I have some options such as "StackOverflow.com" (so there's a dot) and then another that would be "A Website" but when I try to use those the reveal-id popup doesn't work. I'm searching for an answer just thought I'd throw this in here in case you were familiar with it. If I change the spaces and dots to _ it works fine which is ok with me for now. If it helps I have a js fiddle that kinda shows what I'm talking about jsfiddle.net/W6zYA/1
if you are trying these option as "id" or "class" then its not work because if we use space between two words its indicating two different class. hope you understand
0

You can't directly output HTML in PHP without either using a print/echo statement, or closing the PHP segment. For example, you can echo a list like this:

<?php
echo '<ul>'
for($x=0;x<$10;$x+=1){
    echo "<li>$x</li>";
}
echo '</ul>';
?>

or you can close the php and write HTML directly:

<ul>
<?php for($x=0;$x<10;$x++){ ?>
   <li><?php echo $x; ?></li>
<?php } ??
</ul>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.