Jump to content

How to create s separate div for every MySQL result(without php foreach)


superclean

Recommended Posts

Hello guys!I'm building a video search engine and i need to create a separate div for every MySQL result.But instead,i get all the result into one single div.

<?php
$sql=mysql_query("SELECT*FROM videos WHERE User='$nemo'");
while($row=mysql_fetch_array($sql,MYSQL_ASSOC)){
$name=$row['Name'];
echo '<div id="found"><h1>'.$name.'</div></h1>';
}?>

Thanks

 

 


<?php

$sql=mysql_query("SELECT*FROM videos WHERE User='$nemo'");
 
$name = array();


while($row=mysql_fetch_array($sql,MYSQL_ASSOC)){

$name[]=$row['Name'];

}
// you can use a loop to find all indexes in that array
// example
echo '<div id="found"><h1>'.$name[0].'</div></h1>';
echo '<div id="found"><h1>'.$name[1].'</div></h1>';
?>
 

Hello guys!I'm building a video search engine and i need to create a separate div for every MySQL result.But instead,i get all the result into one single div.

 

<?php
$sql=mysql_query("SELECT*FROM videos WHERE User='$nemo'");
while($row=mysql_fetch_array($sql,MYSQL_ASSOC)){
$name=$row['Name'];
echo '<div id="found"><h1>'.$name.'</div></h1>';
}?>
Thanks

Correctly nesting your HTML elements may help. The h1 element should be inside the div, not overlapping.

You should also have unique id names.  If you are only using the id for styling, then use a class.  If you are using it for an anchor or other location sourcing, make the names unique.

 

http://www.w3.org/TR/html401/struct/global.html#h-7.5.2

 

id = name[CS]

This attribute assigns a name to an element. This name must be unique in a document.
class = ctype-data[CS]
This attribute assigns a class name or set of class names to an element. Any number of elements may be assigned the same class name or names. Multiple class names must be separated by white space characters.
 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.