Hi so I am fairly new at getting into php and sql so this might be a very simple problem but I cant seem to figure it out.
I need to pull all the data from our staff table and then list it on our page. This would be very simple if it was just going down the page but for every 4 staff members that are pulled I need to close the div and reopen a new div and continue pulling the members. I'm not sure on how to code this and still be able to open and close the divs. Here is what I have right now which just pulls the same staff member 4 times and then moves on to the next staff member in the next row. Thanks in advance for the help!
<?php
$sql = mysql_query("SELECT * FROM staff ORDER BY id");
$array = array();
while ($row = mysql_fetch_assoc($sql)) { ?>
<div class="row staff-padding">
<div class="col-sm-3">
<img src="<?php echo $row[img_link]; ?>" class="img-thumbnail img-staff"/>
<h4><?php echo $row[name]; ?></h4>
<p><?php echo $row[job_title]; ?><br />
<span class="glyphicon glyphicon-phone-alt"></span> <?php echo $row[phone_number]; ?> <br />
<span class="glyphicon glyphicon-envelope"></span> <a href="<?php echo $row[email]; ?>"><?php echo $row[email]; ?></a><br />
</p>
</div>
<div class="col-sm-3">
<img src="<?php echo $row[img_link]; ?>" class="img-thumbnail img-staff"/>
<h4><?php echo $row[name]; ?></h4>
<p><?php echo $row[job_title]; ?><br />
<span class="glyphicon glyphicon-phone-alt"></span> <?php echo $row[phone_number]; ?> <br />
<span class="glyphicon glyphicon-envelope"></span> <a href="<?php echo $row[email]; ?>"><?php echo $row[email]; ?></a><br />
</p>
</div>
<div class="col-sm-3">
<img src="<?php echo $row[img_link]; ?>" class="img-thumbnail img-staff"/>
<h4><?php echo $row[name]; ?></h4>
<p><?php echo $row[job_title]; ?><br />
<span class="glyphicon glyphicon-phone-alt"></span> <?php echo $row[phone_number]; ?> <br />
<span class="glyphicon glyphicon-envelope"></span> <a href="<?php echo $row[email]; ?>"><?php echo $row[email]; ?></a><br />
</p>
</div>
<div class="col-sm-3">
<img src="<?php echo $row[img_link]; ?>" class="img-thumbnail img-staff"/>
<h4><?php echo $row[name]; ?></h4>
<p><?php echo $row[job_title]; ?><br />
<span class="glyphicon glyphicon-phone-alt"></span> <?php echo $row[phone_number]; ?> <br />
<span class="glyphicon glyphicon-envelope"></span> <a href="<?php echo $row[email]; ?>"><?php echo $row[email]; ?></a><br />
</p>
</div>
</div>
mysql_queryinterface. It's awful and is being removed in future versions of PHP. A modern replacement like PDO is not hard to learn. A guide like PHP The Right Way can help explain best practices. Always be absolutely sure your user parameters are properly escaped or you will have severe SQL injection bugs.