Solved

Why do these values not display the same way every time?

Posted on 2014-01-09
7
195 Views
Last Modified: 2014-01-09
The page in question is https://www.countryshowdown.com/new_map.php. When you pass your mouse over Nevada, you'll get a list of four radio stations. The problem is the way in which they're displayed. Instead of there being another station displayed to the right of KJRC, there's a blank cell. Now hover over Oklahoma. Perfect! No empty cells. Why do I have an empty cell over Nevada? You see the same thing in North Carolina.

I've gone out to the database and there's nothing obvious there, as far as a flaw in the data. There's just something about the way those two queries are running where I'm getting a cell and then a </tr></tr>.

Here's my code:

$allie = "select station_name from dbo_radio_stations where state_id='$bruce_row[state_id]'";
	$allie_query=mysqli_query($cxn, $allie);
		if(!$allie_query)
		{
		$whatever=mysqli_errno($cxn).': '.mysqli_error($cxn);
		die($whatever);
		$count++; // increment count
		}
		?>
<table style='width:100px; border-spacing: 1px; border-collapse: separate;'><tr>
<?php while($allie_row=mysqli_fetch_assoc($allie_query))
{
$count++; // increment count
extract($allie_row);
?>
<td class='station'><?php echo stripslashes($allie_row['station_name']);?></td><?php
	if ($count % $maxcols == 0)
	 { // if modulus of count is = 0 then end row
	echo "</tr><tr>"; 
	 }
}
if ($count)
	{ // data exists
	 $fill = ($count % $maxcols); // current column
	if ($fill){ // if not last column already fill in blank columns
	for ($i = $fill; $i <= ($maxcols -1); $i++){
	echo "<td>&nbsp;</td>";
	}
	echo "</tr>";
	 }
	 echo "</table>";
	}
?>

Open in new window


What am I missing?
0
Comment
Question by:brucegust
  • 4
  • 3
7 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39769069
This is your code
<tr><td class='station'>KRJC</td></tr><tr><td class='station'>KOWA</td><td class='station'>KIXW/KIXF</td></tr><tr>

KRJC is on its own row then you start a new row with KOWA
0
 
LVL 58

Expert Comment

by:Gary
ID: 39769092
What is the value of maxcols
0
 

Author Comment

by:brucegust
ID: 39769120
Yo, Gary! The value of my maxcols is 2. The code that you refer to above is correct with the exception that it should be:

<tr><td class='station'>KRJC</td><td class='station'>KOWA</td><td class='station'>KIXW/KIXF</td></tr><tr>

...in other words, two columns and then a new row. In some instances, I'm getting a new row after only one cell / column and I can't figure out why.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39769183
Is your counter starting at 0

Not really sure
Add an echo
echo $count."-".$maxcols;
if ($count % $maxcols == 0)
0
 

Author Comment

by:brucegust
ID: 39769222
It is. But you made me just think of something. The $count is is defined at the top of the page. Is it possible that after each iteration of the code, I need to reset the count? I'm smelling there, Gary, what do you think?
0
 
LVL 58

Expert Comment

by:Gary
ID: 39769239
Me thinks you've hit the nail on the head - the echo would show the counter is not what it should be.
0
 

Author Comment

by:brucegust
ID: 39769284
That did it!

Thank you, sir!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question