superclean Posted March 16, 2013 Share Posted March 16, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/275743-how-to-create-s-separate-div-for-every-mysql-resultwithout-php-foreach/ Share on other sites More sharing options...
jazzman1 Posted March 16, 2013 Share Posted March 16, 2013 (edited) <?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>'; ?> Edited March 16, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/275743-how-to-create-s-separate-div-for-every-mysql-resultwithout-php-foreach/#findComment-1419024 Share on other sites More sharing options...
Barand Posted March 17, 2013 Share Posted March 17, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/275743-how-to-create-s-separate-div-for-every-mysql-resultwithout-php-foreach/#findComment-1419066 Share on other sites More sharing options...
jcbones Posted March 17, 2013 Share Posted March 17, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/275743-how-to-create-s-separate-div-for-every-mysql-resultwithout-php-foreach/#findComment-1419084 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.