0

Not sure why this is giving me hell - but I am sure it is an easy fix, that I'm just not seeing.. ?

My query that shows 7 event logos that are upcoming..

[LOGO] [LOGO] [LOGO] [LOGO] [LOGO] [LOGO] [LOGO]

$query_Recordset3 = "SELECT id, event_type, event_type_2, event_name, event_logo,event_date FROM event_calendar WHERE review_live = 1 AND event_logo > '0' AND event_date >= CURDATE() ORDER BY event_date ASC LIMIT 7"; 

My little problem: If I have event without a logo.. so it shows just one or a couple instead of 7.

How it is now if there is two events with logos:

[LOGO] [LOGO] [x] [x] [x] [x] [x]

I am trying to come up with a way to show a default for the rest of my "logo images"

How I want it to look

[LOGO] [LOGO] [default] [default] [default] [default] [default]

Is my query not right or do I just need to do a fancy "do while" ??

Thanks my NINJAS!! Sorry if there is other do while and query questions.. i just didn't find exactly what i was looking for :-)

2
  • 2
    Well, you are looking for event_logo > '0', witch mean, you will always have a result there. How are you planning on determining, witch one is not real? Commented Dec 11, 2012 at 14:53
  • Good point, i was thinking about that as well. Commented Dec 11, 2012 at 15:15

2 Answers 2

2

Just count the number of rows you got and then fill up until you have 7 logos

<?php $query_Recordset3 = "SELECT id, event_type, event_type_2, event_name, event_logo,event_date FROM event_calendar WHERE review_live = 1 AND event_logo > '0' AND event_date >= CURDATE() ORDER BY event_date ASC LIMIT 7"; $result = $mysqli->query($query_Recordset3) or die(mysqli_error()); for ($i = 0; $row = $result->fetch_row(); $i++) { // process row, show logo } for (; $i < 7; $i++) { // show default } 
Sign up to request clarification or add additional context in comments.

2 Comments

Excellent! I will try right away, these both look promising!!
Got it finally!! This worked well -- thanks!! Now I know the process of a "for" loop!
2

Something like this:

$logocount = 7; while(/*fetch mysql result here*/) { //output a logo $logocount--; } echo str_repeat("Default logo here",$logocount); 

1 Comment

Alternatively, have a default value for the event_logo column and make the default value point to your default image ;-)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.