473,394 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

A Iittle code help with test for existing variables

I am trying to only show the charges if they are in the database..

I am querying a table for the subject information and also show the charges associated with each subject.

What I am trying to do with the code is to only show charges if they exist. I know I can do it with just showing the $charge1 fields but this is how I am attempting to do it.

Here is the page:
[html]
http://www.tnrcso.org/wanted.php
[/html]here is the php code[php]<?
include ("top.php");
include ("nav.php");
?>
<td width=75% valign=top>
<table border=0 width=100% class=leftMenutop1>
<td><span class='text'>
<p class='bodyHead1'>Roane County Sheriff's Office Most Wanted Fugitives</span></p>
<table border=0 width=99% class="addalert">
<td valign=top><img src='img/alert.gif' align=left></td>
<td><span class='text1'>These fugitives should be considered ARMED and DANGEROUS! NEVER attempt to apprehend a fugitive yourself.
If you have information on the location of any of these fugitives, contact the Roane County Sheriff's Office at (865) 717-4700 or dial 911</td></table>
<br>
<?
include('db.php');
echo "<table border=0 width=99% cellpadding=2 cellspacing=0 class='pbox14'>";
$query1 = mysql_query("SELECT * FROM `wanted` ORDER BY `id`");
while ($row1 = mysql_fetch_array($query1))
{
$id = $row1['id'];
$first = $row1['first'];
$last = $row1['last'];
$address = $row1['address'];
$city = $row1['city'];
$state = $row1['state'];
$city = $row1['city'];
$zip = $row1['zip'];
$charge1 = $row1['charge1'];
$charge2 = $row1['charge2'];
$charge3 = $row1['charge3'];
$charge4 = $row1['charge4'];
$charge5 = $row1['charge5'];
$charge6 = $row1['charge6'];
$charge7 = $row1['charge7'];
$charge8 = $row1['charge8'];
$charge9 = $row1['charge9'];
$charge10 = $row1['charge10'];
$qq = mysql_num_rows(mysql_query("SELECT * FROM `wimage` WHERE `news_id`='$id'"));
$mug11 = ($qq>0) ? "<img src=\"../news/wimage/t$file\" border=1>" : '';

echo "<td colspan=3 class='wanted1'>&nbsp;$first $last</td><tr>
<td width=100 valign=top>";
$q = mysql_query ("SELECT * from wimage WHERE news_id=$id");
while ($Row6 = mysql_fetch_array($q))
{
echo "<img src=\"../news/wimage/t{$Row6['file']}\" border=1></td>";
}
echo "</td>
<td valign=top><span class='text1'><B>$first $last</b><br>$address<br>$city, $state $zip</td>
<td valign=top><span class='text1'><b>Charges</b><bR>";
if ($row1['charge1']==0) { echo "1. $charge1 <Br>"; } else { echo ""; };
if ($row1['charge2']==0) { echo "2. $charge2 <Br>"; } else { echo ""; };
if ($row1['charge3']==0) { echo "3. $charge3 <br>"; } else { echo ""; };
if ($row1['charge4']==0) { echo "4. $charge4 <br>"; } else { echo ""; };
if ($row1['charge5']==0) { echo "5. $charge5 <br>"; } else { echo ""; };
if ($row1['charge6']==0) { echo "6. $charge6 <br>"; } else { echo ""; };
if ($row1['charge7']==0) { echo "7. $charge7 <br>"; } else { echo ""; };
if ($row1['charge8']==0) { echo "8. $charge8 <br>"; } else { echo ""; };
if ($row1['charge9']==0) { echo "9. $charge9 <br>"; } else { echo ""; };
if ($row1['charge10']==0) { echo "10. $charge10 <br>"; } else { echo ""; };
echo "
</td><tr>";
}
echo "</td></table><br>";
?>
<table border=0 width=99% class="addalert">
<td valign=top><img src='img/alert.gif' align=left></td>
<td><span class='text1'>These fugitives should be considered ARMED and DANGEROUS! NEVER attempt to apprehend a fugitive yourself.
If you have information on the location of any of these fugitives, contact the Roane County Sheriff's Office at (865) 717-4700 or dial 911</td></table>
<br><br><Br>
</td></table>
</td></table>
<?
include ("bot.php");[/php]Thank you
Apr 14 '08 #1
2 1345
ronverdonk
4,258 Expert 4TB
I really do not understand the question. Does [php]if ($row1['charge1']==0)[/php]mean that the charge exists when it is zero (0)? If not, please explain a bit more.

Ronald
Apr 24 '08 #2
aktar
105 100+
Hi Nathan,

put this in place where you have all those charges:

Expand|Select|Wrap|Line Numbers
  1. $counter    =    1;
  2. foreach ($row1 as $field => $value){
  3.  
  4.     if (strpos($field, "charge") && !empty($value)){
  5.  
  6.             print "$counter. $value<br />";
  7.             $counter++;
  8.  
  9.     }//end if (strpos($field, "charge")
  10.  
  11. }//end foreach ($row1 as $field => $value)
  12.  

It seems to me that you have allocated certain number of fields to write the charges. This may cause you a problem in the future as it will not let you scale.
For example if you have 9 fields for chages but the offender was naughty 10 times.. where do you put the extra charge???

Read up on Database normalisation and see how it can help you.

Regards
Apr 25 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
9
by: Ken Durden | last post by:
I already posted this to comp.programming.threads, but the group over there seems to be arguing from a purely theoretical standpoint rather than addressing the reality of compiler optimizations and...
3
by: masood.iqbal | last post by:
In this day and age, you never say no to any work that is thrown at you ---- so when I was offered this short-term contract to convert legacy C code to C++, I did not say no. Personally I believed...
11
by: Ben Collingsworth | last post by:
Anyone have some efficient source code for implementing a ring buffer?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.