0

I have the following code.

<?php if ( $showdata['venue'] == "Brean Sands" ) {echo "<div class=\"gigpress-related-park\">"; echo $showdata['date_long']; echo $showdata['venue']; echo "</div>"; } ?>
<?php if ( $showdata['venue'] == "Camber Sands" ) {echo "<div class=\"gigpress-related-park\">"; echo $showdata['date_long']; echo $showdata['venue']; echo "</div>"; } ?>
<?php if ( $showdata['venue'] == "Pakefield" ) {echo "<div class=\"gigpress-related-park\">"; echo $showdata['date_long']; echo $showdata['venue']; echo "</div>"; } ?>
<?php if ( $showdata['venue'] == "Prestatyn Sands" ) {echo "<div class=\"gigpress-related-park\">"; echo $showdata['date_long']; echo $showdata['venue']; echo "</div>"; } ?>
<?php if ( $showdata['venue'] == "Southport" ) {echo "<div class=\"gigpress-related-park\">"; echo $showdata['date_long']; echo $showdata['venue']; echo "</div>"; } ?>

This pulls the information from my db just fine, but I need it to loop, or repeat so that multiple dates appear for each venue. There are multiple dates for each venue in the db, but as the code is, it only returns the value for the first date. I need the others to appear as well.

How do I get this code to loop while looking at only one venue and pull all dates, then end?

2
  • how do you fetch the value from db? show us the code. Commented Jun 28, 2012 at 12:08
  • The Values are fetched here pastebin.com/bfy1Cmug Commented Jun 28, 2012 at 12:17

2 Answers 2

2
$query = mysql_query("the query");
while($showdata = mysql_fetch_assoc($query)) {
  put your code here
}

So you run the query to get all database records you want, then you loop through assigning the row to $showdata. This will then process everything inside the loop for every row it returns from the database query

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

7 Comments

Just use PDO or mysqli_* instead of mysql_*
I understand all of this, except the query. What do you mean? pastebin.com/bfy1Cmug I believe that is my query, it then include_once related, which contains the above code.
@PLB: thats an alternative, but not a direct solution. A loop would still be required whether you use PDO or mysqli, they are just alternative ways of interfacing with the data store.
@Lee I've suggested using pdo or mysqli_* only for security purposes.
@PLB: each to their own i guess. I have my own way and you have yours. However a little bit of knowledge can hurt sometimes. If mysqli is used incorrectly it can be insanely less secure and compromise a system far worse. i.e. the single biggest issue with mysqli (which is also its strength if you do things properly) is that it allows multiple sql statements. But as i say, we all have our own approach to a problem
|
0

assuming you use mysql_ function to fetch values from db. here is what you should do.

$query = mysql_query('SELECT QUERY');
while($showdata = mysql_fetch_assoc($query)) {
    echo "<div class=\"gigpress-related-park\">" . $showdata['venue'] . $showdata['venue'] . "</div>";
}

however it would be better of using PDO or MySQLi instead of using mysql_.

1 Comment

I believe my values are fetched by the following pastebin.com/bfy1Cmug which then loads the above script through "related"

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.